# Yet another PID controller



## MartinHalfer (Dec 2, 2020)

Hello ... I'm new to the forum. For some time i have scoured the internet for suitable PID controllers for my Gaggia Classic. I haven't found any that really had the flexibility and features that I was looking for, so i decided to design my own.










When done, it should have the following features:

Hardware:
3.3V onboard power supply
ESP8266 (ESP12) module for wifi connectivity and processing.
MAX31855 thermocouple amplifier.
Screw terminals for AC power, thermocouple input and relay output.
Breakout connectors for programming of the ESP8266 after assembly of the PCB.

Software: (not developed yet)
Temperature readout through SPI
PID controlled duty cycle relay output
MQTT temperature readout and setpoint setting. Written in the Ardunio IDE

The project is far from finished - If you want to contribute or just build a board yourself, check out https://github.com/martinhalfer/ESP-12_thermostat

I expect to finish the project in the coming months.


----------



## Cafe675 (Jun 22, 2015)

congratulations for the work, it looks very good, I subscribe! post the advances you make!

For the gaggia classic I've seen several PID, commercials and DIY, what makes yours that you haven't seen in others?


----------



## MartinHalfer (Dec 2, 2020)

Thanks for the interest... It will be controlled through an MQTT broker. MQTT is a messaging format for Internet of Things devices. In practice, that means you can easily integrate the coffee machine in your smart home setup - As an example adjust the setpoint to brew temperature automatically each morning and turn heater off automatically when you leave for work etc...

The PID controller itself is very compact and will fit inside almost any espresso machine housing. Setpoint control and temperature readout is done on a mobile device. No need for sticking/bolting an ugly box to the outside of your machine.

The first crude version of the software is written. Onboard LED on the microcontroller simulates heater output. Device control in the background is a hass.io (Home Assistant) server that controls the setpoint for the boiler at shows the current temperature.

All communication between the hass.io server and the PID controller is through WiFi.


----------



## allikat (Jan 27, 2020)

How's the security on it? IOT protocols are often stupidly easy to hack.


----------



## MartinHalfer (Dec 2, 2020)

I haven't addressed security yet. There's only password authentication to access the MQTT broker. However, it would be possible to implement Transport Layer Security for the MQTT connection ...

I'm not sure it is worth the effort though. Worst case is an attacker would blow the thermal fuse of the boiler and you wouldn't get your morning latte.


----------



## MartinHalfer (Dec 2, 2020)

Progress ... Assembled the PCB and tested with the software. So far everything is working as expected. Next step is mounting the device in the machine.


----------



## Rincewind (Aug 25, 2020)

@MartinHalfer your link isn't working for me...any chance you can post the picture directly here ? ...i'd love to see your PCB/artwork/component-layout etc. 😋


----------



## MartinHalfer (Dec 2, 2020)

Sorry... I'll try again:


----------



## Rincewind (Aug 25, 2020)

Excellent....what prototyping software did you use for your design ?


----------



## MartinHalfer (Dec 2, 2020)

The PCB was designed in KiCAD. The software was written in Arduino IDE. All files are accessible on the GitHub link in my original post.


----------



## Rincewind (Aug 25, 2020)

Not tried KiCAD yet...but i'll have a quick butchers later on....yeah i looked at your GitHub....well done BTW 😎


----------



## MartinHalfer (Dec 2, 2020)

It has been a while since my last post... Mounted the cotroller to the Gaggia Pro this weekend and it works as expected... Temperature signal is a bit noisy and might need some software filtering and the PID tuning is way off. It makes a huge overshoot when the machine is turned on, and doesn't react quickly enough to cold water flowing through the boiler... More to come...


----------



## MartinHalfer (Dec 2, 2020)

After some software modifications (averaging of many sensor readings and PID tuning), the temperature sensing and PID controller perform MUCH better... Slight overshoot when turned on, after that it settles slowly to set temperature while the machine warms up. Temperature consistency during shots is not perfect, but probably much better than with the stock temperature switch.

What I learnt so far:

- The thermocouple was a pretty lousy design choice as it's 2% accuracy limits the possible responsiveness of the controller during shots.

- The temperature at the probe is very sensitive to activation of the external heater element as it sits right next to it. Temperature overshoots are more likely to be readings of the housing temperature rather than the water inside it.

Next improvement might be a bypass of the PID controller during pump activation. My idea would be that i could find a heater element duty cycle that approximately matches the cooling by the water flow during shots, or;

Redesign of the board to use a resistance temperature detector to improve the temperature readings and allow the PID to respond immediately to temperature changes.


----------



## MartinHalfer (Dec 2, 2020)

I reduced the noise with software filtering and grounded copper shielding around the thermocouple wire. This made it possible to use a more aggressive tuning of the PID parameters, without sacrificing temperature stability...


----------

