Menu Close

NodeMCU Peizo Buzzer on Arduino IDE

This tutorial of Robo India explains how to use buzzer on NodeMCU on Arduino IDE.

Detailed Tutorial

1. Introduction:

A Peizo buzzer is a device that is used to generate beep sound (generally a warning or alert in embedded system). It is a two leg device the longer leg is positive. If voltage is supplied it generates beep sound. Through analog write volume of beep can be controlled.

If a buzzer is switched with different time intervals it generates a melody.

This tutorial is for NodeMCU on Arduino IDE. Please note that the same tutorial can be performed on LUA as well.

1.2 Hardware required

S.No.ItemQuantity
1NodeMCU 1
2Breadboard 1
3Transistor 1
4Resistor 1k 2
5LED 1
6Jumper Male to male 8
7Buzzer 1

2. Building Circuit

Schematic Diagram:

Circuit Layout:

3. Programming:

Once the circuit part is done, NodeMCU is needed to be programmed. Here is the code to run this circuit on NodeMCU.

You may download this code (Arduino Sketch) from here.

// Robo India Tutorial of Buzzer
// Just like code of digital output.

const int buzzer =  4;

void setup() {
  pinMode(buzzer, OUTPUT);
       
}

void loop(){
  digitalWrite(buzzer, HIGH);
  delay(200);
  digitalWrite(buzzer, LOW);
  delay(200);  
}

4. Output

The buzzer generates beep sound in a loop. Try delay in microseconds to generate melody. Volume is controlled through analogWrite.

5. Troubleshooting

LED glowing but Buzzer is not working and vice versa: Check both of them separately.

If still not working pull the led out and test it may be defective

If you have any query please write us at support@roboindia.com

Thanks and Regards
Content Development Team 
Robo India
https://roboindia.com

Leave a Reply