Guruashish Choudhary
Published © GPL3+

Turn LED On and Off Through LDR

This example demonstrates how to use an LDR (Light Dependent Resistor) as a switch; each time you cover the LDR, the LED is turned on/off.

BeginnerFull instructions provided1 hour85,982
Turn LED On and Off Through LDR

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Photo resistor
Photo resistor
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Resistor 221 ohm
Resistor 221 ohm
×1
LED (generic)
LED (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×7
Breadboard (generic)
Breadboard (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

SCHEMATICS

Code

ON and OFF LED

C/C++
int ldr=A0;//Set A0(Analog Input) for LDR.
int value=0;
void setup() {
Serial.begin(9600);
pinMode(3,OUTPUT);
}

void loop() {
value=analogRead(ldr);//Reads the Value of LDR(light).
Serial.println("LDR value is :");//Prints the value of LDR to Serial Monitor.
Serial.println(value);
if(value<300)
  {
    digitalWrite(3,HIGH);//Makes the LED glow in Dark.
  }
  else
  {
    digitalWrite(3,LOW);//Turns the LED OFF in Light.
  }
}

Credits

Guruashish Choudhary

Guruashish Choudhary

2 projects • 4 followers

Comments