Hardware Details

The Radiator Knob Controller

A major aspect of my device is being able to physically turn the radiator knob clockwise and counterclockwise in order to turn the radiator on or off. This mechanism is driven by a stepper motor attached to a 3D print that fits onto and tightens around my radiator knob. The stepper motor is powered by a motor drive controller that is connected to a 24V DC wall power supply. All of this is controlled by an ESP32-CAM module, which was very cost-effective because it was an extra ESP32 module that came with the kit provided with the class and added no immediate cost to my project. This is programmed using an FTDI programmer.

As seen on the left side of the image below, I use an arm with clamps on both ends to hold the motor in place while turning the radiator knob. I wasn't able to get a picture of my device on my actual radiator in my apartment as I am currently back home, but I was able to get the general set up on my table. Some differences are that the C clamp currently fastened to the table would instead be attached to the valve between the radiator knob and the radiator. The two limit switches attached to this clamp would also need to be adjusted as the radiator knob is higher off the ground than the radiator valve. 

In my original design, I was planning on adding gearing in between the motor and the 3D print in order to increase the torque as the radiator knob can be very sticky and hard to turn. However, I realized that I could eliminate this step by increasing the power supply to 24V from the original 9V I was testing my prototype with, which allowed the stepper motor to output much more torque. This freed up time to add features like a physical thermostat into my project.

Radiator Knob Enclosure

This 3D print fits onto and tightens around my radiator knob. It has a special D shaft cut out that is a perfect fit for the stepper motor. The 3D print also has a slit going through the entire model that allows the print to be loosely put onto the knob and tightened to hold onto the knob.

The bottom of the 3D print shows the cutout for the radiator knob to fit into and also the hose clamp that allows the print to tighten. There is also a rubber lining on the inside of the cutout to allow maximum friction between the print and the radiator knob.

Thermostat/Webserver

Another aspect of my project was creating a physical thermostat that can be placed anywhere in the room. At the heart of this is a DOIT ESP32 devkit that controls all the peripherals while also acting as the webserver. Some of these peripherals include an OLED display, temperature sensor, and rotary encoder. The OLED display communicated through SPI and so needed 5 pins for MOSI, CLK, DC, CS, and reset. The temperature sensor only needed one GPIO pin as it relayed the data digitally. The rotary encoder needed three pins. The whole device is powered by a battery pack that holds 4 AA batteries (6V), which is reduced to 3.3V by the voltage regulator.

Software Details

On the software side, I decided to use the Arduino IDE as it was relatively simple to use and provided many ready-to-use libraries and example code.

Webserver/Website

As mentioned before, the webserver was hosted on the DOIT ESP32 devkit driving the thermostat. I was able to set up the webserver by using the ESPAsyncWebServer library and connected to the WiFi using the WiFi libraries. I then used SPIFFS to upload the HTML, CSS, and JavaScript files for my website onto the ESP32 module and was able to serve them for each HTTP_GET request through using ESPAsyncWebServer. 

I was also able to get devices communicating with each other through the webserver using WebSockets. This was also implemented using ESPAsyncWebServer. I used the ArduinoJson library to send data as a JSON file between the website and the webserver. This library allows the serialization and deserialization of the JSON file as it is sent as a string. This would be used to send the real temperature from the webserver to the website along with the temperature set on the thermostat.

The website would be able to connect to the webserver via WebSocket through its JavaScript file. The JS file allowed the updating of information on the website when a new WebSocket message came in and would also facilitate what JSON data was sent back. This included the set temperature on the website to the web server along with if the motor should be turned on or off depending on if the set temperature was higher or lower than the real temperature. The website also had buttons that lowered or raised the set temperature on the website and updated it accordingly. Any change to this would then be sent back to the webserver to update the temperature on the thermostat.

Thermostat

The main peripherals I needed to code for were the temperature sensor, OLED display, and rotary encoder. The temperature sensor was relatively simple to implement as it sent the data digitally through a GPIO pin. This was interpreted using the OneWire and DallasTemperature libraries and saved as a variable. This would then be sent to the website as the real temperature via WebSockets as a part of the JSON file. 

The OLED display was also pretty simple as it was driven by SSD1306, and so I was able to use the Adafruit_SSD1306 library to connect to the ESP32 module through SPI. I was also able to drive the display by using the Adafruit_GFX library and was able to find some nice example code for it in the ArduinoIDE. I used this to display the product name and also the set temperature of the thermostat.

I used the Encoder library for the rotary encoder. The rotary encoder allowed me to change the temperature on the thermostat display. This was done by counting how many turns were made on the dial, which was then subtracted by the set temperature. Once this new temperature was calculated, it would update on the OLED display as well as sending this data to the website via WebSocket to update the set temperature on there as well.

The Radiator Knob Controller

The software for this device includes the libraries Stepper, WiFi, and WebSocketClient. The Stepper library allowed the pins to be set on to control the motor as well as the speed and direction for the stepper motor. The WiFi library was used in conjunction with the WebSocketClient library to make the ESP32 module a WebSocket client to the thermostat ESP32. This allowed the module to receive the command to turn the motor in order to turn the radiator on or off. 

The limit switch stopped the motor from moving more than one rotation in either direction, which prevented the knob from overrotating. This was implemented by using a digitalRead to see if the switch was being driven low or high, which means pressed or not pressed respectively.  There was a loop for the motor to turn one step at a time in its given direction while the limit switch was not yet pressed. Once it is pressed, the motor will do nothing until its given direction is opposite of the direction it is currently stopped in. The motor will then move in the opposite direction until the switch is not pressed, in which it will resume its typical behavior defined in the loop.

Future Steps and Closing Thoughts

Even in its current iteration, there are still many improvements I can think of making on my project. Although I used the ESP-CAM because it came with the lab kit for the class, it would have been easier to get another DOIT ESP32 devkit as there were a very limited number of pins to use on the ESP32-CAM (camera and SD card taking up most of them) and connecting GPIO pin 0 to GND every time I had to flash was a hassle. Additionally, I am currently driving the inner circuitry for the motor drive controller with the 5V output from my FTDI programmer, which is not ideal as it needs to be connected to another USB source. I could instead use a voltage regulator to bring the 24V from the power supply to 5V and make this device standalone. I would also want to create a 3D enclosure to house all the parts for the thermostat and research additional methods on securing the stepper motor and housing the parts for this inside an enclosure as well.

Overall, this was a really fun, hands-on project that I thoroughly enjoyed working on and am still considering working further on. I am so excited to see it in action as I bring it back to my apartment in Evanston. Here's to no more sweaty nights and freezing mornings!