LDR Buzzer Using Node

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.
Components Required





components required can be observed above:
- Node MCU
- Buzzer
- Breadboard
- Light dependent resistor
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.
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.
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); } }
Output
