Making an Annoying beeping PCB. I can get the loop to work correctly at random intervals but the passive buzzer is making a low-volume tap rather then a high pitch beep. I tried using tone(buzzer, 1000) which makes the correct sound but its constant instead of being at random intervals. I have attached code.
//Make sure to plug the buzzer into this pin # on the arduino!
const int buzzer = 9;
//You buzzer will turn on at random intervals between the shortest and longest wait times in seconds entered here.
const int shortest_wait = 300;
const int longestest_wait = 600;
long randomWait; //we'll change this each loop.
//How many miliseconds the buzzer will stay on?
const int buzzer_length = 500;
//This loop runs once when the Arduino is turned on, to set up the buzzer.
void setup(){
pinMode(buzzer, OUTPUT);
}
//This loop runs over and over, as long as the Arduino has power!
void loop(){
//pick a new random wait time.
randomWait = random(shortest_wait, longestest_wait);
//turn the buzzer on with our selected sound.
digitalWrite(buzzer,LOW);
delay(buzzer_length);
//leave the buzzer off for our random amount of time.
digitalWrite(buzzer,HIGH);
delay(randomWait*1000);
}