A very SAD story

Here we see the first stirrings of a SAD light for my wife. She’s convinced that it’s daylight that wakes her up so having recently discovered inexpensive daylight colour LED STRIP and already used it for full-spectrum soft lighting, I’ve been toying with the best way to make her a slow-start SAD (seasonal affective disorder) light.. here’s the story so far…



I’ve been in the business of programming single-chip micros for years via www.willowdesign.info but recently I’ve concentrated on software so it was not only something of a treat to get the breadboard and soldering iron out again – but also interesting to try out a (for me) new processor – the ATMEL ATMEGA328 chip – which for the price is quite neat and a great advance on the old PIC chips. What you’re looking at is an assembled ARDWEENY at the top right (takes less than half an hour to solder one up), courtesy of my pal Jonathan. This is an Arduino clone, i.e. a single-chip microprocessor board with little more than the chip itself and reset and power circuits built in. This particular chip has 32k of program space which means you can be fairly care-free when it comes to the programming language and the Arduino library contains (amongst other things)  a C library for LCD control – hence the display. The original plan was to build a web server to control stuff but a separate Ethernet card wasn’t playing ball so this project got priority instead.

The bright test light you see at the top is being PWM modulated by the chip itself– which is ideal for stepping up to the 12v at a couple of amps or so that I’ll need to power several metres of bright daylight LED strip.

Ignore the protrusion coming out of the top of the micro board, that’s the programmer which is ditched once the development is done – apart from the LCD you’re basically looking at around £8 worth of parts plus the led strip, battery and LCD, oh, and a power supply.

It’s an interesting beast, the Atmel.. part of a family of similar chips, it has several analog inputs – but also some analog outputs – well, not really… in the development kit you can set analog outputs to any value 0-255 but what’s really happening is that under interrupts you’re getting a PWM output. As it happens this is ideal for dimming LED lighting!

This is entirely done in software, no real time clock and I made a pigs ear of the coding, could be much more efficient but with 32K – who cares…  as the Xtal running the chip is pretty accurate so I hope to get this stable to within  second a day or so.

The two buttons work as mode and controls (fully de-bounced in software and with auto-repeat on hold) and the blue preset is just for LCD contrast. I tried using an “analog” output to control the contrast and it’s not very satisfactory. Problem is I’m developing on 5v (from the usb header programming unit) but running the clock on a 3v6 Nicad charged from the 12v supply which runs the LED strip… and the variation causes massive contrast variation with those LCD displays so a fixed resistor is out while I’m developing at least. 

Once the time and alarm time is set, when the alarm time is reached, the light will slowly come on (this is programmable) and once at full brilliance it will stay on, again for a programmable length of time. Should the power fail the battery will continue to keep the unit powered, though at this point I don’t know for how long. Modern LED backlighting is pretty thrifty on power. I may well decide to detect power out on a pin and turn off the LCD backlight to save power!

Things that have come up so far?  PWM’ing LEDS is far from ideal, you would think with a 1% duty cycle on PWM you’d get 1% light output – WRONG, your eyes are not linear and the LED probably isn’t… so even on the minimum setting – the pulse on-off ration of 1-255, you see a very obvious light output… 2-255 is another obvious step… and so on, once you get to about 5% power the steps are no longer visible but this is no-where near as smooth as I’d hoped – I’ve put in additional code to slow down that first part of the brightening phase. I’d smoother the lot with a capacitor but then we go from a very efficient PWM with a simple BC337 transistor to needing something more beefy and I was trying to keep this simple.

While I was working on the software (which now handles AM/PM) I remembered I had some of those DALLAS 1-wire chips lying around. I thought it might be nice to add a temperature sensor in… (thinking about it  – I now have a 24-hour timer with potential temperature control instead of a SAD light – but that’s for another day). The DS1820 is a GREAT temperature sensor. It looks like a transistor, costs a couple of quid and has 2 wires of which you can ignore one.  So one wire goes to ground, the other to a 1K resistor which pulls up to 5v. That wire also goes to a digital input.  There’s a 1-wire library for the Arduino and it took me all of 5 minutes to extract the necessary code to read the temperature in centigrade. This chip is superb, non of yer pesky analog stuff, you simply read the temperature digitally to within 0.5c accuracy. That added a couple of Kbytes or so (and all of 20 lines of code if that) taking me up to 11k of the 32k available.

Perhaps next a musical alarm?

When it’s all tested and working I’ll modify this blog to include the source code.

This is fun!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s