Programming Perfect Extraction: The MokaBot and PID Control

James Hoffmann////3 min read

Overview of Precision Pressure Brewing

Traditional coffee brewing often relies on manual intuition, but the MokaBot represents a shift toward algorithmic precision. The core challenge of the Moka Pot lies in its volatile temperature fluctuations; as water leaves the bottom chamber, the air expands rapidly, often overheating the grounds and creating bitter flavors. By integrating a PID Controller, the MokaBot prototype automates the 'gas management' phase of brewing, ensuring a steady, low-temperature flow that highlights the nuanced notes of specialty coffee.

Prerequisites and Logic Fundamentals

Before implementing a control loop like this, you need a basic understanding of sensor feedback systems. The logic relies on a closed-loop system: the hardware reads a temperature, compares it to a target (the set point), and adjusts the power output accordingly. Familiarity with C++ for Arduino or Python for Raspberry Pi helps when translating these mathematical concepts into executable code.

Key Libraries & Tools

  • PID Library (e.g., Arduino PID Library): Handles the complex calculus required to calculate output based on error over time.
  • Thermocouple Interface (MAX6675/MAX31855): Essential for reading high-precision temperature data from the probe.
  • Solid State Relay (SSR): Allows the low-voltage microcontroller to toggle the high-voltage heating element via Pulse Width Modulation (PWM).
  • Web App Integration: Uses Wi-Fi to transmit real-time telemetry for graphing and data logging.

Code Walkthrough: The PID Logic

While the MokaBot uses custom software, the logic follows a standard structure. First, we define our constants for Kp (Proportional), Ki (Integral), and Kd (Derivative).

// Define PID constants
double Kp=2.0, Ki=5.0, Kd=1.0;
PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);

void setup() {
  Setpoint = 106.0; // Target temperature in Celsius
  myPID.SetMode(AUTOMATIC);
}

In the main loop, the controller calculates the error—the difference between the current temperature and the 106-degree target.

void loop() {
  Input = readThermocouple();
  myPID.Compute();
  analogWrite(HEATING_ELEMENT_PIN, Output);
}

As the temperature nears the set point, the Output value decreases, pulsing the heating element to prevent overshooting. This 'judicious application of heat' mimics a skilled human operator but with millisecond-level precision.

Syntax Notes and Hardware Conventions

In these control systems, Pulse Width Modulation (PWM) is the primary convention. Instead of turning a heater 'halfway on' (which is impossible for most elements), the code toggles it on and off rapidly. The ratio of 'on' time to 'off' time determines the effective heat. Additionally, calibration functions are vital. Javi included a boiling-point calibration to ensure accuracy regardless of altitude, a critical feature for global consistency.

Practical Examples and Gotchas

A common mistake is failing to account for thermal lag. The sensor may report 100 degrees while the element is still radiating heat that will push the water to 110 degrees. This 'overshoot' requires tuning the Derivative (Kd) value to predict the rate of change and cut power early. The MokaBot demonstrates this by 'pulsing aggressively' early on and easing off as the coffee begins its steady, non-sputtering flow.

Topic DensityMention share of the most discussed topics · 12 mentions across 10 distinct topics
MokaBot
25%· products
Arduino
8%· companies
C++
8%· products
Javi
8%· people
Minorsky
8%· people
Other topics
42%
End of Article
Source video
Programming Perfect Extraction: The MokaBot and PID Control

The MokaBot Brews Better Coffee Than Me

Watch

James Hoffmann // 19:26

Hi! My name is James, and I make videos about anything and everything to do with coffee, occasionally food and sometimes business/entrepreneurship. I create how-tos, guides, reviews, vlogs, video essays and mini-documentary films. In the real world, I've started a few companies, I wrote "The World Atlas of Coffee" and "How To Make The Best Coffee At Home". I do a little advisory work for startups too. If you want to get in touch, drop me a line but please read these two things first: 1. I don't do paid reviews. I have a Patreon that helps me buy the products I want to review to prevent bias (then I give them away!) 2. I get a lot of email, so sadly I can't help with queries about which equipment you should buy. TO GET IN TOUCH PLEASE REACH OUT VIA WEBSITE: https://www.jameshoffmann.co.uk/contact-me Management: Ziggurat XYZ

Who and what they mention most
3 min read0%
3 min read