Arduino light sensor project

One of the most common smart home systems is the one that turns on the light when it is dark. Many cars nowadays have such lights. they simply turn on automatically when it is dark.

Everybody can see the usefulness of such devices without thinking a lot, and the good news is that it is very easy to build something of this sort using the Arduino Uno board.

All you need is the Arduino Uno board and few basic components. You can also add a relay to it to control high devices if needed.

Light sensor with the Arduino Uno board

Here is what we need to build our system:

This Arduino project will also be interesting if you use the whole settings to control a Lamp as we did in the Arduino relay project.

Remeber the color of the LED doesn’t matter in this project. Make sure you have properly connected a resistor with the photoresistor; this is important and help create a voltage divider to get it working. For the LED I used a 300Ω resistor and for the photoresistor a 2,4kΩ resistor.

When the connections are ready, we can upload the code to the Arduino. What the code does is: it reads the value from the analog pin A0. If the value is smaller than 650, it turns the LED ON (it basically turn the LED on when it is dark). if the value is bigger than 650, it will turn OFF the LED.

As an addition, it will print the analog value on the serial so you can see it and eventually adjust the resistor values or threshold for the control the LED.

Here is the code:

void setup() {
Serial.begin(9600);
pinMode(A0, INPUT);
pinMode(6, OUTPUT);
}
void loop() {
Serial.println(analogRead(A0));
delay(100);
if(analogRead(A0) < 650){
digitalWrite(6, HIGH);
}else{
digitalWrite(6, LOW);
}
}

Feel free to play with the code and do not forget to adjust it to your needs.

 

tchouken2

Related Posts