Arduino powered, temperature sensing, RGB LED nightlight

September 4th, 2012

About a year ago I started on a project to make a temperature controlled nightlight. I was inspired by seeing these lovely LED lamps styled as mushrooms growing out of pieces of wood. Those mushrooms were made out of glass, which was somewhat beyond my skills. However I then saw some had used translucent sculpey to make mushroom nightlights on instructables. So with that discovery it seemed like it would be rather simple to do…

The first job was to solder up a three colour (RGB) LED (a super bright one from oomlout):


Wires + RGB LED ready for coating in Fimo

I then covered the LED in translucent Fimo:


RGB LED and wires covered in Fimo

As Fimo only needs to be heated to about 100C to set it’s ok to do this, as it won’t hurt the LED. Also LEDs don’t normally give out much heat, so covering them is ok. Of course this is a relatively low power (though quite bright) LED as well which helps.

I found a branch on the way home from work, which I cut up and sanded down. This formed the base for the mushroom:


Testing fit of fimo covered RGB LED

As you can see I also opted for a chunky on/off button, in the style of the original mushroom lamps.

Next I put a small electronics project box into the bottom of the piece of wood and made space for a slide switch and power socket:


Power socket, slide switch and latch switch soldered

At the time I decided to try to use a Picaxe 08m chip to control the LED and read from a temperature sensor. The Picaxe 08m has a native function to read the temperature from a DS18B20 One Wire digital temperature sensor. It also had just about enough inputs and outputs to handle controller the three colors of the LED and reading from a slide switch (to make it switch between temperature display and plain nightlight). The individual chips were also pretty cheap, so it seemed like a good plan at the time.

However the size of the circuit and number of components I needed to solder was all a bit too much for me:


Red means fail

Eventually after much debugging I was able to get some things working – e.g. controlling the colour of the LED, but the temperature sensor just wouldn’t cooperate and always gave a high reading. I also managed to get through a few sensors due to mis-wiring them!

So I decided it was time to start again with the circuit. I bought a better soldering iron (a not too expensive digital temperature controlled one) and started on a new circuit:


Nightlight circuit take 2
Lots of jumper wires on nightlight circuit attempt 2

And before I could finish everything I lost impetus (an active toddler and a lack of sleep may have played a part) and the project sat on a shelf for nearly a year.

Then after discussing a friend’s Arduino experiments I realised that maybe I could use an Arduino Pro Mini to finish the job.


Comparing size of Arduino pro mini to original nightlight circuit

The Arduino was a lot more powerful than the Picaxe chip, with several K of RAM (vs. the 512 bytes for the 08m). Though it was overkill and cost more than the Picaxe chip it would make my life a lot easier. The Arduino gave me a 5V regulated power supply, so I could use the slightly simpler to read from TMP36 temperature sensor. I could also use internal an pullup resistor for the slide button. The other advantage to all that processing power was that I could use PWM (Pulse Width Modulation) when controlling the LED to produce a full range of colours. With the Picaxe I could only really have seven colours, with no smoothing between them. As this was intended to be used in the aforementioned toddlers bedroom having nice smooth transitions between colours was very appealing.

I soldered together the LED, switch, sensor etc to a small piece of perf-board with some female headers for mounting the Arduino too. I had to do a bit of work with a dremel to create more space, as the new setup was a bit taller too.

At this point I could then start programming the nightlight by hooking it up to a regular sized Arduino.


Nightlight working when wired to regular Arduino

This was great as it proved that everything was working fine and I could just focus on the code. It also meant I could do things like temporarily wire in a potentiometer instead of the temperature sensor, to make debugging the code simpler:



It was at this point that I then discovered what could have been a disastrous miscalculation – I spaced the headers for the Arduino Pro Mini too close together! Bit too much haste and perhaps a bit too little sleep, meant that I nearly had to start all over again for the fourth time! Luckily I found that as the headers were only 0.1″ closer together than they should be I could use some extra long male headers soldered on to the Arduino and bent to compensate:


Creating slightly offset headers for Arduino pro mini

Then it was a case of programming the Arduino Pro Mini using a serial adapter (carefully balanced so as to make contact correctly). I found I had to reset the Pro Mini and un-plug and re-plug the USB cable to get it work properly, but once the connection was good I could reprogram the board easily enough.


Programming Arduino pro mini with code for nightlight

All was good, so I decided to try out the nightlight by testing in different temperatures. The fridge seemed like a good starting point:


Testing nightlight in fridge

Luckily the weather was fairly warm that day too:


The nearly finished nightlight

I recorded a timelapse of the LED’s colour change as the temperature warmed up:


Changing color of nightlight after warming up from being put in fridge for a while

Sadly although the nightlight was responding to the change in temperature, it appeared that left to it’s own devices it would tend to warm up over a few minutes and then read a couple of degrees higher than it should. Without the bottom cover on it too longer to do this, so it was clearly some sort of a cooling issue, as it still read higher again if I turned the nightlight off then on again. I think I should have placed the sensor much further away from the rest of the electronics and made sure it was well ventilated.

So to help stop provide a little cooling/ventilation I ended up carving a wooden base our of pine, that I could drill a hole at an angle for cooling with an exit hole in towards the top of the main section. The base also gave the nightlight a bit more heft and made it easier to turn on/off as well as to operate the switch to change it from temperature to simple nightlight.


Wooden base for nightlight Nightlight on stand (rear view)

Despite the slight disappointment that the temperature reading wasn’t going to stay constantly useful, I am quite happy with the nightlight. It looks nice and will does work well as an actual nightlight. The temperature reading facility has been proving useful to see what the temperature of William’s room is like and therefore what sort of nightclothes would work best. Given how protracted it’s development has been I’m rather happy really. It’s also rekindled my respect for the Arduino platform. The Mini Pro in particular is great. It’s very small, but extremely powerful and as it’s a bit cheaper than a full size Arduino makes it more appealing for embedding it into a project permanently. I guess the only downside would be the lack of integrated USB connection (for serial IO), but that’s not needed for every project.


Nightlight on stand Nightlight on stand

As usual source code is available in my Arduino Sketches github repo (plus a Fritzing wiring diagram of the circuit).

Blinking Halloween Spider Eyes Hats using PICAXE 08m chips

November 1st, 2010

For some reason I got seized by the idea of creating some electronics for our Halloween costumes this year. In previous years I have gone as far as dying my hair green for Halloween, but that is just an evening’s work. This year we were having a more sedate affair – it being our first Halloween as parents.

We settled on making spider costumes. Basically black clothing, with extra arms made out of tights. I then decided that as spiders have eight eyes that making some hats with six extra eyes would make sense. After initially thinking I would just hook up some LEDs straight to a battery I decided to massively complicate matters by and try to make them blink periodically (at random).

So for this act of over-complication I chose to use the PICAXE 08m microprocessor. The core circuit (minus ability to program) is essentially just 3AA batteries, the chip itself and two resistors – so at least for a circuit involving a microprocessor wasn’t that byzantine. That is kind of the point of a microprocessor though. To the end-user it hides it’s internal complexity away. I don’t really need to know how many hundreds or thousands of transistors it contains internally. I only need to think about how it fits into my circuit.

I chose to have six LEDs to create pairs of “eyes” that would blink in tandem. This meant the PICAXE chip would turn three output pins on and off at random intervals. With a 4.5V power supply two LEDs wouldn’t need a massive current limiting resistor – 100Ohm would be sufficient. So the circuit consists of the 08m chip, two resistors (10KOhm and 22KOhm) to pull-down the serial-in pin, a 100nF capacitor to even the power supply, six LEDs and three 100Ohm current limiting resistors:

It’s not actually that complex a circuit, but spending several hours soldering it up (twice) for a couple of hours at a party might have been overkill. Still it was good practice. I also got to try out fitting everything into some project boxes and generally making things look “proper”.


