theriveroars
Published

Darkness to light

A simple Arduino project to light up LED's when it is dark. And what's more, you can even change its colour!!!

BeginnerFull instructions provided1,708
Darkness to light

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Photo resistor
Photo resistor
×1
Resistor 1k ohm
Resistor 1k ohm
×2
Jumper wires (generic)
Jumper wires (generic)
×11
RGB Diffused Common Cathode
RGB Diffused Common Cathode
You can use common anode by adjusting the circuit
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Schematics for the project, made with Fritzing

Code

Darkness indicator

Arduino
Copy and paste in your Arduino editor!!
void setup() {

  Serial.begin(9600); 
  pinMode(A5, INPUT);// for taking input from photoresistor
  pinMode(4, OUTPUT);//for the pin corresponding to blue
  pinMode(3, OUTPUT); //for the pin corresponding to green
  pinMode(2, OUTPUT); //for the pin corresponding to red
}

void loop() {
  // put your main code here, to run repeatedly:

  int ledOutput = (analogRead(A5));  //output of LDR is assigned to ledOutput
  
  int ledO = map(ledOutput, 1, 1023, 0, 254); 
  
  Serial.print("Lightread");
  Serial.println(ledO);       //read the output of the LDR on the serial monitor
  
   if (ledO >= 28) {          //if it is bright, turn off the light
    digitalWrite(4, LOW);
    digitalWrite(3, LOW);
    digitalWrite(2, LOW);
   }
  else if (ledO >= 20)        //little less bright, turn on blue light
  {
    digitalWrite(4, HIGH);
    digitalWrite(3, LOW);
    digitalWrite(3, LOW);
  }
     else if (ledO>= 9)       //turn on green light
  {
    digitalWrite(4, LOW);
    digitalWrite(3, HIGH);
    digitalWrite(2, LOW);
  }
    else                     //turn on all colurs
    {
    digitalWrite(4,HIGH);
    digitalWrite(3,HIGH);
    digitalWrite(2, HIGH);
    }
    
  delay(49);

}

Credits

theriveroars
2 projects • 0 followers

Comments