Introduction: PhotonLamp - a WS2812b Equipped Designer Lamp With MQTT Control
Several years ago we bought a designer lamp which had a lamp shade in form of a cigar and was made out of milk glas. We liked the particular design of the shade and the overall appearance of the lamp. But i've been not really satisfied with the light which came from five small standard light bulbs. Since the shade has a rather small radius, you got no continuous light impression but you could see the single bulbs through the shade. When i stumbled across a WS2812b LED stripe an idea was borne: I wanted to convert/upcycle the lamp and replace the standard light bulbs by RGB LEDs. Not to mention that the "new" lamp should be controllable by Wifi to get a higher WAF 8-).
Step 1: The New Innards of the Lamp - Partlist
Since i already did some projects with Particle Photons (https://particle.io) i choose this really neat controller as the base of my project. Summarized i needed this hardware to build my lamp conversion:
- 1x 90cm pipe with M6 metric thread on one end
- 1x Particle Photon
- 1x HC-SR04 ultrasonic sensor (for a special twist)
- some wires to connect the parts
- 1x AC/DC 5V/2A power supply
- power connector for the base of the lamp to plug in the power supply
- 1x WS2812b LED stripe with 30 LEDs per meter (3m length)
- A designer lamp
Step 2: The Wiring
The setup of the wiring is really easy: As shown in the fritzing drawing you have to connect the power supply with the Photon on pin VIN and GND and with + and - on one end of the first LED stripe. The HC-SR04 is connected by two rather long wires with pin D2 (TRIGGER on HC-SR04) and D3 (ECHO on HC-SR04) of the Photon. The pin D4 of the Photon connects to DI of the first LED stripe.
Step 3: The Hard Part - Assemble the Pieces
The LED stripes are self-adhesive, but i secured them with some additional cable ties (see detail pictures). To keep the wires as short as possible i decided to wire the four led stripes in zigzag - pin D4 of the Photon is connected to DI of the first stripe, DO of the first stripe is connected at the top end of the pipe to DI of the second stripe. DO of the second stripe is connected to DI of the third stripe at the bottom of the pipe. DO of the third stripe is connected to DI of the fourth stripe at the top of the pipe. The VCC and GND lines of each stripe are connected the same way. The wires for the ultrasonic sensor are the longest and run through the inside of the pipe.
The power supply is connected to a socket i put into the hole in the base of the lamp where in the original version the 220V power cable went through. Power cables go from this connector to VIN/GND of the Photon, to VCC/GND of the led stripes and to the ultrasonic sensor.
Step 4: The Soft Parts - Firmware Available on Github
The firmware is available in this git repository on Github:
If you use the same pins to connect LED strip and the HC-SR04, the only thing you have to change before compiling the code is to create a file "MQTT_credentials.h" in the "src" subdirectory which contains three lines:
#define MQTT_HOST ""
#define MQTT_USER ""
#define MQTT_PASSWORD ""
There are several good guides how to setup a mosquitto server which you can easily find by using your favorite search engine...
Step 5: The Firmware - How to Use the MQTT Connection
I use a Rasperry Pi 3 with mosquitto (http://www.mosquitto.org) as MQTT server, please refer to it's documentation on how to set it up. You may subscribe to the topic ([device id]= ID of your Particle Photon):
to see if it's successfully connecting to the server and if it's able to post it's status:
The output should look like this ([device id] = ID of your Particle Photon):
/[device id]/state/DisplayMode 8 /[device id]/state/Brightness 250 /[device id]/state/ForgroundColor 100,023,014 /[device id]/state/BackgroundColor 034,006,034 /[device id]/state/MaxDistance 92 /[device id]/state/LastDistance 92 /[device id]/state/CurrentDistance 92 /[device id]/state/FirmwareVersion 0.6.3
The exact output may depend on the version of the firmware you're using.
But there's more fun in it: By publishing to:
/[device id]/set/[parameter] [value]
you may change the pattern which is displayed as well as some colors.
- To change colors send:
/[device id of Particle Photon]/set/ForgroundColor/[red],[green],[blue] /[device id of Particle Photon]/setBackgroundColor/[red],[green],[blue]
For [red], [green] and [blue] insert the decimal values of the respective color.
- To change the display pattern send:
/[device id of Particle Photon]/set/DisplayMode [value between 1 and 11]
Current implemented display modes are:
- Spiral (in development)
Some of them are from the example section of FastLED.
- To change brightness send:
/[device id]/set/Brightness [value between 1 and 100]