Now that we understand how the popcorn machine works out of the box, let's have a look at the changes we'll make. For my setup, I have opted to keep the original housing of the popcorn machine, and add a separate enclosure for the control electronics. That means that inside the popcorn machine, I only rewired the fan and heater so that they are powered separately and routed those wires outside the machine. I also added two temperature probes (K-type thermocouples), one to measure the temperature of the incoming hot air and one to measure the temperature inside the roast chamber.

For the controller, I used an Arduino Uno and a TC4+ shield, which is made specifically for coffee roasting and has all the necessary electronics. In addition, we need a solid state relay (SSR) for heater control, and either a DC power supply for a DC fan, or an AC PWM dimmer board for an AC fan. Our goal is not only to be able to switch heater and fan on and off independently, but to gain fine-grained control of their heater output and fan speed.

In the following, we will go through the modifications one by one: Heater control, fan control (DC or AC), thermocouples. The attached diagrams show the wiring for each of these individually, and a complete wiring setup with a DC fan.

Controlling a heating element



For the heating element, this is very easy. Because the heating coil doesn't change temperature instantly when switched on or off, we can get away with simply switching it on and off relatively slowly, usually once per second. If we wanted, say, 70% heater output, we would switch the heating element on for 0.7 seconds, and then switch it off of 0.3 seconds. To do this, we can use a solid state relay (SSR), which is essentially an electronically controlled switch. We simply connect the AC-side of the SSR in series with the heating element, on the live side. The DC (control) side of the SSR connects to one of the SSR drivers (OT1) on the TC4+ shield.

My popcorn machine has a voltage divider with primary and secondary heating coils, so I used only the primary heating coil. This puts the coil at 230V mains voltage, instead of the roughly 212V it was before. On the bright side, that means slightly higher heating power (ca 1240W) than the original setup (ca 1100W), on the other hand also a higher risk of overheating. Depending on the specs of each heating element in your setup and the magnitude of the resulting increase in peak heating power, you might want to avoid running the heater at 100\% power to be safe. It is also imperative that the thermal fuse remain in place.

Controlling a DC fan



Controlling a DC fan is also easy, and works in a similar manner to the heating element: We simply turn power on and off, except for a motor we need to do so much more frequently, hundreds or thousands of times per second for smooth running. This is called pulse-width modulation, and is luckily something that microcontrollers excel at. The TC4+ has the electronics for this on board, so we only have to connect the DC fan and the DC power supply to the respective terminals on the TC4+. Internally, the electronics work much in the same way as before: The TC4+ has a MOSFET (the DC version of a SSR) in series with the fan motor.

You will have to place a flyback diode across the motor terminals, to protect the DC driver from overvoltage generated by the motor when slowing down. This is simply a diode across the motor terminals, opposite to the usual direction of current flow. You can reuse one of the diodes from the bridge rectifier for this.

You will need a DC power supply that matches the DC fan's voltage (slightly higher might be fine). The rated current of the power supply should exceed the fan motor current. I would aim for at least twice the rated power. When a DC motor is turned on, the current draw (``inrush current'') is momentarily much higher than the steady state current - bear this in mind. If you find that the power supply resets if you turn the fan on, you can try increasing the fan duty in several steps to limit the inrush current.

If the popcorn machine PCB has inductors and/or capacitors in series or in parallel with the fan motor, keep them. They are for filtering out electrical noise generated by the motor brushes.

Controlling an AC fan



With an AC fan motor, things are a little more complex. Due to the way AC works, we cannot simply switch power on and off hundreds of times per second. Instead, we need to do what an old-school dimmer switch does, and turn on power part-way through each half-sine wave of the AC waveform. The easiest way to do this is to use an AC PWM dimmer board, which does all the timing required for this internally. To the TC4+ and Arduino, this will look the same as a DC fan, making the software side easy. There are several such boards available on Tindie, for instance this model: https://www.tindie.com/products/bugrovs2012/pwm-ac-light-dimmer-module-50hz-60hz

If you get a different AC PWM dimmer board, make sure it is one that only needs a PWM input and does the timing internally. If the board has a zero-cross output, it likely requires the Arduino doing the timing, making things more complex.

A small side note: You might not strictly need fine-grained fan control. On some setups, it is necessary to start with a high fan speed and then gradually lower it toward the end of the roast. This is because the raw beans are relatively heavy, so stronger airflow is required to move them; On the other hand, once the beans get lighter toward the end of the roast, a lower fan speed allows for a higher peak temperature. But, this isn't always necessary. On my roaster, I am able to keep the fan speed constant. So you could try simply connecting the fan to another SSR, or even a physical switch, in the first instance, and see how that goes. For a DC fan, you get fine-grained control ``for free'' with the TC4+ board, since this already has a DC PWM driver on board; But with an AC fan you could try to see if you can get away without the extra AC PWM dimmer board.

Thermocouple temperature probes



We will add two thermocouple probes to measure the temperature of the coffee beans and that of the incoming hot air. These will connect directly to the thermocouple interface on the TC4+ board.