Zápisník Josefa Rouska

Python a React.js programátor zaměřený na Shopify integrace

Wireless RGB lamp

For a long time I wanted to have a wirelessly controlled RGB light in my kitchen. This idea got more specific shape when I saw hacked IKEA dioder light where original PIC microcontroller was removed and ATTiny took its place. This wasn’t the one I ended up using, but I think it’s worth mentioning. I have decided to use 5,1W RGB LED along with ATMega328P with Arduino bootloader and XBee for the wireless connectivity.

Arduino is running on 3,3V so it can safely communicate with XBee which means the only special circuit needed is LED controller. Controller consists of three BD139-16 transistors and three high power resistors. Base current is limited by 470 ohm resistors. Thing which scared me a bit when I was testing this circuit is that high power resistors were getting pretty hot. But values I measured were correct and yeah, it’s good idea to check datasheet. I found that high temperature is normal. There is another thing worth mentioning. Don’t forget to connect AVCC pin to VCC, because it is required when running on 3,3V with BOD enabled. You will save yourself few hours wondering why the hell it doesn’t work on 3,3V.

XBee I’m using is XBee Series 2 with API firmware, because it allows me to easily create mesh of devices. My current setup is XBee Controller connected to Netduino Plus and two end devices. Wireless LCD and RGB Lamp. Netduino serves as gateway to the internet (for temperature sensors) and LAN (for controlling lamp). Netduino runs lightweight webserver and when request is received it sends ZigBee packet to the lamp. This way I can change mode by visiting http://192.168.1.95/mode/mode_id. I can do the same on Wireless LCD so I don’t have to run to my PC every time I want to control the lamp. I will describe both ways in future posts.

Firmware is pretty straightforward. It listens for commands, stores settings on EEPROM and fades the led. Commands are received in form of ZigBee Receive packet where first byte specifies command id and following bytes are different for each command. Commands are described in table below.

Commands

IDNameDataDescription
20 Fade delay high byte, low byte 0 - 65535 milliseconds
21 Mode mode id 0 - disabled, 1 - single color, 2 - fading, 3 - strobe
22 Color color id 0 - Red, 1 - Green, 2 - Blue, 3 - Yellow, 4 - Cyan, 5 - Orange, 6 - Magenta
23 Color red byte, green byte, blue byte 0 - 255 for each color
24 Status returns current settings in format: 25, mode, [fade delay] high, low, [color] R, G, B

Schematic

Part list

IDDescriptionCount
R4, R5, R6 470Ω 3x
R2, E3 4,7Ω 2x
R1 8,2Ω 1x
T1, T2, T3 BD139-16 3x
RES1 Ceramic Resonator 16MHz 1x
D1, D2, D3 L-LXHL-HPRGB 1x
IC1 ATMega 328P 1x
IC2 XBee Series 2 1x

Source code

Source code is available on Github.