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

  • 45,923 views
  • 5 comments
  • 19 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

RGB LED Button Controller

Project showcase by Re

  • 14,757 views
  • 2 comments
  • 18 respects

Ambient Light Sensor Using Photo Resistor and LED Lights!

Project tutorial by DCamino

  • 11,103 views
  • 9 comments
  • 22 respects

LED Dice

Project showcase by EvdS

  • 31,674 views
  • 23 comments
  • 91 respects

Weather Clock

Project showcase by Tittiamo

  • 12,422 views
  • 9 comments
  • 28 respects

Turn LEDs On/Off via Remote Control

Project tutorial by ismystore

  • 9,818 views
  • 1 comment
  • 8 respects

Programming 8x8 LED Matrix

by SAnwandter1

  • 237,208 views
  • 45 comments
  • 220 respects
Add projectSign up / Login