Go Down

Topic: Clock with LDR using sunset to sync (Read 1 time) previous topic - next topic

Jan Willem Kooi


I just wrote my fist big mail but was not able to post it, since it contained a link. So I have to start all over   >:(
I made a 433 remote switch system for my livingroom lamps. The link will follow in my next mail but it measeres the daylight to swtich on and an software clock to switch off.

But my idea was:

Is it possible to make a clock using Millis and let it sync using an LDR and measuring the daylight?
You should program sunset and sunrise times for a year. Lots of challages (clouds, sunset is graduate proces etc.)

Jan Willem

Jan Willem Kooi

My project is can be found here:


Jan Willem


There is a DateTime  library in the playground that makes it easy to run a clock from the Arduino without external hardware : http://www.arduino.cc/playground/Code/DateTime

Ran Talbott

but was not able to post it, since it contained a link. So I have to start all over

Any time you're writing a long/complicated post to a website,  you should copy and paste it to a text editor window.  Maybe even save it to disk if there's a thunderstorm going on,  or your roommate is testing the high-power industrial laser she bought at the bankruptcy auction.  You never know when a blog software bug,  a power failure,  or the electromagnetic field from a passing alien spaceship will cause a problem with posting.

I think you've already figured out that variations like clouds can cause problems with trying to determine sunrise and sunset from light level.  But it sounds like the ambient light level is what you really want to measure,  anyway,  since you're controlling artificial lights:  if the clouds are especially thick,  it might get dark enough that you'd want to turn on some of the lights at 0930.

You're probably going to need to put your light sensor in its own little enclosure,  so it can be pointed where it will truly measure daylight:  you don't want the clock turning off the porch light because you sat down at your desk and turned on the reading lamp next to the clock  :)  Or turning it on because you brought a box to your desk and set it down so it blocked the sensor.  I would put an opamp,  wired as a unity-gain buffer,  in the enclosure with the sensor:  it will give you a nice,  strong low-impedance signal to feed that ADC,  and reduce the risk of the sensor cable turning into an antenna.


Jan Willem Kooi

Hi Ran,
My project is already working. The LDR has a incredible range from a few K to many M ohms. Without any OPAMP and without a closure, just by putting the box in the windowsill, it works fine. (have a look at the schematic) And with a rolling average it doesn't switch during daylight. Since it is summer here, I haven't had the situaltion that it is during daylight so clouded that lamps were needed. The software clock is not stable enough. I tried the DateTime library but decided to program it my self. Just to learn. But is there a difference (in terms of overhead processes) between write just code for the Arduino and writing in C++ code as a Library? Is it compiled differently?

The cloud thing was more refering to sync on sunset and rise.

Mike Mc

Why would you want to do this? Why not sync with a time server or use a RTC chip?

Jan Willem Kooi

Why? Because it is not done yet and because you almost need nothing. Just 1 resistor + 1 LDR.

Mike Mc

I don't see how you could possibly get an accurate sync of time from a light level.

Jan Willem Kooi

I agree, it is not easy. But all sunset and sunrise moment are known for a specific place. And for a lamp switching system it is not necessary to be accurate to the second. A couple of minutes is ok. Remenber, you only need the clock for switching off.

If you set the date, the system known when sunset and sunrise should occur that day and also for the future days. That date with sunset en sunrise times should be programmed in a table.

With a rolling average ( difficult to determine the parameters) of what the system measures and what it should be based on the table, you can adjsut the clock.
That's the idea. I am convinced that it is possible but have no idea how accurate it could be. Would be nice if it was +/- 5 minutes.

Jan Willem

Go Up