0
const int buzzer=6;
const int switchPin=3;


void setup() {
  pinMode(switchPin,INPUT);
}

void loop() {
  int switchState;

  switchState=digitalRead(switchPin);

  if(switchState == HIGH) {
    tone(buzzer,324);
  } else {
    noTone(buzzer);
  }
}

When I plug the buzzer into pin 6, even if there is nothing connected to pin 3, it still buzzes. Any help?

jpeterik12
  • 21
  • 2

1 Answers1

0

This seems like a PullUp/Down resistor problem.

Pull-up resistors are used in electronic logic circuits to ensure that inputs to the arduino settle at expected logic levels if external devices are disconnected or high-impedance. 'Just because you have nothing at all connected to an input pin doesn't mean it is a logical zero.'

look here for details.

Mali
  • 2,990
  • 18
  • 18