DIY Inventor
Published

Arduino DIY LED Control with LDR Sensor (Photoresistor)

This example demonstrates how to use an LDR (Light Dependent Resistor) darkness LDR, the LED is turned on/off.

BeginnerProtip1,336
Arduino DIY LED Control with LDR Sensor (Photoresistor)

Things used in this project

Hardware components

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

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Circuit Diagram

Connection of LED

Connect to Long Pin (+5V Pin) of LED to (Pin 12) of Arduino
Connect to Small Pin (GND Pin) of LED to (GND) of Arduino
Connection of LDR

Connect LDR (Any One Pin) to (+5V) Of Arduino
Connect 1K Resistor to Another Pin OF LDR and Connect Resistor Pin to GND of Arduino
Connect Ldr 2 Pin To A0 Of Arduino

Code

Code

C/C++
/*Inventor DIY Inventor (Krishna Agarwal)
Desingner DIY Inventor (Krishna Agarwal)
Codder DIY Inventor (Krishna Agarwal)
*/

//set pin numbers
//const won't change
const int ledPin = 12;   //the number of the LED pin
const int ldrPin = A0;  //the number of the LDR pin


void setup() {

  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);  //initialize the LED pin as an output
  pinMode(ldrPin, INPUT);   //initialize the LDR pin as an input
}

void loop() {
  int ldrStatus = analogRead(ldrPin);   //read the status of the LDR value

  //check if the LDR status is <= 500
  //if it is, the LED is HIGH
Serial.println(ldrStatus);
/*Inventor DIY Inventor (Krishna Agarwal)
Desingner DIY Inventor (Krishna Agarwal)
Codder DIY Inventor (Krishna Agarwal)
*/
   if (ldrStatus <=80) {

    digitalWrite(ledPin, HIGH);               //turn LED on

   }
  else {

    digitalWrite(ledPin, LOW);          //turn LED off
  }
}

Credits

DIY Inventor

DIY Inventor

0 projects • 15 followers
Hello Guys, My name is Krishna Agarwal , and I'm passionate about Making DIY Projects. Here I make Arduino and Robotics related projects.

Comments