Introduction: LDR Buzzer Using Node

About: My team has developed a new product. PLEASE CHECK IT OUT ON INDIEGOGO AND SHOW YOUR SUPPORT. CAMPAIGN LINK: https://igg.me/p/2165733/x/17027489. I'm a tech and food enthusiast and also a Soccer Player. I love…

Hi!! I am Gokul, back with another series of tutorials on Node MCU today.This project deal with LDR buzzer i.e if there are any changes in light there is a ping in the buzzer.This ibles is used during the day time in while we are away from our home and integrate the IoT platform to reveal the suspicious activity.Let's now get started by collecting the components.

Step 1: Components Required

components required can be observed above:

  • Node MCU
  • Buzzer
  • Breadboard
  • Light dependent resistor

Step 2: LDR Connection

LDR is a light dependent resistor that resistance is increased when there is increase is decrease in the light rays around the surface

The connection of the LDR is as follows:

  • One leg of the LDR is connected to the GND through 10 k resistor
  • The same leg is connected to the analog pin A0.
  • Another leg is connected to the 3.3 volt of the Node MCU.

Step 3: Buzzer

Buzzer is an electronic device which is used to convert the electrical impulse sent as input to a sound energy.

The buzzer has two polarities but in the form of wires(red wire and black wire).

The connection of the buzzer is as follows:

  • The red wire is connected to digital pin 2.
  • The black wire is connected to the GND pin of the Node MCU.

Step 4: Coding

const int buzzerPin = 2;const int ldrPin = A0; 
void setup () { 
Serial.begin(9600); 
pinMode(buzzerPin, OUTPUT); 
pinMode(ldrPin, INPUT); 
}int ldrStatus = analogRead(ldrPin); 
if (ldrStatus >= 400) { 
tone(buzzerPin, 100); delay(100); 
noTone(buzzerPin); 
delay(100);
 }void loop() {int ldrStatus = analogRead(ldrPin); 
if (ldrStatus >= 400) { 
tone(buzzerPin, 100); 
delay(100); 
noTone(buzzerPin); 
delay(100);
 }else {
noTone(buzzerPin);
} }

Step 5: Output

Makerspace Contest 2017

Participated in the
Makerspace Contest 2017