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");

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

  • 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()
    – chrisl
    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


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!

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.