Programming Perfect Extraction: The MokaBot and PID Control
Overview of Precision Pressure Brewing
Traditional coffee brewing often relies on manual intuition, but the
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
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-Fito transmit real-time telemetry for graphing and data logging.
Code Walkthrough: The PID Logic
While the
// 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.
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
