muhammed amar slik
Published

Turn On and Off LED by LDR (Toggle LDR)

This example demonstrates how to use LDR as a switch; each time you cover the LDR, the LED is turned on (if it's off), and off (if it's on).

BeginnerShowcase (no instructions)1 hour77,282
Turn On and Off LED by LDR (Toggle 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)
×1
Breadboard (generic)
Breadboard (generic)
×1

Story

Read more

Schematics

Toggle LDR

Code

Toggle LDR

Arduino
const int lamp = 7;
boolean x = true;
.
void setup() {
  Serial.begin(9600);
  pinMode(lamp , OUTPUT);

}

void loop() {
  int c = analogRead(A0);
  delay(500);
if ( c<300 && x == true){
  digitalWrite(7,HIGH);
   x = false;
   delay(1000);

}
else if ( c <300 && x == false){
x = true;
digitalWrite(7,LOW);
delay(1000);
}
}

Credits

muhammed amar slik

muhammed amar slik

0 projects • 10 followers

Comments