HW2 : Hue hub Controller
Updated: May 12, 2020
This past two weeks, I was working on creating a hue hub controller to control the Philips hue light bulb trough the Hue Hub. Trying to connect Arduino to hue hub using HTTP clients is simpler than its sound. There are four main functions in my controller. The first function is the switch control. I use two toggle switches to control the on/off state and changing the controlling mode for the light. Another function is the adjustable knob using a linear potentiometer to adjust the light value according to mode. In the third function, I embed one LED light to illustrate the color of the bulb. The last function is the screen showing the state of wifi connection and light mode and value.
Here's the demonstration video!
Arduino Nano 33 IOT (from Physical computing kit)
Toggle Switch x 2 pcs (from ITP)
Wifi and HTTP Client
Adafruit_SSD1306 (include SPI.h and Wire.h)
Circuit diagram & Code
1. Toggle switch
I connected both legs of the on/off switch with pin 2. So when the switch moves either side, the value of the pin 2 is changing. For the mode switch, I connected one leg to pin 3 and another to pin 4. So when the switch moves to the left, it'll trigger pin 3 and another side trigger pin 4.
2. Neopixel >> pin 5
3. Linear Potentiometer >> pin A2
4. OLED screen >> connection from Adafruit tutorial using SPI connection
The most challenging part of this code is how to make the HTTP request send only when I want and stop when the movement finished. The method I choose is to store the value of the potentiometer and compare between the last update and recent value. The request is sent only when the gap of the value is bigger than the threshold. I found the example code of how to store the analog signal value on the Arduino forum. Thanks to all the people who contribute to this forum!
After testing, I decided to change the push button to the toggle switch, because it seems more consistent.
In the fabrication part, I decided to use white acrylic to make the enclosure. I divide the enclosure into three levels by using the stand-off as a structure. On the cover, I engrave some labels to declare the function of the buttons and also attached most of the components with this sheet. The middle part is for attaching the potentiometer and dividing the wires. Lastly, I embed breadboard and Arduino on the base.
Problem I found
- The value of the potentiometer is fluctuating because of the 3.3 v supply from Nano. I try to map the value and multiply to reduce the noise. It seems better but most of the time it still fluctuated.
- There are some delays when I sending the request from the controller to the hub. I try to store the value of the potentiometer and send request only when the number is bigger than the threshold. It seems work but sometimes it still sends requests twice. (sometimes it happens because of the fluctuating value of the potentiometer)
- I can not keep the value of the potentiometer when I switch mode. For example, when I want to set up the hue at maximum value and switch to saturation mode to change the saturation, the saturation number is jumping to the maximum value automatically. I guess because I have only one potentiometer to control values. If I have to improve this I might make save the value button to store the value when the user finishes adjusting.
- The value of the Neopixel is not exactly matched the hue bulb. I try to change the color mode of the Neopixel into HSB mode. but it's still not matched.
From making this device, I learned a lot of new extra stuff beyond the assignment such as how to read the library, how to use toggle switch and screen, which is really useful. It was such a wonderful growing moment for me :)