How to Control LED using LDR with Arduino UNO

shape
shape
shape
shape
shape
shape
shape
shape
blog-details
June, 2021

Introduction

In this tutorial, you are going to learn how to Control led using  LDR with Arduino UNO.

The led will turn on when there is light.

 

Theory

LDR is briefly known as Light Dependent Resistor. Also called photoresistor.

It is basically used where it is necessary to detect the presence of light.

This is sensible to light, if light falls on it the resistance value changes.

Parts Required

 

PARTS QUANTITY
Arduino UNO 1
A-B Cable 1
LED 1
220ohm Resistor 1
Connecting Wires As Per Required
BreadBoard 1

 

 

 

 

 

 

 

Circuit Diagram

 

Code

For programming this concept we need to understand some basic syntax of Arduino IDE. The first thing is we need to install Arduino. After that, we need to know how to interface led to Arduino.

Let us define and declare LED as an output device.

 

#define LED 6

void setup()
{
 Serial.begin(9600); // serial monitor starts here
 pinMode(LED,OUTPUT); 
}

 

Then read the analog value of the LDR sensor in the void loop function.

 

void loop()
{
 sensorValue=analogRead(A0); // storing the value in one variable
 if (sensorValue<700) //if sensor value less than 700
 {
 digitalWrite(LED,HIGH); //led will on
 }
 else 
 {
  digitalWrite(LED,LOW); //led will off
 }
 Serial.println(sensorValue); 
 delay(1000);
}

 

Final Code

 

#define LED 6
int sensorValue;

void setup()
{
 Serial.begin(9600);
 pinMode(LED,OUTPUT); 
}
void loop()
{
 sensorValue=analogRead(A0); 
 if (sensorValue<700)
 {
 digitalWrite(LED,HIGH);
 }
 else 
 {
  digitalWrite(LED,LOW);
 }
 Serial.println(sensorValue); 
 delay(1000);
}

 

Comments

Leave a Reply