My family members are spread out in different cities. There are days when we miss each and it is not enough to just call and talk all the time. I wanted to provide an unobtrusive way for us to keep in touch. Then I came across this project by John Harrison - Networked RGB Wi-Fi Decorative Touch Lights (https://www.hackster.io/team-filimin/networked-rgb-wi-fi-decorative-touch-lights-a6c9c8). It was a perfect solution and it can be used by anyone to keep in touch with their loved ones. I decided to use the new ESP module and an online MQTT server for the connection as it would be cheaper. Further, I developed the code from scratch and hosted the MQTT server on a raspberry pi.
These are the heart of the project. This is how the users interact with each other. The lamps are designed to respond to the touch of the user. I bought a lamp online and removed the bulb holder and installed my circuit board on that. Further, the lamps also need to talk to each other over the internet and also need decent programming capability. The ESP module is able to perform all these functions at a very low cost.
To achieve all these functionalities, the lamps are equipped with a touch sensor, a Wi-Fi module and a RGB led. Since the touch sensor is small component, I connected the sensor portion to the top of the lamp using a conductive tape and aluminum foil. This had an unexpected benefit of making the touch sensors to be proximity sensors! The capacitive effect of the sensors expanded beyond touch.
They communicate with each other over Wi-Fi through a MQTT server and therefore they can be placed anywhere.
The ServerSince all the lamps talk over Wi-Fi, there needs to be a server running which can coordinate the lamps. I initially used an online MQTT server which was easy to set up. However, the server crashed one day. That’s when I decided to create my own server on the raspberry pi and it has server me faithfully. The setup was a little bit of a hassle to set up a DDNS for the pi, but once I got the server up and running, it worked flawlessly. I hosted the DDNS server on freedns.afraid.org
Once the lamp starts, it looks for the saved Wi-Fi signal to connect to. If it cannot find one, it will then start up a Wi-Fi hotspot to which the user can connect to and input the Wi-Fi SSID and password. This feature is from the library WiFiManager library and it creates a reliable platform to connect to the Wi-Fi network.
Once the internet connection has been established, it attempts to connect to the MQTT server. This should take about 3 minutes to happen.
After the MQTT connection has been established, the lamp waits for a touch input or a signal from the server. If a touch has been recorded, it sends a message to the MQTT server that the lamp has been touched. Each lamp is assigned a number and the lamp sends this information along with the message. As MQTT works, the message is transmitted to all the other lamps who are subscribed to the topic.
Once a lamp receives a message of a touch, it changes the colour to match the encoded colour. The lamp that transmitted the message itself will change colour only once it receives the message back from the MQTT server.
LEDs change colour almost instantaneously which is not a very pleasing way to change colours for this project. Hence, I wanted a gradual way for the lamps to change colour. To achieve this, I simulated a PWM for each of the 3 inputs to the RGB LED and varying the duty cycle to either dim or brighten the LED. This change greatly improved the look and feel of the lamps.
Challenges FacedThis project, as with most projects had its share of problems, big and small. I will talk about a few of the main ones.
Coding on the MQTT. This is a relatively new product with relatively few documentation available online. I initially used the programming language LUA. The programming style was completely new and took me a while to get the basic functionality working. Even then, once I moved to the advanced portions of the code, the language got complicated. I then decided to move to the more stable arduino and managed to complete my code successfully. Another thorn in the coding for ESP was that the CPU could not be idle for more than 1 minute at a time or else the Wi-Fi will get disconnected. This placed huge restrictions on the use of delay functions and created bugs in the code that took days to be resolved.
There were many libraries available for the ardunio that can be used for the ESP, but there were multiple libraries performing the same task and choosing the library the suited the project was a challenge. Further, since the many libraries used (MQTT and Wi-Fi manager) are interlinked, porting the code from one library to another was a challenge.
Once I got the software side of the project in a decent shape, I had to battle with the hardware to integrate the touch sensor. Since the delay functions have problems on the ESP, the switch debouncing was a challenge to meet.
Final ProductMy plan was to gift the lamps to my parents on their wedding anniversary. It was just around the corner so I worked over time and managed to get it working in time! They have a lot of fun playing with it daily!
Here is my mom controlling the lamp from another country. My lamp is configured to be green (you can notice the change in the middle)
My sister took the idea to a new level, she made a custom case for hosting the ESP and it looks really cute!
Overall, I am really pleased to create a product that my family members can actually use on everyday! The possibilities of the world of IoT continues to amaze me.
Comments