2

I have a problem with my arduino buzzer: the code should be doing the following: I have a security system where in order to open the door you have to enter a 4 digit code from the remote. If the code is correct the door opens. if not you can try again. You have 3 chances to try to enter the pin before an alarm goes on. here comes the problem: the alarms code triggers but the buzzer isn't making any sound.

here is the code for the alarm sound:

if (tryCount>=3) { // if the pin is wrong 3 times we sound an alarm
 Serial.println("got in alarm");
 while(true) {
 Serial.println("got in while");
 noTone(buzzer);
 tone(buzzer,100,300);
 delay(300);
 noTone(buzzer);
 tone(buzzer,1000,300);
 delay(300);
 }
}

here is the proof the alarm code triggers:

trigger proof

here is the full code: https://create.arduino.cc/editor/mihimbc/8ec2fe30-d812-45cc-b0ae-850b437eb05b/preview

and here is the hardware schematics:

arduino schmatics

asked Mar 22, 2021 at 7:24
2
  • 1
    Is the buzzer an active or a passive one? Only passive buzzers can be driven via tone(). Active buzzers can only switched on or off via digitalWrite() Commented Mar 22, 2021 at 8:27
  • it's an active one. to mention: when i move the instruction for the buzzer inside the loop it works, but in that specific part of the program doesn't. and it's strange that accordingly to the Serial.println that i've put inside the while it seems that its getting there but but no sound is coming from the buzzer Commented Mar 22, 2021 at 8:37

1 Answer 1

1

The problem was with the buzzer, somehow was a faulty buzzer, I've managed to replace it and the problem was solved. Thanks everybody for your time trying to help me!

answered May 15, 2021 at 19:05

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.