I worked in the Specialty Coffee industry and installed quite a few PID controllers in espresso machines over the years to give much better temperature control.
After learning about the Arduino platform I decided to build my own PID controller.
To greatly simplify things, a kit of this project is available at Jameco Electronics here -
Arduino Based PID Controller For Espresso
Below are some photos of the controller, it can be set up in 2 different form functions, depending on your space requirements/limitations.
If used in the flatter configuration (on the RHS), the mounting holes of the LCD line up with the mounting holes of the PID board, enabling the use of mounting hardware to help support the weight of the LCD, rather than placing unnecessary stress on the solder joints between the LCD and PCB.
If used in the configuration shown on the LHS, the PCB and the LCD can be mounted to separate faces of a project box.
Parts ListExported from Arduino_PID_for_Espresso_v2_Rev_C.brd at 7/23/2013 12:07:39 PM
EAGLE Version 6.4.0 Copyright (c) 1988-2013 CadSoft
Part Value Package
C1 47uF TT5D6
C2 47uF TT5D6
C3 0.1uF C025-024X044
C4 0.1uF C025-024X044
C5 10uF CPOL-RADIAL-10UF-25V
C6 0.01uF C025-024X044
C7 10uF CPOL-RADIAL-10UF-25V
D2 1N4007 DO41-3
D3 1N4148 DO-1N4148
D4 1N4148 DO-1N4148
D5 1N4148 DO-1N4148
IC1 7805TV TO220V
IC2 MAX31855 SOIC8
JP2 1X06/90 1x6pinhead
JP5 1X16 pinhead
LED1 GRN LED3MM
LED2 RED LED3MM
Q1 16MHz CSTLA_T
Q2 2N4401 TO92-
R1 2K7 AXIAL-0.4
R2 10K 1/6W-RES
R3 10K 1/6W-RES
R4 10K 1/6W-RES
R5 10K 1/6W-RES
R6 10K 1/6W-RES
R7 10K pot B25P
R8 10K 1/6W-RES
R10 10K 1/6W-RES
R11 3K1 AXIAL-0.4
R12 330 AXIAL-0.4
S1 DTS-6 DTS-6 switch-tact
S6 DTS-6 DTS-6 switch-tact
S7 DTS-6 DTS-6 switch-tact
S8 DTS-6 DTS-6 switch-tact
S9 DTS-6 DTS-6 switch-tact
U$1 2.1MMJACKTHM PJ-102A
U1 ATMEGA328P-PU DIP254P762X457-28
Note:- The ATmega328P requires a Uno or Duemilanove bootloader. You can either use another Arduino to burn a bootloader or you can buy one pre-burned. Which ever bootloader you use, you MUST select that device in the Arduino IDE. Failure to do so will result in avrdude errors.
****This device can control MAINS POWER devices. Mains power electricity is DANGEROUS. Faulty mains wiring due to lack of knowledge can KILL you and/or others! It is YOUR responsibility to correctly wire the controlled devices or find someone who can. *********
Check off all components against the list before beginning assembly.
You will also need to buy a SSR (Solid State Relay), USB FTDI 5V cable a HD44780 compatible 16x2 LCD, and a thermocouple.
SSR's are available in both AC and DC output versions, make sure you get the right type for your application. The input voltage must accept 5V. Heating applications require a Zero-Crossing SSR (these make up the majority of available SSR's). The SSR switching current and voltage ratings MUST at least meet, or preferably exceed the ratings of the device you intend to control.
Note:- some SSR's need a heatsink, especially if they are operating close to their maximum current. If the SSR is to mounted in a warm/hot area you MUST use a SSR that significantly exceeds the current rating of the device to be controlled.
Thermocouples- If you require a large temperature range (−200 °C to +1350 °C ), I recommend a K-type thermocouple. If you require a narrower temperature range (−200 to 350 °C), I recommend a T-type thermocouple . Note that T-type thermocouples are more accurate than K-type. There are also other types of thermocouples available, make sure you know what type thermocouple suits your particular application before proceeding.
Thermocouple sensor JUNCTIONS come in many types:- Washer, Probe, Bead, etc. You will need to select a thermocouple junction that best suits your application.
IMPORTANT NOTE:- If you get a MAX31855KASA+ IC, you MUST use a K-type thermocouple. If you get a MAX31855TASA+, you MUST use a T-type thermocouple. If you use the wrong thermocouple you will get incorrect readings. Both of the MAX31855 IC's are available directly from MAXIM Integrated - http://www.maximintegrated.com/datasheet/index.mvp/id/7273/t/al
If you are a student you can get free samples of these IC's from Maxim Integrated.
Solder the Surface Mount chip first, as it will be very difficult to solder it when there are other components around it later.
The chip is mounted with pin 1 to the lower RHS of the PCB.
I strongly recommend the use of extra flux, a magnifier and tweezers to carry out this step. Solder paste is NOT required to solder surface mount chips with a soldering iron, especially SOIC packages such as this one.
First, before placing the chip, solder where pin 1 of the chip will go, so there is a little spot of solder on the pin 1 pad. Once the solder cools, add a little flux and then place the chip carefully with tweezers.
When correctly placed (double check the chip orientation is correct!), tin the tip of your soldering iron with a little solder and touch it to pin 1 and the spot of solder you added earlier. The extra flux will help the solder flow without needing to add more solder.
When this is done, check the alignment of the other pins to their respective pads. If correctly aligned, flux each pin & pad, then carefully solder each one (the additional flux will help prevent solder bridges). If the IC is NOT correctly aligned, add some more flux to pin 1, & touch the tip of the soldering iron to pin 1 and align the chip before attempting to solder other pins. Keep the amount of time that the soldering iron is on any of the pins of the MAX31855 chip to a minimum to avoid damaging the chip.
When done clean the area with some isopropyl alcohol and an old toothbrush or paper towel to remove the flux residue.
Position the components for the +5V power supply on the PCB. These components will be fitted on the LHS on the PCB. They include the DC Jack, 1N4007 Diode, 2 x 47uF Electrolytic Capacitors, the 0.1uF Capacitor, the 2.7K resistor and the LM7805 Voltage Regulator. You will notice they are all grouped together on the PCB.
Make sure the Electrolytic Capacitors are positioned with the "-" symbol on the capacitor on the opposite side to the "+" marking on the PCB. Make sure the LM7805, and the 1N4007 Diode are positioned with the stripe (negative side) as shown on the PCB. Solder the above parts into position and clip excess lead length.
After soldering and clipping the excess leads, turn the PCB over and fit the Green LED to the other side of the board raising it approx 3mm (1/8") above the board. Before soldering, double check the polarity. The flat side of the LED is the "-" lead, the longer lead is the "+" lead. After soldering clip the excess lead length on the other side of the board.
Now connect a walwart power supply (2.1mm Center Positive) with a voltage of 9V to 12V DC.
The Green LED should illuminate.
If the Green LED does NOT illuminate, something has been positioned incorrectly, or there is a bad solder joint. You will need to rectify any incorrectly positioned or soldered components before continuing the build.
The 3V3 power supply components inhabit the lower RHS of the PCB close to the MAX31855 chip. These components are 3 x 1N4148 signal diodes, 2 x 10uF electrolytic capacitors and 1 x 10K resistor (below the MAX31855 chip).
Position and solder the 3 x 1N4148 Signal Diodes as shown to the Lower Right side of the PCB. Take care to observe the polarity of the diodes. The stripes on the diodes (negative side) must match the stripes on the PCB.
***Important Note - The diodes are NOT all facing the same way. Double check the polarity before soldering***
Next position and solder the 2 x 10uF Electrolytic Capacitors, taking care to observe polarity as indicated on the PCB. Finally position the 10K resistor & solder into place.
If you have a multimeter, connect your walwart to the PCB and confirm approx 3.3V (3.1V-3.3V typically) is present on the LHS of the 10K resistor (with the negative lead of the meter to the center pin (GND) of the LM7805 Regulator). If you do not have a multimeter, you can press the leads of the Red LED against pins 1 (GND, negative side of LED) and pin 4 (3V3 Vcc, positive side of LED) of the MAX31855 chip.
If no voltage is present, or the LED does not illuminate, you have most likely positioned one or more of the diodes incorrectly. If this is the case, check the other components as well as there may be other polarized components incorrectly positioned.
As you are soldering components, it is a good practice to clean the PCB periodically with some Isopropyl Alcohol and a swab or an old toothbrush or paper towel to remove the flux residue.
Start positioning/soldering the components with the lowest profile (ie, resistors) and work your way up to taller components to make your job easier.
Position all of the resistors, making sure you have placed each resistor in its correct position. Use a resistor color code chart to check against if you don't know the color codes or use a multimeter to check. Solder them into place and clip excess lead lengths on the back of the board.
Fit the Red LED on the same side of the PCB as the Green LED. Allow 3mm (1/8") of extra lead length so the LED sticks out from the board, just like you did for the Green LED.
Now position the socket for the ATmega328PU chip in place taking care to align the notch in the socket with the notch shown on the PCB. Double check the socket is positioned correctly before proceeding. Solder only 1 pin, check the socket is inserted correctly and fully, then solder the other pins.
Position the Ceramic Capacitor and the 16MHz Resonator and solder into place. Now position the Transistor in place making sure the orientation is as shown on the board and solder into place.
Position and solder the 2 position terminal connectors to the PCB, with the terminal holes facing out from from the PCB.
Position the 6 Pin Right Angle Male Header in place with the short, straight pin side through the PCB and the right angle pin side pointing down, and solder into place.
Position and solder the 16 pin male header in place with the 90 degree pin side through the PCB and the short straight pin side facing AWAY from the PCB.
Alternately, if you wish to change the form factor of the Arduino PID controller, you can choose to use straight pin header. In this form factor, the mounting holes in the PCB line up with the mounting holes on the LCD
Position the Potentiometer and solder into place.
Now you should have just 5 button switches and the LCD screen left.
Turn the PCB over and fit the 5 switches to the same side of the PCB as the LEDs and solder into place.
With the majority of the components (except the switches and LEDs) facing down, position the LCD. Before soldering make sure that the Pin 1 & Pin 16 marks on the LCD match the Pin 1 and Pin 16 marks on the PCB respectively before continuing. After double checking the LCD is positioned correctly, solder it into place.
Check the notch marked on the ATmega328 chip and align it with the notch on the socket (Double check that the socket is facing the correct way!)
You may need to bend the pins of the chip slightly inwards. Carefully push the chip into the socket, taking care not to bend the pins as you insert the chip. Visually inspect the chip/socket before going further.
Download the Arduino IDE V1.0 for your OS from http://arduino.cc/en/main/software
Make sure you get the right version! Install the software.
When installed, connect the USB cable to your computer first , then connect the other end to the PCB making sure the black wire in the cable lines up with the pin marked "GND".
******Note:- If you connect it the wrong way you will damage the ATmega328 chip, so make sure you position it correctly!********
Open the Arduino IDE now installed on your computer. Click on "Tools", "Board" and select "Arduino Uno". Then click on "Tools" and "Serial Port" and select the COM port the PCB is connected to. If you are not sure which COM port is being used, go to your Device Manager, click on the arrow next to "Ports (COM & LPT)". You should see at least 1, possibly more devices listed. Unplug the cable from your computer, and plug it in again. The device that disappears and reappears from the list is the Arduino PID Controller. Take note of the COM port number.
Go back to the Arduino IDE and now select the correct port.
To test the ATmega chip, go to the Arduino IDE and click on "File", "Examples", "Basics", "Blink" This will open a new IDE window with some code in it.
Go to line 13 (line number is at the bottom left of the Arduino IDE window) where it says
" pinMode(13, OUTPUT); "
change the "13" to "7" (without the quotes)
Now go to lines 15 and 17 and change the "13" to "7"
Now click on the Verify button (looks like a "Tick"), when it compiles, then click on the Upload button (next to the Verify button). If it does not compile, you have made a syntax error.
Immediately press and HOLD the Reset button on the Arduino PID controller, when you see the text "Binary sketch size: xxxx bytes (of a 30720 byte maximum)" appear in the bottom of the Arduino IDE window, RELEASE the Reset button.
If you get an avrdude error, it most likely means you didn't release the button soon enough, or you have the wrong Arduino board selected under Tools. Check the correct board is selected under Tools and try uploading again and release the RESET button at the correct time.
When it uploads correctly, you should see the Red LED begin blinking. This indicates that the Arduino is working correctly. You are now ready to upload the PID code.
STEP 7 -
Go to https://github.com/CoffeeTronics and locate and download the zip for Arduino PID controller for Espresso that has the highest version number (version 2.0 and above). The "Download Zip" button should be on the RHS of the webpage, just below the "Clone In Desktop" button. Extract the downloaded zip file to your computer. Go into the extracted folder & copy the CONTENTS of the extracted "Libraries" folder (NOT the Libraries folder itself) to your Arduino "libraries" folder (where you installed the Arduino IDE).
Copy the Arduino_PID_Controller sketch to your Arduino "Sketchbook" folder.
Now close ALL Arduino IDE windows you have open and restart the IDE. Click on "File", "Sketchbook". The file "Arduino_PID_for_Espresso_v2.0" should now be there. Click on it, a new window will open containing the code.
If the "Arduino_PID_Controller" sketch is not there, most likely you did not close all Arduino IDE windows. Close all Arduino IDE windows and restart the IDE and check again
Once you have opened the code, click on the "Verify" button. After it compiles, upload the code to the Arduino PID Controller (Don't forget the RESET button!).
If it doesn't compile, you may have downloaded the wrong version of the Arduino IDE, or an obsolete version of the Arduino PID Controller code or you may have placed the contents of the Libraries folder in the wrong folder, or have a Libraries folder inside the Libraries folder.
Once it has uploaded successfully, remove the programming cable and walwart power from the PID Controller, the LCD screen and Green LED should now be OFF. Now connect the PID Controller OUTPUT pins ("-" is on the lower side, "+" is on the upper side) to the INPUT pins of the SSR you purchased. Make sure the + pin of the output goes to the + pin of the SSR. and the "-" output pin goes to "-" input of the SSR.
*****IMPORTANT:- Make sure the device you intend to control is UNPLUGGED from the power outlet before proceeding with the next step!!***** Connect the OUTPUT side of the SSR to the device you are controlling (eg. Inline with the heating element).
Connect the Ground ("-" input) of the SSR INPUT side to the Ground of the device being controlled. This helps prevent capacitive ground loops, which can cause erratic temperature readings.
Connect your thermocouple to the thermocouple input terminal connector, taking care to observe polarity. If you have used a K-type, then the Yellow Wire is + and the Red wire is -. If you have used a T-type thermocouple, the Blue wire is + and the Red wire is -. The "+" side of the thermocouple terminal block is on the upper side, while the "-" is the lower side.
Connect your walwart to the DC Jack on the PCB. The Arduino PID Controller will boot up, the LCD will say "Arduino PID for Espresso". After 3 seconds, it will begin displaying temperatures. As the code contains an array for smoothing the temperature readings, the displayed temp will increase rapidly for the first couple of seconds before stabilizing.
Hold the thermocouple junction (the end that senses temperature) in your hand and you should see the temperature reading on the LCD increase from your body heat. If it decreases, you have connected the thermocouple backwards.
Now you can fit the thermocouple to the device being measured. If you are using a washer thermocouple and the place where you are fitting the thermocouple to is Grounded, you may find the temperature readings jump around a bit. If this occurs, you will need to electrically insulate the thermocouple from the device being measured with Mica washers and some teflon tape around the screw/bolt. Don't forget to use some thermal compound to keep good thermal conductivity.
You are now ready to tune the controller.
STEP 8 -
Note:- The Autotune function steps the Output and observes changes in the Input to calculate parameters for the Proportional, Integral and Derivative Bands.
Go to the Google code page for Processing-
https://code.google.com/p/processing/downloads/detail?name=processing-1.5.1-windows.zip&can=2&q= Download the zip folder and extract it to your computer.
Now go here - http://www.sojamo.de/libraries/controlP5/
and download the ControlP5 library. Follow the instructions listed on the webpage under "Installation".
Now go to the where you extracted the Arduino PID ZIP and look for "AutoTune Front and Backend" folder. Copy the folder to your Arduino folder (most likely in your Documents folder).
Open the Arduino IDE, then click File, Open. Navigate to the extracted zip file and open it. Open the folder Autotune Front and Backend, then open the folder AutotuneMAX31855Backend, then open the folder AutotuneMAX31855. Double click on the ino file AutotuneMAX31855. This will open the BackEnd of the Autotune code in the Arduino IDE..
Ctrl F (FIND) "//EDIT" (without quotes) and hit ENTER to find parameters than can be changed by the user (YOU). If you change parameters, it is recommended you save the code with a different name, should you wish to easily change back to the original code.
Upload the code to the Arduino PID Controller (make sure programming cable is oriented correctly, and RESET button timing is correct). When finished programming leave the cable connected to the Arduino PID controller as it will be used by the processing FrontEnd. Close the Arduino IDE.
Open the Processing IDE, click on File, Open, then find the zip folder you extracted, AutoTune Front and Backend, ProcessingFrontend, PID_FrontEnd_v0_3. Select the PDE file named PID_FrontEnd_v0_3.
This will open the code in a new Processing window.
Do a CTRL F (find), type in "//EDIT" (without the quotation marks") and hit ENTER. This will take you parameters that may be adjusted by the end user (YOU) before running the tuning front-end.
If you make any changes, save the updated file under a new name, so it is easy to go back to the original if needed.
Now click "Run" (looks like a Play button). This will open a window where you can manually tune or Autotune the controller. If after about 20 seconds you cannot see the Setpoint, output and Input being graphed (RHS of window), try closing the window and click the Run button again. If you have problems getting Processing to graph values, check you have closed all Arduino IDEs. Occasionally Windows causes problems, and needs to be rebooted.
I will assume you want to use Autotune as it is far easier for beginners. Check the programming cable is still connected.
The values to the RHS of the buttons in the Processing window are the current values in use. The values to the LHS or BELOW the buttons can be changed to what you require. These values will be shifted in when the SEND_TO_ARDUINO button is clicked.
Set the TOGGLE_AM button to MANUAL, set the SETPOINT button to your required Setpoint, check TOGGLE_DR is set to DIRECT, check TOGGLE_TUNING is set to OFF. Now click the SEND_TO_ARDUINO button.
This puts the controller in MANUAL mode. Start small and slowly increase the OUTPUT button (0-1000) each time you change it, click the SEND_TO_ARDUINO button (Toggle the TOGGLE_AM button to AUTO then back to MANUAL before clicking SEND_TO_ARDUINO), Continue slowly increasing the OUTPUT until your system is in equilibrium with the desired temperature. This can take some time, especially for slow temperature loops, so be patient!
When your system is at equilibrium with the desired SetPoint, change the "Toggle Tuning" button to ON and click "Send to Arduino". The value to the RHS of the Toggle_Tuning button should change to ON. This means it is now AutoTuning the loop. If you watch the OUTPUT graph, you will see the AutoTune function Step the Output several times. When the value beside Toggle Tuning changes from ON to OFF it has finished. The values you now see next to P, I and D are the Autotuned values. Make a note of these values.
Note:- The Autotuned values are a good place to begin manual fine tuning to get better tuning parameters. There are plenty of guides on manual tuning of PID loops. In my personal experience, I have found that running Autotune first, and then tweaking the values gradually gives quite decent results.
Now you can either spend some more time manually fine tuning the loop, or you can upload the Arduino_PID_for_Espresso sketch to the PID controller (inserting the parameters you noted into lines 120-122 of the Arduino PID Controller sketch).
The structure of the menu system is
BREW ESPRESSO--This will change setpoint to Brew Setpoint
STEAM MILK--This will change setpoint to Steam Setpoint
BREW TEMP--SET BREW POINT--Press L and R keys to change Brew Setpoint
STEAM TEMP--SET STEAM POINT--Press L and R keys to change Steam Setpoint
OFFSET--SET OFFSET--Press L and R keys to change Offset (this is used to display "at the group" temps for espresso machines)
SCALE-- Not currently in use, will be implemented in a software update available through GitHub.