LDR Interfacing to Arduino

by callmeappytechie in Circuits > Arduino

1922 Views, 12 Favorites, 0 Comments

LDR Interfacing to Arduino

17.png

Hi, guys!! I'm Sridhar Hanrahan back another instructable dealing with the security system based on the light using an LDR sensor.This has a major application in bank security system and any light-based alarm system.seems interesting?Before getting into hardware interface let me explain to you what is a LDR ?.A light dependent resistance is a kind of resistor whose material is made up of high resistance material thus when the light falls on the sensor there is a kinetic energy happening inside the sensor causing the decrease in the resistance of the sensor.So having this little knowledge about this sensor let's get started to collect the electronics.

Components Required:

1.png
2.png
4.png
5.png
4.psd.png

The component required for this projects are:

  • Arduino Uno
  • Breadboard
  • LDR
  • Piezo buzzer
  • A 220-ohm resistor

Let's start interfacing the Piezo buzzer in Arduino.

Piezo Buzzer Interface:

6.png
7.png
8.png
9.png

The piezo buzzer contains two wire coming out of an enclosure.The red wire is called as positive or anode and the black wire is called as negative and cathode.

The connection of the piezo buzzer is followed:

  • The black wire is connected to the negative railing of the breadboard.
  • the red wire is connected to the digital pin 11.

Next,Let get start to connect the LED.

LED Interface:

11.png
12.png
13.png
14.png

Light emitting diode is a two terminal semiconductor device.the two terminal vary in size, the longer leg is called as positive or anode whereas the shorter leg called as negative or cathode.

The connection of LED is as follows:

  • The longer leg is connected to the digital pin 10.
  • The shorter leg is connected to the negative railing of the breadboard.

Now let's connect the LDR.

LDR Interface:

15.png
16.png

The connection of LDR is as follows:

  • The 220-ohm resistor is connected to either leg of the LDR.
  • The leg to which the 220 ohms is connected is connected digital pin 13.
  • The other leg of the LDR is connected to the Analog pin A0 of the Arduino.

Now let's get into coding

Coding:

10.png

const int ledPin = 8;

const int buzzerPin = 9;

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(" ACTIVATED "); }

else {

noTone(buzzerPin);

digitalWrite(ledPin, LOW);

Serial.println(" DEACTIVATED");

}

}

If any peeps have difficulty in following the instructables please leave a comment below.

Thank you,