/*
#Code written by TeamUltron
#Satyajeet Ranjan
#02-10-2017
# this project uses a photo resistor module and a 3 color led module
# Feel free to contact me for any help. 'satyajeet.ra2016@gmail.com'
# any suggestion is always welcome.
**NO RIGHTS RESERVED
*/
int sensorPin = A5; // select the input pin for the potentiometer
int ledPin = 13; // select the pin for the LED
int red = 8; //red pin for led module
int blue =9 ; //blue pin for led module
int green = 10; //green pin for led module
int val = 255; //taking the max value for lights
int sensorValue = 0; // variable to store the value coming from the sensor
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(115200);
}
void loop() {
sensorValue = analogRead(sensorPin);
if(sensorValue <=290)
{
Serial.println("DAY LIGHT");
analogWrite (red,100);
analogWrite (blue, 100); //Led will be static
analogWrite (green, 120);
}
else if (sensorValue>=500){
Serial.println("night light");
for (val = 255; val> 0; val --) //using for loop to keep led flashing.
{
analogWrite (red, val);
analogWrite (blue, 255-val);
analogWrite (green, 255);
delay(10);
analogWrite (red, val);
analogWrite (blue, val-65);
analogWrite (green, val-40);
delay(5);
}
}
else{
Serial.println("Light not that good");
for (val = 255; val> 0; val --){
analogWrite (green, val);
delay(10);
analogWrite (red, 300-val);}
analogWrite (blue, 128-val);
delay(10);
}
digitalWrite(ledPin, HIGH); //blinking arduino led based on the sensor val.
delay(sensorValue);
digitalWrite(ledPin, LOW);
delay(sensorValue);
Serial.println(sensorValue, DEC); //print the decimal value from sensor
}
Comments