Hand warmer
Most hand warmers you can buy are small and battery powered, which limits for how long you can use them. I mainly need a hand warmer at my desk, where I have 12V and 24V PSU and USB-C chargers. I also realized that I have everything needed for a hand warmer at home, so I decided to make one.
Mechanical design
The hand warmer is split into two sections. The bottom is the heated grip for your hand. The top section houses all the electronics.
The bottom section is made out of a solid 32mm aluminum rod 100mm long. It has brushed surface finish made with Scotch brite. The top of the rod has one hole in the middle for the heater cartridge, one for the thermometer and three M3 threaded holes for mounting the top section. The heater cartridge and thermometer are secured using M3 grub screws in a couple of radial holes.
The top section is printed out of PETG-CF and has a hexagonal shape. That is because it prevents the heater from rolling around, leaves more space for the electronics inside and looks good. The cover is fastened with M2 countersunk screws and heat set inserts. The LED diffuser is printed from translucent PCTG.
The CAD files can be found on Onshape.
Electrical design
I chose the ESP32-C3 mini for this project as it is small, and I have a lot of them. The hand warmer can be powered with a 24V PSU, but it also includes a 20V bait module for USB-C PD. I also included a diode to prevent the 24V back feeding the bait module. Powering it off USB-C reduces the power, which makes it take a bit longer to heat up. The high voltage is stepped down to 5V using a small buck converter. 5V powers the neopixel LED strip and the ESP32, which uses the integrated LDO to reduce it to 3.3V. The heating is done by a 40W 24V 3D printer hotend cartridge and a mosfet module. Temperature is measured by PT100 and a MAX31865 breakout board.
The breakout boards are mounted using double-sided tape on both sides of the internal panel.
Firmware design
The program loop is split into four main parts
Level handling
The hand warmer can cycle through different levels using a button. Each level increase increases the set temperature. Maximum number of levels is set by the number of NeoPixel LEDs. Going over the limit resets the level to 0, where the target temperature is 0°C, effectively turning off the heating. The button is attached to interrupt and includes software debounce.
Regulator
The target temperature is interpolated from the minimum and maximum set temperature and the current level. The regulator uses just the proportional term with high P gain. This is possible because the system has very low inertia. In other terms turning off heating makes the temperature go down almost instantly, because the heater and thermometer are separated by just a couple of millimeters of aluminum. The P gain is so high that the heating duty cycle is at 100% up to 2°C temperature error, but the overshoot is at most only 0.5°C. The main disadvantage is that there is a steady state error, which gets higher with higher cooling power (when it is warming your hands). In simpler terms the hand warmer can't hold the required temperature when it is warming your hands. Thankfully the high P term doesn't let this error be too large.
Originally I wanted to use the arduino PWM output using the analogWrite() function, but the 500Hz output paired with the high current draw produced buzzing noise. The arduino PWM frequency isn't easily changeable, so the program uses the LED control (LEDC) from espressif. The PWM frequency is set to 200Hz, where it is inaudible.
LED strip
The NeoPixel LED strip signalizes the current level with the number of lit LEDs and the temperature with the color. The color changes from green (ambient temperature) to red (target temperature) based on the current temperature.
Safety stops
The program includes two safety stops. First stops the heating when the current temperature goes over 60°C. This doesn't prevent thermal runaways caused by mosfet failure in closed position or temperature readout failure, for which I should include a thermal fuse. The second safety stops turns the heating off after one hour of constant heating.
The whole code:
#include <Adafruit_MAX31865.h>
#include <Adafruit_NeoPixel.h>
// pin definitions
#define MISO 9
#define MOSI 10
#define CLK 8
#define CS 5
#define heaterPin 4
#define ledPin 3
#define buttonPin 2
// neopixel definitions
#define NUMPIXELS 6
#define brightness 25 // 0-255
// PWM definitions
#define LEDC_TIMER_BIT 8
#define LEDC_BASE_FREQ 200
// constants
#define RREF 430.0 // The value of the Rref resistor. Use 430.0 for PT100 and 4300.0 for PT1000
#define RNOMINAL 100.0 // 100.0 for PT100, 1000.0 for PT1000
#define Pterm 125 // Pterm * tempDiff
#define ambientTemp 20 // ambient temperature for color scaling
#define minTemp 40
#define maxTemp 50
#define debounceDelay 100
#define shutdownTime 60 // time in miutes after the heater turns off automatically
// variables
float tempTarget = 0;
float tempDiff = 0;
int i = 0;
int level = 0;
int green = 0;
int red = 0;
float tempRange = 0; // range of possible temperature values (ambient to set)
volatile bool buttonPressed = false;
volatile unsigned long lastPress = 0;
unsigned long startTime = 0;
Adafruit_MAX31865 thermo = Adafruit_MAX31865(CS, MOSI, MISO, CLK);
Adafruit_NeoPixel pixels(NUMPIXELS, ledPin, NEO_GRB + NEO_KHZ800);
void IRAM_ATTR handleButtonPress() {
buttonPressed = true;
}
void setup() {
Serial.begin(115200);
delay(500);
Serial.println("setup start");
pixels.begin();
thermo.begin(MAX31865_3WIRE); // set to 2WIRE or 4WIRE as necessary
ledcAttach(heaterPin, LEDC_BASE_FREQ, LEDC_TIMER_BIT);
pinMode(buttonPin, INPUT);
attachInterrupt(buttonPin, handleButtonPress, FALLING);
Serial.println("setup completed");
}
void loop() {
// level handling with button
if (buttonPressed) {
buttonPressed = false;
if (millis() - lastPress > debounceDelay){
lastPress = millis();
if (digitalRead(buttonPin) == LOW){
level++;
if (level > NUMPIXELS) {
level = 0;
}
if (level == 1) {
startTime = millis();
}
Serial.print("level:");
Serial.println(level);
}
}
}
// REGULATOR
if (level == 0) {
tempTarget = 0;
} else {
tempTarget = map(level, 1, NUMPIXELS, minTemp, maxTemp);
}
float temp = thermo.temperature(RNOMINAL, RREF);
Serial.print("Temperature_real:");
Serial.println(temp);
float tempDiff = tempTarget - temp;
float PIDsum = Pterm * tempDiff;
PIDsum = minMax(PIDsum, 0, 255);
Serial.print("PIDsum:");
Serial.println(PIDsum);
ledcWrite(heaterPin, PIDsum);
// LED green to red based on power
tempRange = tempTarget - ambientTemp;
pixels.clear();
if (temp < (ambientTemp + tempRange/2)){
green = brightness;
red = map(temp, 0, ambientTemp + tempRange/2, 0, brightness);
} else if (temp > tempTarget){
green = 0;
red = brightness;
} else {
green = brightness - map(temp, ambientTemp + tempRange/2, tempTarget - 0.25, 0, brightness);
red = brightness;
}
for(i=0; i<level; i++) {
pixels.setPixelColor(i, pixels.Color(red, green, 0));
}
pixels.show();
// Safety stops
thermoFault();
thermalStop();
if ((millis() - startTime) > (shutdownTime * 1000 * 60)) {
level = 0;
}
delay(50);
}
void thermoFault() {
uint8_t fault = thermo.readFault();
if (fault) {
Serial.print("Fault 0x"); Serial.println(fault, HEX);
if (fault & MAX31865_FAULT_HIGHTHRESH) {
Serial.println("RTD High Threshold");
}
if (fault & MAX31865_FAULT_LOWTHRESH) {
Serial.println("RTD Low Threshold");
}
if (fault & MAX31865_FAULT_REFINLOW) {
Serial.println("REFIN- > 0.85 x Bias");
}
if (fault & MAX31865_FAULT_REFINHIGH) {
Serial.println("REFIN- < 0.85 x Bias - FORCE- open");
}
if (fault & MAX31865_FAULT_RTDINLOW) {
Serial.println("RTDIN- < 0.85 x Bias - FORCE- open");
}
if (fault & MAX31865_FAULT_OVUV) {
Serial.println("Under/Over voltage");
}
thermo.clearFault();
}
}
void thermalStop() {
float temp = thermo.temperature(RNOMINAL, RREF);
if (temp > 60) {
Serial.println("thermal stop");
level = 0;
}
}
float minMax(float value, float min, float max) {
if (value > max) {
value = max;
} else if (value < min) {
value = min;
}
return value;
}