Introduction: PID Controlled Thermostat Using ESP32 (Applied to a Rancilio Silvia Coffee Machine)

Warning
The Rancilio Silvia machine runs on high voltage. Any modification to it might be fatal to you or your machine, you act at your own risk and responsible for your modification. Any modification to the machine might void the manufacturer warranty. Make sure to disconnect the machine from the power line before working on it.

What is a PID controller?
A proportional-integral-derivative controller (or just PID controller) is used to regulate speed, temperature, pressure or other process variable with high accuracy and stable results. I am going to use the Arduino PID library to control the temperature of my Rancilio Silvia coffee machine. More mathematical information can be found on Wikipedia - https://en.wikipedia.org/wiki/PID_controller

Why would I modify my working espresso machine?
I bought my new Silvia E v5 in 2019 and it is still working as new, so why would I modify it? The Silvia has 3 thermostats in it:

  • Brew thermostat 100°C (marked with red dot)
  • Steam thermostat 140°C
  • Safety thermostat (cuts the power if the boiler reaches 165°C)

Silvia’s original brew thermostat turns the boiler on at around 90°C and turns it off around 100°C. Once turned off, the temperature will continue to climb up to ~114°C and only then it starts to cool down. This means that every time you pour an espresso shot, the temperature will be different. These temperature variations make it very hard to get a good espresso shot at the right temperature, which has a huge effect on the taste. You can do temperature surfing or install a PID controller :-)

Wait, but there are ready-to-use PID controllers online!
That’s right, but all the solutions I found online (well, except meCoffee.nl which are not available) require an ugly controller box outside the machine or cutting holes in the machine’s box. I wanted to keep my machine fully restorable to its original state.
So my controller will use a web UI to control the target temperature.
Also, learning new things and DIY is fun! This was my first microcontroller project.

Supplies

Parts I used

  • NodeMCU esp32 microcontroller
  • Short micro USB cable (10cm - 15cm)
  • Phone USB charger that can power the esp32
  • 40A SSR
  • PT100 temperature sensor with ring head
  • MAX31865 Board here or here
  • Thermal paste
  • 6.3mm spade connectors
  • 16 AWG Gauge Wire (will be used to turn on/off the SSR)
  • 14 AWG Gauge Wire (will be used to connect the USB charger to the 220V power supply)
  • Heat Shrink to cover the soldering

Tools needed

  • Soldering Iron
  • Small flat head screwdriver

Resources I used

Step 1: Connecting the Sensor to the Board

  1. Prepare the MAX31865 board based on the instructions found here - https://learn.adafruit.com/adafruit-max31865-rtd-pt100-amplifier
    Each PT100 sensor might have a different configuration using this board.
  2. Connect the PT100 sensor to the MAX31865 board and the MAX31865 to the esp32 board.
    I used the following pins on the esp32:
    MAX31865 pin > Esp32 pin
    CS > 13
    DI > 14
    DO > 27
    CLK > 26
    VIN > 3.3V
    GND > GND

Step 2: The Software

I have used PlatformIO on Visual Studio Code so it would be very simple to install all the required libraries.
I have also used some code parts from https://github.com/Schm1tz1/ESPressIoT which was a great source.

You can download or clone the code from GitHub - https://github.com/bnayalivne/silvia-pid

Make sure to edit the src/web.cpp file and change the ssid and password for the network connection.

To upload the software you have to do 2 things.

  1. Upload the data/ folder which contains the HTML/JS files - In VS Code click on the PlatformIO icon on the left find the “Upload File System image” task.
  2. Upload the software using “Upload” or “Upload and monitor” tasks.

Once the software is installed on the esp32 board you should get the IP address from the board on the IDE monitor.

If you open the IP address on your browser (for example http://192.168.0.123 ) you should see the UI of the controller showing the current temperature of the room.

Step 3: Preparing the Wires

Other than controlling the temperature using PID, I also wanted to have the following features:

  1. The controller has to turn on when Silvia is on, and turn off with the machine.
  2. No external power cables.
  3. It should be possible to undo any change easily (that’s why it was important to use the spade-connectors).

So I used the power going out from Silvia’s CPU unit.

I have soldered female spade connectors to the USB charger,
And 2xCable splitters to take power from the original machine CPU unit.

I have also prepared red+black 14AWG cables with male spade connectors on one side to go from the SSR to replace the current thermostat.

Step 4: Connect As Read Only

On this step we are going to connect the temperature sensor as "read only" mode, to make sure we are getting correct temperature reading from the sensor before letting the new PID to control the boiler status.

  1. Connect the controller to the power supply - On the Silvia’s CPU unit I have disconnected cables 10 and 2 and instead connected my splitters, one leg of the splitter will connect to the original cable and the second will connect to the USB charger
  2. Connect the microUSB cable to the charger and pass it through the cables hole to the boiler area.

  3. I have used a small candy box (Altoids) to cover the esp32 and the MAX31865 boards.

  4. Unscrew one of the brew thermostats (the one with the red dot on it, see image). screws and place the PT100 ring on it with some thermal paste. This will capture the boiler’s temperature and will be used in the PID software.

It's time to make sure we are getting readings from the temperature sensor to the controller and that you are able to connect the UI from your phone/pc using it’s IP address. Make sure the controller turns on/off with the machine and that the temperatures match the boiler status (during espresso brew, during steam mode, etc…).

Do not proceed to the next step if you can't get correct readings at this step.

Be careful not to turn on the machine while the covers are open, keep in mind that this is an high-voltage machine!

Step 5: Move the Control Over to the PID Controller

  1. Remove the 2 connectors from the brew thermostat and connect them with the red and black cables that will go to the SSR.
  2. Position the SSR unit behind the front cover. Make sure it's away from the drip tray.
    There is a single screw there that I used to fix it, but you mght want to drill another screw.
  3. Connect the cables that go from the boiler (the cables that are now attached to the old thermostat cables) to the SSR AC side.
  4. Connect the DC side of the SSR to ESP32 board pins 19 and GND. This will make the SSR turn on/off on the AC side.

Step 6: Make a Great Espresso

At this point, your ESP32 should be able to read the boiler’s temperature and control it’s operation using PID.

You can configure the desired temperature using the web UI.

What’s next?

  • Make the temperature recover better after every shot.
  • Nicer UI.
  • Easier to switch WiFi networks.
  • Steam temperature control.
  • Turn on/off remotely or based on preset hours.

Now, let's make a great espresso!