I have made a circuit consisting of:
- three LEDs (Blue, Green, Yellow)
- 10 wires
- three 330 Ω Resistors
- one 10K Ω Resistor
- one red board
- on bread board
- one LDR
Based on the strength of light shining into LDR one of three lights shines.
Under a normal room light the green LED shines. If there is less amount of light given by covering the LDR, the yellow LED lights up. Lastly when a strong light is given blue LED lights up.
Code:
void setup() { Serial.begin(9600);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
}
void loop() { int sensorValue = analogRead(A0);
Serial.println(sensorValue);
if(sensorValue > 900){
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
}
else if(sensorValue < 900 && sensorValue > 600){
digitalWrite(10, LOW);
digitalWrite(11, HIGH);
digitalWrite(12, LOW);
}
else {//(sensorValue < 600){
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, HIGH);
}
delay(1);
}
Schematic: