Introduction: Thermometer Moodlight
Moodlights are low-intensity lights that slowly change color and some people find them useful for creating a peaceful atmosphere. Several variations on the theme can be thought of, where instead of randomly changing color or intensity, the color pattern actually conveys some information. I thought it'd be nice to correlate the color to the temperature.
The project is kept cheap and simple by using a very basic 8-pin microcontroller chip (the ATTINY13A), a passive temperature sensor (NTC), a low-power standard RGB LED and some common materials (hand-cream lid, ping-pong ball, discarded USB cable). The cost of the components is less than 2 euros, and no specialized tools are needed, just a soldering iron and a swiss army knife.
So what does it do: this moodlight diplays 13 states dependent on the temperature, in steps of 2 degrees Celcius:
10C : blinking blue
12C : fading blue
14C : constant blue
16C : fading blue-cyan
18C : constant cyan
20C : fading cyan-white
22C : constant white
24C : fading yellow-white
26C : constant yellow
28C : fading red-yellow
30C : constant red
32C : fading red
34C : blinking red
Pretty nice to keep an eye out on rooms getting to hot or too cold!
Step 1: Materials Needed
What you'll need (in approximate order of priority):
- An 8-pin microcontroller of the ATTINY family (I used ATTINY13A, but it should be pin-compatible with the more powerful but less cheap ATTINY85 as well)
- A common-cathode (1 negative, 3 positive pins) RGB led. Diffused is better than clear.
- A 10kOhm NTC (Negative Temperature Coefficient): I favoured this passive component over the apparently more popular digital temperature devices, since they are cheap, robust and extremely simple to use.
- 1 10kOhm resistor to make a divider with the NTC.
- 3 100Ohm resistors to limit the current throught the LEDs.
- A 5x7cm prototype board
- A USB cable (we'll cut it and only use the female connector.
- A mini-switch
- A ping-pong ball as a diffusor
- A hand-cream lid or anything else as a base
- A soldering iron
- A swiss ary knife or other sharp object to puncture holes in the base and in the ping-pong ball.
- An Arduino UNO R3 or compatible to program the ATTINY13A
Step 2: Working Principle
The NTC is a resistor whose value depends strongly on the temperature, in opposite direction to 'normal' materials: at higher temperatures it has less resistance than at low temperatures. It is made from semiconductor, where at high temperatures more electrons are liberated. Its resistence can be parametrized as R=R25*exp(beta(1/T-1/308)), with the temperature expressed in Kelvin (Celcius+273). NTCs exist for many values of R25, while the value of beta is always in the range 3000-5000K. By putting a 10kOhm 'normal' resistor in series, the voltage on the NTC will be half of 5V at 25C, and decrease at higher temperatures.
The voltage on the NTC can be read out with the integrated ADC (analog-to-digital converter) of the ATTINY. It's a 10-bit ADC, so the reading is between 0 and 1023, and every count corresponds with circa 0,1C. The ADC reading is compared to a list of values to determine the temperature and the corresponding state. To offload the tiny memory of the microcontroller, the correspondence between temperature and ADC reading is calculated on a spreadsheet and then copied and pasted to the code. The spreadsheet is attached to allow calculations for other values of R, R25 and beta.
To avoid flickering when the reading is near the boundary between two states, a Schmitt-trigger mechanism is implemented: to change state is has to be at least one count over the threshold.
Three pins are used for light output. To keep the currents under control, each LED channel has a 100Ohm resitor in series. With a 5V supply and a 3V drop on the blue and green channels, the current is ~20mA. The red channel has a 2V drop, and thus a higher current of 30mA. Since the red channel already gives less light per mA than green and blue, I refrained from incrementing the resitor on the read channel (should be 150Ohm to keep that channel at 20mA as well).
Step 3: The Software
The code continuously reads the ADC value assigns the state and decides which LED to turn on. To reduce spikes in the current, only one of the LED channels is on at a time. The ADC readout speed is increased to reduce flicker.
The easiest way to program an ATTINY chip is to use an Arduino as ISP (In System Programmer). Follow the following steps:
Starting up the Arduino IDE, open 'Preferences' then add https://raw.githubusercontent.com/damellis/attiny... for additional board managers.
Under 'Tools/Board', select 'Board Manager' and at the bottom of the list, install 'attiny by David A. Mellis'
Connect the Arduino Uno and upload 'ArduinoISP'. It is available under 'File/examples'
Connect the Arduino to the ATTINY, easiest done by putting the ATTINY on a prototype shield:
Arduino pin 13 - ATTiny pin 7
Arduino pin 12 - ATTiny pin 6
Arduino pin 11 - ATTiny pin 5
Ardunio pin 10 - ATTiny pin 1
Arduino +5v - ATTiny pin 8
Arduino GNd - ATTiny pin 4
Choose 'Board Attiny24/45/85', 'Processor ATtiny85', 'Clock Internal 1 MHz' and programmer 'Arduino as ISP' (attention: not 'ArduinoISP' but 'Arduino as ISP' )
Upload the attached ThermometerMoodlight.ino
Step 4: The Board
There are few components that can easlily be soldered on a small prototype PCB. I used a 5x7cm 'paper' prototype board, cut to fit inside the base. After figuring out the approximate positions of the components, I draw their position and solder them, followed up by their connections. Note that the LED is mounted on the opposite side of the other components! Finally, the power cables are connected, eventually in series with a switch so that it can be switched off without unplugging cables.
Step 5: The Base, Diffusor, Cable and Scale
The device runs on 5V, so a USB power supply is perfect. You can take a USB cable and cut off the male part.
For the base, a lid of a hand-cream pot works well. Poke a hole in the centre, large enough fo r the LED to go through and a hole on the side large enough for the USB cable to pass through. Make a knot so that when pulled, the force doesn't get to the connections of the cable.
A ping-pong ball diffuses the light very well. Poke a hole in it of about 1 cm and glue it on top of the base!
Finally, the scale can be printed and attached with glue or tape to the base.