Connected Control for Chefs
There’s almost no limit to what an MCU can be used for—including objects that previously had no electronics at all. In this article, learn how this Cornell University student built a Microchip PIC32 MCU-based system that wirelessly measures and controls the temperature of a pan on a stove. The system improves both the safety and reliability of cooking on the stove—and has potentially interesting commercial applications.
I was the family chef for a number of years in my home, but since I began attending university, my mom has reluctantly taken over as house cook. Learning how to cook can be difficult, and my mom’s tendency to multitask while food is on the stove causes a few small kitchen fires each year. My project, called Smart Pan, solves this problem, making cooking easier to learn, preventing overcooking and stopping fires.
The Smart Pan is an installable knob and handle set that controls your stove wirelessly. It consists of two separate components—a temperature sensing handle and self-correcting stove knob—that communicate via radio (Figure 1). The installable handle detects the temperature of any pan and the knob turns to maintain a given temperature on any stove.
The Pan also connects to your phone, where myriad smart options can exist. From a smartphone, you can instruct the Pan to follow specific profiles, so you can cook just like your favorite chefs. The Pan contains simple rules to turn off if the temperature exceeds the smoke point of cooking oil. The knob and handle both use available 9 V batteries and are easily installable in the average kitchen. Both the handle and knob modules also use Sean Carroll’s PIC32MC250F128B Small Development Board. The Circuit Cellar article materials webpage has a link to the details of that board . Figure 2 shows a photo of with an overview of the project.
The handle mounts like a sleeve over most pan handles, and is secured in place with a pair of thumbscrews. I chose thumbscrews so that the handle could be slipped on and off different pans without any tools. The back thumbscrew prevents frictional load on the inside of the case when the pan is lifted. The front thumbscrew prevents the handle from slipping around inside the case.
The case is made of 3D-printed polylactic acid plastic, commonly referred to as PLA. The advantage of PLA is that it’s readily available for prototyping. On the down side, it’s quite susceptible to melting under heat. Luckily, most of the work of thermal isolation is done for us by pan manufacturers, to prevent customers from burning their hands. The thermocouple wire can provide only a limited cross-section for heat conduction, so these thermocouples should only allow a small throughput of heat.
PLA restricts the use case of the pan slightly, but incorporating additional cooking features is nearly impossible for additional reasons. For instance, when making a roast a chef will place the pan in the oven after browning the roast on the stovetop. PLA couldn’t survive in an oven, but neither could any modern electronics. Robust microprocessors are only comfortable up to 80° C, so without a significant advance in processor materials or thermal efficiency, this device could never be used in the oven.
The ends of the proposed PLA handle contain small thermocouples attached to permanent magnets. Neodymium Iron Bromide (NIB) magnets were chosen both because of their availability and because the temperature at which their magnetic polarization breaks down is far outside the range of normal cooking temperatures.
These magnets attach to the sides of the metallic pan and conduct heat to the thermocouple. The magnets are separated from the thermocouples by Kapton tape. Kapton tape allows for complete thermal conductivity without any electrical conductivity. This prevents the electrically conductive magnets from interfering with the thermocouple measurement without also insulating the thermocouple from the heat that it needs to measure.
Based on information from this thermocouple, the knob computer will pick an appropriate amount to turn, and rotates the knob to keep a consistent temperature. However, thermocouples tell us only the voltage across them, and the knob and pan computers are separate. Therefore, I measure the thermocouple with a thermocouple IC, and then transmit that information via the Microchip PIC32 microcontroller (MCU) and the XBee device. (Figure 3).
The Sparkfun MAX31855K is a breakout board with a thermocouple IC. It allows the PIC32 MCU to read the thermocouple via SPI. The module requires 3.3 V power, and draws a small enough current that the PIC32 board regulator can be used to power it. The IC provides 14-bit resolution over the entire range of K-Type temperatures. This gives us a resolution of 0.3°C, which is more than enough for accurate cooking. However, this temperature value must somehow be transmitted to the knob module, which we can do using the XBee module.
The XBee Series 1 module sends data from the handle module to the knob. XBees are hugely popular for a number of reasons, but I chose to use them in this project because they connect with simple serial ports. This allowed me to send the current temperature value without much hassle and without having to work with an unfamiliar protocol. The XBee board draws approximately 50 mA at 3.3 V, so it can be powered simply via the 3.3 V linear regulator on the PIC32. This increases the draw on the PIC32 linear regulator, but not so much that I see any problems.
These modules of course require a power source to operate. Both the handle and knob module use a 9 V battery as a power source. This is to ensure that a consumer could easily switch out batteries without much hassle. From the 9 V battery, power is downregulated to on-chip 3.3 V power for the PIC32’s Bluetooth Module and Thermocouple IC, off-chip 3.3 V power for the XBees and off-chip 5 V power for the Servo Motor within the knob module.
The knob module receives a transmitted temperature from the handle board, translates this temperature to a PID command and rotates a servo accordingly (Figure 4). The knob was designed to replace any standard range/stove/oven knob as easily as possible. In the current revision of the project, I’m using an old stove knob. Conveniently, most stoves have the same notched control rod behind their knobs, so the knob can connect with most stoves by sliding on with a press fit. The battery is replaceable through a drawer in the front of the knob, so the knob doesn’t need to be removed to change batteries. This 9 V battery supplies power to all the knob component modules, which are described below.
The knob receives commands through an XBee module identical to the one in the handle system. The commands are then translated in software on the PIC32 to a PWM command. The PIC32 then generates this PWM command and sends it on to a level shifter. This level shifter increases the magnitude of the commands and sends them to the servo motor. This process adjusts the knob such that the pan reaches the desired set temperature with a simple PID control loop.
The servo motor needs 5 V control logic to operate. However, the PIC32 Small Development Board is only configured to output 3.3 V logic. The level shifter answers this with a simple amplifier hack. A bipolar junction transistor (BJT) and two resistors can shift the peak value of the PWM from 3.3 V to 5 V.
A good way to think about how the level shifter circuit works is to notice that it is, in effect, just a common base amplifier of for the PWM. The base is held at +3.3 V when the input is high (also +3.3 V) and the transistor is off. This allows the collector to float up to the +5 V rail. When the input goes low, the transistor turns on hard and pulls the collector to just above the logic low level of the input. BJTs also have the advantage of fast switching times, so the level shifter introduces very little lag into the sense and respond control loop.
I also wanted the user to be able to control the temperature to which the knob sets. The Bluetooth module is from Adafruit, and is based on a Nordic Semiconductor nRF8001 chip. It connects to a mobile phone and has its own open source app that allows a user to send temperature set commands. This module then connects via SPI to the knob PIC32 and forwards those command values.
To begin any sort of calculation, we need first to take the temperature from the thermocouple IC. We only need to read data from the thermocouple, so it’s only necessary to connect to the MISO (Master In Slave Out) pin on the thermocouple breakout board. To read the MAX31855 over SPI, we pull the select pin (CS) to low, read the data then set the pin back to high. The value of the temperature that the MAX chip transmits is a 32-bit integer, where the last 14 bits represent the temperature in degrees Celsius. I found a tutorial for of the code in the MAX31855 website .
The pan handle pulls this information within the ISR (interrupt service routine), so that the data are consistently sampled, rather than sampled as the threads are scheduled. The precise timing of the samples may not seem important because we’re severely oversampling relative to the problem, but the PID control loop is much more accurate with regular samples.
The pan handle’s PIC32 converts that data into a string, so that it is accepted by the Zigbee software running on the XBee (Figure 5). I took the digit value of the temperature and sent it as a string. The XBees have a 100-byte UART buffer on board that ensures that the samples are transmitted when we’re ready to receive them. The PIC32 in the knob currently sends a Zigbee receive command in the ISR, so that it’s at least consistently timed on each individual board. The knob PIC32 receives this temperature value, compares it to a user set value and translates the disparity between the two values into the desired PWM value. Good control currently requires tuning for individual stoves.
After converting the temperature back to an integer that it can manipulate, the PIC32 also performs a sanity check on that temperature to ensure user safety. To prevent common house fires, the PIC32 has a shutdown protocol when the temperature reading exceeds the mean smoke point of several common cooking oils (150°C). If 20 sequential temperature readings are above this threshold, the set temperature is automatically changed from the user set value to room temperature. This immediately turns the pan off or to its lowest setting, and sends an alert to the user’s phone. I also propose that a sanity timer be incorporated into these sanity checks to prevent a user from leaving the stove on at a high temperature.
The primary function of the PIC32, however, is to follow a given temperature profile. The knob PIC32 takes the user set temperature from the Bluetooth module over SPI much like the temperature board (Pulling CS to low, Reading the data, then raising CS again). I followed a tutorial from Adafruit’s Bluetooth nRF8001 website that was fairly illustrative . The output is also a 16-bit value, where 14 of the bits represent the temperature in degrees Celsius.
Conveniently, the Bluetooth module has a smartphone app that was easy to modify and get a minimum working product. The app uses Adafruit Bluefruit BT Connect on Android as a base . It currently allows you to set variables stored in the Bluetooth module with their built-in GUI, so users can edit the USR_SET temperature value with a slider. The PIC32 accesses the Bluetooth chip in the same way that it accessed the MAX Thermocouple IC. This abstracts away the backend of Phone-to-Bluetooth communication in a way that makes it fairly easy to use.
The PIC32 then computes the error between the set temperature and the temperature read from the thermocouple. This error in temperature is the metric used in a PID control loop. I chose this linear error metric instead of something like mean square error, because I found that mean square error dramatically increased the “jitter” in the output.
With this error, I compute the PWM with a conventional PID control loop, which I tuned to my hotplate and pan at home. It’s important to note that these tuning values will differ for different pans and stoves. In the final output, I average the previous 20 samples to prevent outlier measurements in the temperature data. This stops sudden swings in the PID calculation from causing large swings in output. This averaging is “hacked” together by writing several variables and averaging them. While that may not be the best method, I did it that way because I know it works. The knob PIC32 then generates the appropriate PWM commands and sends them out over pin RB9.
Testing and Improvements
Although I had much initial success, one main issue kept arising during test. The latency time between a dramatic temperature change and the subsequent change in the pan. The pan has a significant thermal mass that takes several seconds to propagate to the outside. Making the system handle modular rather than drilling into the pan has this disadvantage. We can see the dither associated with a thermal “slew” in Figure 6. Using a second thermocouple allows us to predict the center temperature rather nicely with a heat diffusion model.
A better physical temperature model could improve this product significantly. The original design required drilling into the center of the pan and filling the cavity with thermal paste. This reduced latency to the speed of the electronics, but required a pan with a hole drilled into it for every unit. A preferable method would be to take two measurements on the edge of the pan and use a diffusion model for the pan, to predict the temperature at the center from the two values at either side. I’ve tested this method by attaching thermocouples to the sides of the pan, but as of writing, it’s still unreliable.
The current revision of the project exists on a breakout board, but the breakout board should be unnecessary for a final product. Ideally, I’d route connections among all the components on a single handle board with the PIC32. This would give me a lot more control over the form factor of the final device, which could make it compact enough to make a long and narrow handle. The same huge improvement in form factor on the knob could be obtained by making another custom PCB.
I’d also change out the XBees for additional Bluetooth chips, so that I could get a less bulky, more reliable connection. XBee Radios are universal and reliable, but they have shortcomings. Radios are best for transmitting reasonably reliable data over large line-of-sight distances. However, in a kitchen setting, the distances are relatively short and an oven usually stands between the pan and knob. The original reason that I wanted to use the XBee was to familiarize myself with UART, but an improved design would perhaps incorporate a second Bluetooth board instead for more robust communication. My XBees also had antennas attached to them, but ultimately, I don’t think that they are necessary for communication over such short distances.
Several other improvements could improve the system’s usability. The user app currently doesn’t feature profiles or push notifications natively, but it could be significantly expanded to do so with a little more knowledge of app development. The user could be notified when their cook temperature exceeds certain preset values that are either dangerous or would ruin the food. The user could also load a whole cooking profile and see a small graph of the set temperatures over time with accompanying instructions for common meals. This is my ultimate vision for this product, and I’m hoping that other hobbyists can expand upon it and implement these features.
The knob controls temperature because a small servo rotates the rod behind the knob. An adhesive ring could be attached on the back panel of the case, to provide a counter torque for this knob to push off of. This solution has the advantage of being as universal as possible. The adhesive ring also has the advantage of connecting with any oven back panel. There are a few good options for the adhesive ring that might be better candidates for a final product. A ring of small magnets could hold the knob against the panel, but would only work on magnetic surfaces. However, it does have the advantage of being cleaner and reusable.
Ideally, I’d prefer to have users not need to tune their own knobs but I don’t yet see a black-box style method to tune the knob automatically. PID auto tuning is the most significant barrier to ease of use. Currently, a user would have to tune the pan to his/her own stove. This is a technical challenge for an inexperienced user that I would like to remedy, if possible. Auto tuning routines exist, but new open loops arise if I have to implement them.
This proposal has a lot of promise, but needs help in the implementation. I’d appreciate any additional comments and suggestions! Some other products have recently sprung up in this space, but they typically ignore the concept of modularity, making them expensive. Other products depend on other expensive pieces of technology. Inirv, a company that raised over $175,000 on Kickstarter two years ago, built a system of smart knobs that costs $299 and relies on an expensive smoke detector unit. That approach might be too little too late to avoid the beginnings of oil fires. In contrast, my Smart Pan implementation has a clear speed advantage here.
For detailed article references and additional resources go to:
References  through  as marked in the article can be found there
PUBLISHED IN CIRCUIT CELLAR MAGAZINE • JULY 2019 #348 – Get a PDF of the IssueBecome a Sponsor