0
\$\begingroup\$

I have an active buzzer which I connected to an arduino pin (besides the other two pins being connected to Vcc and GND). I would expect the speaker to beep when I do a digitalWrite(PIN, HIGH) but it's the opposite. Indeed if I don't turn off the pin explicitly the buzzer will go off. This is the same for a small vibration motor.

Is there a sort of "convention" or even these devices have some weird default logic? And more importantly why?

\$\endgroup\$
3
  • \$\begingroup\$ There is nothing weird in negative logic. For example it is quite common to tie GPIO pins to a pull-up resistors to avoid floating inputs. Such an input will be high by default. \$\endgroup\$
    – Eugene Sh.
    Apr 1, 2021 at 18:06
  • \$\begingroup\$ Which buzzer or motor would this be, please add the make and model to your question. \$\endgroup\$
    – Justme
    Apr 1, 2021 at 18:26
  • \$\begingroup\$ Why active buzzers (and some vibration motors) require LOW in order to emit sound ... no, they do not ... they require a voltage difference across the power pins ... whether you permanently connect the positive and switch the negative, or permanently connect the negative terminal and switch the positive terminal is not relevant \$\endgroup\$
    – jsotola
    Apr 1, 2021 at 19:32

1 Answer 1

2
\$\begingroup\$

The load (active buzzer circuit) is between Vcc and the GPIO pin. When the GPIO pin is high, there is no voltage across the load so of course there is no sound. When the GPIO pin is low there is Vcc (almost) across the load so you get the beep.

The propensity to put loads between Vcc and the GPIO is related to physics- n-channel transistors of the same size are much better at sinking current than equivalent size p-channel transistors because of carrier mobility differences, if memory serves.

It may not be as important in the case of the GPIO pins on ATMega and similar microcontrollers because the designers have gone to pains to make the source capability of the GPIO pins similar to the sink capability.

If you want to try it the other way, you would connect the (+) pin of the active beeper to the GPIO pin and ground the (-) pin.

\$\endgroup\$

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.