Piezo Buzzer using Analog Pin

I am currently using NodeMCU for my project and I have used up all my Digital pins and I need to turn on my buzzer if a certain condition is met. How do I use the A0 pin of my NodeMCU to trigger the buzzer? Any help would be much appreciated.

this is my Digital pin equivalent code:

if(RSSi < -70){
    
    tone(buzzer, 1000); // Send 1KHz sound signal...
    delay(1000);        // ...for 1 sec
    noTone(buzzer);     // Stop sound...
    delay(1000);        // ...for 1sec
  }
  else{
    noTone(buzzer);     // Stop sound...
  }

From this thread:

The numeric value of A0 is 17, as defined here. But unlike on an Arduino board, you can't use it as a digital pin. It only work for pin numbers 0-16. If you are using as a parameter for analogRead , the numeric values would be 0 and 17, as seen here.

So A0 will not work as an OUTPUT.

oh noo :face_with_spiral_eyes:

perhaps try a multiplexer in order to give more outputs

Shift registers are cheap and run fast on SPI. I have bought those 4/$1 before covid.

Perhaps you have an Input that you could move over to "A0" ?

Alright, will check them out :ok_hand:

i will read on that, thanks :ok_hand:

Unfortunately all my pins are used for output

Hi,
Can you please post an image of your buzzer?

Does it buzz(BEEP) if you connect 5Vdc to it?

Trying to establish what sort of device you have.
A BEEPER that makes its own sound, or a speaker type unit that needs a changing current to make a noise.

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

buzzer
This buzzer

So you just need to turn an output pin HIGH to make it work.

Have you written some code to JUST test it out?

Tom.. :smiley: :+1: :coffee: :australia:

yes, i have tested them. But my issue is that all my digital pins are occupied and I'm only left with A0 pin, hence i asked "how do i use the A0 pin to trigger the buzzer".

But it's okay, I'll try to use a shift register as suggested by the other user.

It was suggested that you could use the analog input as a psuedo digitsl input.

If you have a NodeMCU that has the voltage divider on the analog input.
Detect a HIGH with:
if(analogRead(pin) > 620); // more than 2V
and a LOW with
if(analogRead(pin) < 310); // less than 1V

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