Assignment 2 : Building a Light-Sensing Circuit Using an LDR & 3 LEDs

The circuit is fairly simple. The LEDs are assigned pins on the Arduino which allows individual manipulation of each LED. 
The functionality of the circuit is as follows :
If the light intensity is detected to be above 700(which was the highest recorded intensity in the conditions that the circuit was made), then the red LED is made to light up. If the light intensity is between 500 and 700, then the green LED lights up. (Note : It was somewhat difficult to replicate this “intermediate” condition). 
Lastly, if the intensity drops below 500, then the blue LED lights up.
I also created a short delay of 1.5 seconds between each change, so as to compensate for any delay in the physical detection of a change in light intensity, which may result in 2 LEDs lighting up at once, or not at all. Also, it must be noted that this circuit might not function exactly the same in a different condition, considering that I coded it around the light conditions I was in at the time of writing the code.

Considering that I had constructed this circuit before, it was pretty straightforward to re-create it. The only problems encountered were occasional hiccups in making the connection between the breadboard and the main board.

// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
//Assign the LEDs to a pin to receive input
Serial.begin(9600);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);

}

// Loop to read the light intensity using the LDR as a sensor, and lighting up an LED accordingly
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// print out the value you read:4
Serial.println(sensorValue);
delay(1); // delay in between reads for stability

 

if (sensorValue > 700) {
digitalWrite(12, HIGH);//if the value is over 700, then light up the LED attached to the 12th pin i.e the Red LED
digitalWrite(11, LOW);
digitalWrite(10, LOW);
delay(1500); //this is to compensate for any delay in physical detection in changes in light intensity
}
else {
if ((sensorValue > 500) && (sensorValue < 700)) {
digitalWrite(12, LOW);
digitalWrite(11, HIGH); //Light the green LED if its in this intermediate range
digitalWrite(10, LOW);
delay(1500);
}

else {
if (sensorValue < 500) {
digitalWrite(12, LOW);
digitalWrite(11, LOW);
digitalWrite(10, HIGH); //Light the blue LED if it goes below the range
delay(1500);
}
}
}

}

 


(Schematic of the Circuit)

(Intermediate Light Conditions)

(Bright Light Conditions)

(Low Light Conditions)

 

Leave a Reply

Your email address will not be published. Required fields are marked *