Project showcase
Turn On and Off LED by LDR (Toggle LDR)

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).

  • 70,234 views
  • 7 comments
  • 32 respects

Components and supplies

About this project

Overview

This example demonstrates the use of a LDR as a switch. Each time you cover the photocell, the LED (or whatever) is turned on (if it's off) or off (if it's on).

Code

Toggle LDRArduino
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);
}
}

Schematics

Toggle LDR
Untitled hn88fpsng7

Comments

Similar projects you might like

Ambient Light Sensor Using Photo Resistor and LED Lights!

Project tutorial by DCamino

  • 52,735 views
  • 10 comments
  • 36 respects

RGB LED Button Controller

Project showcase by Re

  • 28,144 views
  • 3 comments
  • 23 respects

Programming 8x8 LED Matrix

by SAnwandter1

  • 363,601 views
  • 64 comments
  • 302 respects

LED Dice

Project showcase by EvdS

  • 63,771 views
  • 41 comments
  • 159 respects

Weather Clock

Project showcase by Tittiamo

  • 18,019 views
  • 9 comments
  • 35 respects

LED Color Sequencer

Project tutorial by thefantasticode.Group

  • 19,246 views
  • 17 comments
  • 45 respects
Add projectSign up / Login