Arduino photo cell measurements

Last time I talked about modifying the LED decoration and creating my own LED string. Today I’ll talk about connecting a photo cell to an Arduino and take timed measurements of outdoor light. Based on the measurements from the photo cell, an ideal value is determined to switch the light automatically.

Wiring the photo cell

Wiring the photo cell is fairly easy. There are many blogs covering the exact wiring and I think the best example is Adafruits learning systems guide. A pull-down resistor is used for detecting more differences in darkness. When more differences in brightness are needed, use a lower value for the pull-down resistor.

I also added my micro-SD expansion bord so I could take timed measurements and save them in a text file on the SD card. Resulting in an automated system that measures the light outside and saves the value in a text file.

The Arduino code for the photo cell

Using my Arduino Mega 2560, I came up with the following code.

The code will take a light measurement, using the photo cell, every 2 minutes. It will then create a string and save the value. The time library is used for adding time information to the measurements. The time is set right before the code is compiled and uploaded to the Arduino, so there is no need for a internet connection or advanced time system. It’s not 100% accurate but does the job wonderfully. Also note that I did not use delay’s, but rather a timer function, delay’s should be avoided at any cost!

The result of the photo cell measurements

I did the measurements 2 times, always starting around the same time, leaving it on for the night and shutting it down in the morning. I exported the text files as CSV files in Excel and then plotted the result.

The light measurements from the photocell

The first day we see a clear spike in the middle of the night, there was a car turning and the lights clearly spiked my photo cell. Around 21:00 I felt that it was time to turn on the lights, this time corresponds with a value of 350. This value can be used to turn on my lights automatically when its dark enough in the room.

Next time I’ll add bluetooth support to check if a person is in the room or not. Quite important not to switch the lights when I’m not at home.

One thought on “Arduino photo cell measurements

  1. Pingback: Light automation project - Part 1 | Fritz-Hut