Introduction: Arduino Brew Mashing PID Controller
First of all, this is my first how to article so I guess won't be perfect.
Described bellow is my build of PID temperature controller for maintaining mash-tun temperature during beer mashing and to control the PWM DC motor for the stir plate.
The circuit is based on Arduino Nano, I2C 16X2 LCD, 3 buttons, mechanical rotary encoder with 20 steps, 2 digital 1-wire temperature sensors, SSR relay and 12V 150W switching DC power supply for the stir motor.
The project is enclosed in a sealed box 26/20/8 cm. For a stir motor I use car windshield wiper motor with gearbox attached to it. The motor draws about 8 Amps @ 12V.
Step 1: Circuit
The circuit consist of few blocks :
Main "core" is the Arduino Nano 3.0 Atmega328 Ch340.
"User interface part" - a 16X2 LCD HD44780 with pre-soldered to it I2C port extender PCF8574. In my case the address of the I2C IC is 0x3F. For controlling I use mechanical rotary encoder, like ED1112S-20 attached to ports 2,3 - using interrupts to read it, so it can't be moved to other pins, and 2 buttons for navigating menu. The axial button on the encoder is also used in some case by the software ( when small steps need to be done ).
"Sensing part" - consist of 2 digital 1-wire sensors DS18B20 connected to one bus. The first one that is detected by the bus is used for the PID, the second one is used for information only and doesn't control anything. In case you don't needed, you can connect just one sensor and it will be used for PID control.
"Control Part" - I use a general 25A/380V ( 3-30V DC gate ) solid state relay for controlling the heater element and a IRLU2905 mosfet for the DC stir motor control. You can chose a different elements here, depending what are you controlling. My heater is 3kW@220V and the stir motor is 8Amps @ 12V. SSR is mounded on the heat sink, cause it gives a lot of heat and I want it outside the box.
DC Power supply - I used 12.5A @ 12V generic switching power supply that makes me a lot of issues - it cases errors in rotary encoder readings, but it can be linked to my box designs. Anyway I changed the PWM frequency and fix the issue, more details in the software part :).
Other various parts : please see the circuit for details. I use the voltage regulator from Arduino Nano to power the 5V rail.
Step 2: Software
The basic part of the software(PID) is from the following site.
What I changed - added encoder, added I2C LCD and removed the routines for the parallel one, added second temperature sensor on the same bus. Added new option for PWM control and menu. Added protection that avoid switching on heating by mistake. Changed a little bit the state machine to add new menu for the PWM.
So how it works... I will not describe the PID principle, it's clear. If you want some details about the PID follow the site above.
To switch it on, after power it on, you should press shift and then select button( power on heater protection ), cause it may switch on the power of the heater ( the last target temperature is stored in the EEPROM ) without water.
On the first screen is the all the info needed for the process- target temperature, current temperature of sensor 1 and 2, the duty cycle of the PID. By pressing select from the main screen it switch off the power of the heater. When pressing shift it rotates trough the menus for setting Target Temp, Kp, Ki, Kd, PWM for the motor. Setting the values happens with the rotary encoder. By pushing the axis of the encoder during rotation, changes the value with 1/10 of the normal step - for fine tuning.
Each value is saved to EEPROM 10 sec after editing. If no user input for more than 5 sec, the controller returns to main screen.There is a shortcut for the DC motor PWM, in main menu - changing the PWM can be done by just rotating the encoder.
To correct the PWM frequency to 31kHz you need to change Timer 2 parameters following this site.
Step 3: Build Process
I started with a water resistant plastic box 26/20/8 cm. Between the solid state relay and the heatsink I use 2 washers with the size of the holes.
The microphone connectors are for each temperature sensor and the DC motor is connected on the 4 pin connector next to the heatsink. I actually use only 2 pins from those 4, cause I want to have more option for extensions if I need something in the future.
There are 3 buttons on the front panel, but actually use only 2, cause I just have those 3 presoldered from old project.
On the bottom is a 25A socket that I found in our local electronics shop for connecting/supply heater element.
When I fit everything I dissembled the whole controller and put some general silicone ( sealant ) to be sure that no water can get in.
Step 4: Testing
For testing prior brewing ( I am brewing on the balcony and need good weather ) I used a hot kettle and I put the 1st temperature sensor in. It kept the temperature spot on :) 50C.
Then the real test came - I had to change some of the PID parameters but at the end it maintain the temperature of the mash for about an hour ( outside with wind ) spot on 67C :). The issue was that I have to bring the frequency of the PWM for the motor to about 4kHz and it is annoying when working. I tested the system with open lid and 31kHz PWM and it run flawlessly. The issue is only when I close the lid with 31kHz and it is caused by the cheap 12V power supply.