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?