Underside of circuit

Finished soldering the LED eyes

Making sure it all fits in project box

I used perfboard for the finished circuit, with some holes enlarged to accept screws for the project box. I also added some extra holes so I could loop the power and LED wires through. This helped to make the connections nice and sturdy.

The chips were programmed using a different circuit, with the serial adapter attached and were then removed from their sockets and inserted into the soldered circuits. The two hats had slightly different programs uploaded to tweak the speed and random nature of the blinking (so they wouldn’t be too similar). The code is viewable at my picaxe08m repository on github (as well as a Fritzing file for the circuit). I did encounter a bug in the PICAXE compiler whilst writing this code. When I started using subroutines (and the gosub call) MacAXEPad would suddenly say “Hardware not found” when attempting to upload. Apparently this problem only affects the Mac version of AXEPad. Luckily there was an easy fix – simply adding a dummy sub-routine at the end of the file:

interrupt: return


The Eye Hat

The finished result looked a bit goofy, but it did work. The main problem though was that it only really worked when the light was low. Not a bad problem for halloween I guess:



Programming a Picaxe 08m chip

September 18th, 2010

After I got my Arduino I felt the urge to brush up on my general electronics knowledge. The last time I’d really played with any circuits was back in about 1994 when I was studying my Technology GCSE – which now is quite a long time ago. So I picked up a copy of Make: Electronics and started reading through it. Sadly I was a bit lazy and just read through the book, rather than actually building many of the circuits suggested. It did come in handy for tips on soldering and I do intend to go back and make some of the circuits – I just got a bit distracted by a new arrival. However the last chapter covered microcontrollers and in particular the Picaxe 08m chip. This really piqued my interest!

The Picaxe 08m is a PIC chip with a pre-installed boot-loader that allows programming the chip via a serial port. This is similar to the way that the Arduino has an AVR chip with a pre-installed boot-loader. There’s also some software for the Picaxe for handling the programming, a bit like the Arduino IDE.

The 08m is massively less powerful than an Arduino. It has 512 *bytes* of program storage and only 14 *bytes* of variable RAM. However it has 5 outputs/4 inputs and can run a single servo. In fact I could have used it for the logic part of my Arduino doorbell. It’s not quite as friendly to get started with as an Arduino though. You need to wire up a simple circuit before you can get going. In fact I actually had to solder together a prototyping board, as I didn’t have much luck trying to used a breadboard. The circuit needed isn’t that complex (assuming you use 3AA batteries for power). The cost of the 08m chip is less that £2. The proto-board is £2, so altogether you can have a simple usable microprocessor for less than £4. It’s also small and doesn’t use much power. So for projects where an Arduino is overkill it’s perfect.

Soldered picaxe 08m prototype board

To make testing out circuits easier I also added a female header to the board, so I could plug in breadboard jumper cables (in the same way as one does with an Arduino Duemilanove):

Picaxe 08m prototype board with header attached

To verify everything worked I wrote the “hello world” program of microcontroller world, a program that simply blinks an LED (by turning pin 1 on and off):

main:
	high 1
	pause 1000
	low 1
	pause 1000
	goto main

That’s Picaxe BASIC by the way. Maybe not as pretty as C, but for a processor with only 14 byte sized variables it’s more than enough.

Then I wired up an LED into the prototype board, along with a small current limiting resistor:

Picaxe 08m prototype board + header blinking LED

Using the Mac version of AXEPad and the Picaxe USB serial cable (which has a stereo socket at one end) I uploaded the program to the 08m chip and saw the LED blinking once every second. I’ve recorded a video of the programming, which should show how straightforward it is:

I’ve got a few projects in mind that are actually space/weight constrained and one in particular that might put the parts involved into extreme peril, so having the option of using a very small and cheap microcontroller is very appealing. I’ll reserve the Arduino now for projects that need it’s extra power and amazing flexibility.