siddh-1
Published © GPL3+

Turn On & Off of LED with Photoresistor

Do you want to turn more Leds then the Room is getting darker and darker with Photoresistor, then this is for you

BeginnerFull instructions provided3,883
Turn On & Off of LED with Photoresistor

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
LED (generic)
LED (generic)
×4
Resistor 220 ohm
Resistor 220 ohm
for each Led 1 Resistor
×4
Resistor 10k ohm
Resistor 10k ohm
×1
Photo resistor
Photo resistor
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

shiny_luulia_37bHdyCXxd.brd

Code

The Code

C/C++
#include <EEPROM.h>
const int ldrsen = A0;
int Led = 13;
int value = 0;
int LedPin2 = 12;
int LedPin3 = 11;
int LedPin4 = 10;
//
void setup() {
  delay(2000);
  Serial.begin(9600);
  pinMode(LedPin2, OUTPUT);
  pinMode(LedPin3, OUTPUT);
  pinMode(LedPin4, OUTPUT);
  pinMode(Led, OUTPUT); 
  pinMode(ldrsen, INPUT);
  
  // Starting the TEST
  
  Serial.println("======Starting the Test======");
  Serial.println("You should see the Led blinking every 2 sec");
  digitalWrite(Led, HIGH);
  delay(200);
  digitalWrite(Led, LOW);
  delay(200);
  digitalWrite(LedPin2, HIGH);
  delay(200);
  digitalWrite(LedPin2, LOW);
  delay(200);
  digitalWrite(LedPin3, HIGH);
  delay(200);
  digitalWrite(LedPin3, LOW);
  delay(200);
  digitalWrite(LedPin4, HIGH);
  delay(200);
  digitalWrite(LedPin4, LOW);
  delay(200);
  Serial.println("Test 1 is completed");
  Serial.println("Now testing the Photoresistor, Make sure it is connected to the Pin A0");
  delay(2000);
  Serial.println("Starting the test now!");   
   
   rerun:
  value = analogRead(ldrsen) /4;
  
  if(value >1){
    Serial.print("The Photoresistor is connected and here are some value: ");
    delay(200);
    Serial.println(value); 
    delay(200);
    Serial.println(value); 
    delay(200); 
    Serial.println(value);    
  }
    else{
      value = analogRead(ldrsen)/4 ;
        if(value<0)
          Serial.println("Hmm the Photoresistor is not connected");
          Serial.println("Retrying in 5s");
          delay(5000);
          goto rerun;
        }
          Serial.println("======END======");
}


 //*************************LOOP*******************


 
void loop() {
  value = analogRead(ldrsen)/4;
  delay(100);
    if(value < 50){
    digitalWrite(Led, HIGH);
  }
  else
  {
    digitalWrite(Led, LOW);
  }
  //Led2
  if(value < 70){
    digitalWrite(LedPin2, HIGH);
  }
  else
  {
    digitalWrite(LedPin2, LOW);
  }
  if(value < 150){
    digitalWrite(LedPin3, HIGH);
  }
  else
  {
    digitalWrite(LedPin3, LOW);
  }
  if(value < 200){
    digitalWrite(LedPin4, HIGH);
  }
  else
  {
    digitalWrite(LedPin4, LOW);
  }
}

Credits

siddh-1
0 projects • 0 followers
Contact

Comments

Please log in or sign up to comment.