Introduction: Lei: the IoT Wi-Fi Ambient Lamp
In this project, we prototyped a 3x3W rgb IoT ambient lamp that can be controlled through the internet using Lelylan and any web browser anywhere in the world.
The lamp was initially designed to be kickstarted, but due to a lack of time and a lot of other stuff, we stopped further developments and decide to release our work as is.
All the software has been developed under Ubuntu so we will use the Energia IDE which is 'needed' for the cc3200 TI Launchpad.
Step 1: Materials
The materials needed for this project are:
- 3x TIP122
- 9x resistors 10ohm 1w
- 3x rgb led 3W common anode (R: 2.0-2.4V, B/G: 3.0-3.4V) (4 USD each)
- 3x resistors 1kohm
- 5v 3A power supply
- TI cc3200 launchpad board (29,99 USD)
- Power supply female plug
- Some cables and jumpers
In terms of non-electronic material you'll need:
- Thin (5mm) Styrofoam panels to create the cube or a custom opaline plexiglass cover
- Some wood panel for the base
- Energia IDE that fully supports the cc3200 and acts exactly in the same way the arduino IDE does.
Step 2: Wirings
In the first test we used only 2 of 3 leds to lower down the cables, a 6v power supply (4xAA batteries)
The circuit is very simple, with the cc3200 we have to control 3 channels (red, green and blue) for each led simultaneously, so we will use 3 pwm pins of the TI board:
P02 -> blue
P64 -> green
P17 -> red
Given that only some mA can be drawn directly from the Launchpad pins, we will need to use some NPN transistors like the TIP122 to control each different channels. Following the second figure we will need to connect:
base -> 1KOhm resistor -> cc3200 color channel that you want to control (P02 || P64 || P17)
collector -> corresponding negative color channel of all 3 leds (See fig.1)
emitter -> GND
We now only have to connect the positive leads of the leds to the power source. We choose to use a 6v power supply able to support up to ~3A, so 15W should be enough for powering our 3x3W leds. 6v is too much for our leds (R: 2.0-2.4V, B/G: 3.0-3.4V) so we need to use some resistors to lower the voltage, but how much bigger should they be?
Given the Ohm's law ∆V = I*R
(we use the lower limit so 2.0V for red and 3.0V for blue/green)
R(r) = ∆V / I = 6v - 2v / 0,35A = 11.42 Ohm
R(b/g) = ∆V / I = 6v - 3v / 0,35 A = 8.57Ohm
The choice of what kind of resistor is driven also by the maximm amount of power (read Watt) that it can dissipate.
P = ∆V*I
so our resistors need to be able to dissipate (at peek)
P(r) = ∆V*I = (6v - 2v) * 0,35A = 1.4W
P(g/b) = (6v - 3v) * 0.35A = 1.05W
we choose some 10Ohm 1W ceramic resistors because were the only one that we could find easily.
Finally all resistors need to be tied togher and connected to the power source (+) on one side, on the other they shoudl be connect to the 9 terminals of ours 3 leds as in Fritzing diagram. Also +5v on Launchpad need to be connected to batteries (+).
At the very end we can connect all the GND together (power supply (-), Launchpad, transistors) and the pink cable (see fritzing note) for programming.
We are now ready to code!
Step 3: Programming Lei
The lamp works like that:
- when is turned on, it connects to Lelylan and subscribes to a topic that rapresent the device, virtually.
- when we interact with the lamp through the dashboard, the lelylan mqtt broker sends an update to all the topic subscribers, in this case only the physical lamp.
In order to get the cc3200 working with lelylan we need to be able to connect and interact with an mqtt broker and to write and parse JSON data. So 3 libraries need to be included in the sketch
- PubSubClient (which should be already included in Energia IDE, you'll need to set the MAX_PACKET_SIZE to 512 bytes (needed for Lelylan to work).)
- ArduinoJSON (which can be downloaded here)
- Wifi (which should be already included in Energia IDE)
Lelylan works by rappresenting physical devices as virtual objects, so we have to create a virtual device in the dashboard and get the relative DEVICE_ID and DEVICE_SECRET needed in the sketch (see this guide for the arduino yun for an overview on how to setup you Lelylan device). Every virtual device has a type that defines what properties and methods can be used on it. We created a custom light type called 'Lei' http://lelylan.github.io/types-dashboard-ng/#/types/54986532bbd5a4c34c000001/
After setting up the device id and secret there are a couple other parameters needed:
#define WIFI_SSID "XXX"
#define WIFI_PWD "XXXXX"
#define DEVICE_IN_TOPIC "devices/____YOUR_DEVICE_ID____/get"
#define DEVICE_OUT_TOPIC "devices/____YOUR_DEVICE_ID____/set"
The sketch simply allows our lamp to listen and apply updates received from the Lelylan dashboard.
The code (that should be embedded) is commented and should be pretty straight forward to follow, anyway if you have any question don't hesitate to contact us . Due to some indentation issues I suggest you to check the code out on my gist https://gist.github.com/bugduino/6e33999e53c5c98d87d5.
There are some part still unfinished (like the rainbow mode, which will use the setFade function) if you want to submit the patch I'd be pleased to update the code.
Step 4: Let's Shrink It
The initial prototype was made on a breadboard, but it needs to be shrinked to fit inside a real lamp so we built a simple shield for the Launchpad that allow us to occupy less space.
All leds can now be connected through some handy pins on top of the board, we have 9 separate leads one for each of the positive lead of the led and other 3 pins for connecting r, g and b channels.
We also introduced a separate power for the shield.
Step 5: Basic Design Prototype
At the beginning we build a simple half-cube in plywood for the base and on each side we put one of our leds.
The cube on top has been made with polystyrene and is around 25cm per edge, with a cube removed of about 6cm per edge.
Step 6: Wood and Plexiglass = Done!
The final iteration of the product include a more polished base in wood and a plexiglass cube.
The base sides were no longer inclined at 45° so at first we didn't realize that our cube wouldn't fit correctly and we ordered a wrong cube (also much taller than the last one).
After realizing that the cube dimensions wasn't correct we ordered another cube, this time with a 60° angled hole in the cube and with a correct 25cm edge.
If you like this project or have any feedback don't hesitate to tweet me @bugduino.
We have a be nice policy.
Please be positive and constructive.