Buzzer makes a static

I have a code where if i press a button it will beep once then wait for 5 seconds to beep again. But when I upload and press the button only the 1st button beeps the second one makes a small static sound. i have tried adding a delay then noTone then delay again but same results

Im using an arduino uno

here is said code

boolean buttonState1;  // boolean variable takes only 1 byte

const byte buttonPin1=10;  // byte constant takes only 1 byte
const byte buzz = 13;  // named variable allows easy changes later


void setup() {
  pinMode(buzz, OUTPUT);
  pinMode(buttonPin1, INPUT_PULLUP);
}

void loop() {
  // put your main code here, to run repeatedly:
  buttonState1 = !digitalRead(buttonPin1);
  if (buttonState1){  // since they are booleans, you don't need "== HIGH"
    tone(buzz,1500,500);
    delay(5000);
    tone(buzz,1000,500);
  }
  else {
    noTone(buzz);
  }
}

image

this is how the board looks like, im not using digital just a visualization

Try a pin other than 13, 0 or 1. Pin 13 has a pulldown resistor for the "L" LED on the board. Pins 0 and 1 are for the Serial Monitor.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.