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

  • 38,668 views
  • 3 comments
  • 20 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

  • 7,977 views
  • 1 comment
  • 12 respects

Ambient Light Sensor Using Photo Resistor and LED Lights!

Project tutorial by DCamino

  • 3,367 views
  • 4 comments
  • 17 respects

LED Dice

Project showcase by EvdS

  • 14,276 views
  • 11 comments
  • 49 respects

Weather Clock

Project showcase by Tittiamo

  • 7,665 views
  • 7 comments
  • 22 respects

Turn LEDs On/Off via Remote Control

Project tutorial by ismystore

  • 6,930 views
  • 0 comments
  • 5 respects

Simple Programmable Robotic Arm

Project showcase by Ryan Chan

  • 49,020 views
  • 63 comments
  • 145 respects
Add projectSign up / Login