electronicsfan123
Published © GPL3+

Interfacing Arduino uno with LDR

In this basic tutorial we are going to see how to interface Arduino uno with LDR sensor. So let's start !!!

IntermediateProtip53,038
Interfacing Arduino uno with LDR

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
LDR, 5 Mohm
LDR, 5 Mohm
×1
LED (generic)
LED (generic)
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Circuit diagram

Image

Image

Image

Code

Code

C/C++
// Interfacing Arduino uno with LDR sensor

const int ledPin = 5; // digital pin 5 
const int ldrPin = A0; // analog pin 0

void setup() { //  Void setup function will only run once, after each powerup or reset of the Arduino board.

Serial.begin(9600);

pinMode(ledPin, OUTPUT); // Here LED is determined as an ouput or an indicator.

pinMode(ldrPin, INPUT); // Here LDR sensor is determined as input.

}

void loop() { // Void loop is ran again and again and contains main code.

int ldrStatus = analogRead(ldrPin);

if (ldrStatus <= 200) {

digitalWrite(ledPin, HIGH); // If LDR senses darkness led pin high that means led will glow.

Serial.print("Darkness over here,turn on the LED : ");

Serial.println(ldrStatus);

} else {

digitalWrite(ledPin, LOW); // If LDR senses light led pin low that means led will stop glowing.

Serial.print("There is sufficeint light , turn off the LED : ");

Serial.println(ldrStatus);

}

}

Credits

electronicsfan123

electronicsfan123

5 projects • 8 followers

Comments