Introduction: Arduino - Buzzer With LDR and LED

In this project; we will see using LDR to activate a buzzer and an LED. When light shines on LDR; the buzzer will give alarm and the LED will flash.

Step 1: Hardware Required

Picture of Hardware Required

  • Arduino Uno
  • Buzzer
  • LED
  • LDR (photoresistor)
  • 220 and 10k ohm resistor
  • Wires
  • Breadboard

Step 2: Buzzer - LED - LDR Attach to Board

Picture of Buzzer - LED - LDR Attach to Board
  1. Buzzer attach to board (the buzzer long leg (+) and short leg (-))
  2. LED attach to board (the LED long leg (+) and short leg (-))
  3. 220 resistor attach to board from LED long leg (+)
  4. LDR attach to board
  5. 10k resistor attach to board from LDR one leg

Step 3: Arduino Connection

Picture of Arduino Connection

  1. The wire connect to ground, then the same wire attach to board.
  2. The wire connect to buzzer short leg, then the same wire attach to GND on the board.
  3. The wire attach to LED short leg, then the same wire connect to GND on the board.
  4. The wire connect to 10k resistor empty leg, then the same wire connect to GND on the board.
  5. The wire connect to +5V, then the same wire attach to LDR empty leg.
  6. The wire connect to digital 12, then attach to buzzer long leg.
  7. The wire connect to digital 13, then attach to 220 resistor empty leg.
  8. The wire connect to A0, then attach to LDR's - resistor's same column.

Step 4: Code

Picture of Code

const int ledPin = 13;

const int buzzerPin = 12;

const int ldrPin = A0;

void setup () {

Serial.begin(9600);

pinMode(ledPin, OUTPUT);

pinMode(buzzerPin, OUTPUT);

pinMode(ldrPin, INPUT);

}

void loop() {

int ldrStatus = analogRead(ldrPin);

if (ldrStatus >= 400) {

tone(buzzerPin, 100);

digitalWrite(ledPin, HIGH);

delay(100);

noTone(buzzerPin);

digitalWrite(ledPin, LOW);

delay(100);

Serial.println("----------- ALARM ACTIVATED -----------");

}

else {

noTone(buzzerPin);

digitalWrite(ledPin, LOW);

Serial.println("ALARM DEACTIVATED");

}

}

Step 5: If It Helps, Please Subscribe

Picture of If It Helps, Please Subscribe

First of all, I would like to thank you for reading this guide ! I hope it helps you.

If you want to support me, you can subscribe my channel and watch my videos.

Mert Arduino Tutorial & Projects

Comments

jsander0706 (author)2017-10-12

This was my first time doing anything with programming and i have been trying to make it work for about two weeks but I finally figured out that I have all the hardware in different pins.... so that was imbarresing but this was really fun. Thanks

daryl.rasmusen (author)2017-02-14

Can I substitute the LDR with a potentiometers, so that, I have more control?

Nematic! (author)2016-11-16

Nicely explained ;)

About This Instructable

8,051views

58favorites

License:

Bio: For more project and tutorial visit my YouTube channel Mert Arduino and Raspberry Pi
More by MertArduino:Arduino - Balance - Balancing Robot | How to Make?Arduino - MPU6050 GY521 - 6 Axis Accelerometer + Gyro (3D Simulation With Processing)NodeMCU ESP8266 - WiFi Robot Car Controlled by Application (Wifi Bot / Android / IoT)
Add instructable to: