DIY: How to Build Your Own PID Temperature ControllerAssembly Time: 2 to 3 hours
This PID (Proportional-Integral-Derivative) temperature controller has been designed around the ATmega328P microcontroller and utilizes the Duemilanove bootloader. This kit incorporates a basic Arduino clone (the Arduino board is not required).
Required tools and components:
Fine gauge solder (23 gauge or finer)
MAX31855 thermocouple interface chip (available directly from Maxim Integrated)
Thermocouple with junction suitable for your application (e.g., probe, washer, etc.)
J-type (-40°C to +750°C)
K-type (-200°C to +1350°C)
T-type (-200°C to +350°C) Solid state relay (will depend on your application)
USB FTDI 5V cable (Note: A single cable can be used for many different microcontroller projects)
Computer with Arduino IDE v1.0
Wall-wart 9V/1.5A, 2.1mm center positive
|Part Description||Manufacturer Part Number|
|Capacitor, radial, 47µF, 50V||R47/50|
|IC, 7805T, TO-220||7805T|
|Capacitor, 0.1µF, 50V||MD.1|
|Resistor, 1/4W, 1kΩ||CF1/4W102JRC|
|LED, T1, green, diffused||LTL-4231|
|Diode, 1N4007, 1A||1N4007|
|Jack, DC power, male, 2.1mm||GCD014-R|
|Capacitor, ceramic disc, 0.01µF, 50V||DC.01|
|Resistor, 1/4W, 10kΩ||CF1/4W103JRC|
|Capacitor, radial, 10µF, 25V||R10/25A|
|Header, vertical, male, 0.1", 1 row, 6 pin||JS1109-6-R|
|Switch, pushbutton, tactile, SPST, OFF-(ON)||BTS-1102B-2|
|IC, MCU, ATmega328P, with Arduino Uno bootloader||A000048|
|IC socket, 28-pin||6000-28NDW|
|Transistor, 2N4401TA, NPN||2N4401TA|
|LED, orange/red, red diffused, T1, 635nm||MCDL-314ED|
|Resistor, 1/4W, 2.7kΩ||CF1/4W272JRC|
|LCD display, 16x2, parallel interface||NHD-0216BZ-FL-YBW|
|Potentiometer, 3/8" square cermet, 1/2W, 10kΩ||3386P-1-103/63P/72PR|
|Resistor, 1/4W, 330Ω||CF1/4W331JRC|
|Header, vertical, male, 0.1", 1 row, 10-pin||7000-1X10SG-R|
Warning: This kit can control mains power devices. Mains power electricity is dangerous. Faulty wiring from lack of knowledge can kill. It is your responsibility to correctly wire the controlled devices or find someone who can.
This controller works by measuring the difference between the desired temperature and the measured temperature. It will perform three separate calculations and calculate the sum of the three then apply the sum as a percentage of a given window of time in the form of a pulse to the solid state relay (SSR).
- Proportional to the size of the error
- Integral time of the error
- Derivative rate of change to the process value
- Temperature reading using the MAX31855 chip
- PID control algorithm code
- Menu system to change the desired temperature and other parameters
Step 1: Check Your Kit's ComponentsCheck off all components against the kit list before beginning assembly. Be sure to check the required components. Some components will depend on your application and will need to be sourced separately. SSRs come in both AC and DC output versions, so please make sure to get the right type for the application.
- Voltage input must accept 5V
- Applications with heating require a zero-crossing SSR
- SSR switching current and voltage ratings must meet or exceed the ratings of the device you are controlling
- Some SSRs need a heat sink (operating close to their maximum current)
- If the SSR is mounted in a warm/hot area, you must use a SSR that significantly exceeds the current rating of the device to be controlled
Step 2: Soldering the SMD ChipSolder the surface mount chip first to make soldering on the rest of the components easier. The chip is mounted with pin 1 to the lower right side of the PCB. Extra flux, a magnifier and tweezers will come in handy when soldering. I find it easier to solder a little spot on the pad where pin 1 of the chip will go before placing the chip. When the solder cools, add a little flux and place the chip carefully with the tweezers.
Double check the chip orientation, solder pin 1 and the spot you added solder to earlier. The extra flux will help the solder flow without having to add extra solder. Check the alignment of the other pins to their respective pads, flux each pin and pad, then carefully solder each one.
Step 3: Construction and TestingGo ahead and position the components for the +5V power supply on the PCB. These components will be fitted on the left-hand side of the PCB. Parts include the DC jack, 1N4007 diode, two 47µF electrolytic capacitors, 0.1µF capacitor, 2.7KΩ resistor and LM7805 voltage regulator.
They will all be grouped together on the PCB. Check that the electrolytic capacitors are positioned with the "-" symbol on the capacitor on the opposite side to the "+" marking on the PCB.
The LM7805 and 1N4007 diode are positioned with the stripe as shown on the PCB. Solder the above parts into position and clip excess leads. When you are done soldering, turn the PCB over and fit the green LED to the other side of the board raising it approximately 3mm (1/8") above the board. 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.
Connect a wall-wart power supply (2.1mm center positive) with a voltage of 9V to 12V DC. The LED should illuminate. If it doesn't work, go back and check all of your soldering joints and components positioning.
Step 4: The 3.3V Power Supply ComponentsThe 3.3V power supply components inhabit the lower right-hand side of the PCB near the MAX31855 chip. These components are three 1N4148 signal diodes, two 10µF electrolytic capacitors and one 10K resistor.
Position and solder the three 1N4148 signal diodes as shown to the lower right side of the PCB. The stripes on the diodes (negative side) must match the stripes on the PCB. The diodes are not all facing the same way. Double check the polarity before soldering!
Position and solder the two 10µF electrolytic capacitors and then position the 10K resistor and solder into place. Power it up with a multimeter and check that you have approximately 3.3V (3.1V-3.3V) present on the left-hand side of the 10K resistor.
You could also press the leads of the red LED against pins 1 (GND, negative side of LED) and pin 4 (3.3V Vcc, positive side of LED) of the MAX31855 chip. If there is no voltage or the LED does not illuminate, the diodes may be positioned incorrectly.
Step 5: Soldering the Final ComponentsSoldering the components with the lowest profile and working your way up to larger components will make your job easier. Solder the remaining components.
With the majority of the components (except the switches and LEDs) facing down, position the LCD. Before soldering, make sure that the pin 1 and pin 16 marks on the LCD match the pin 1 and pin 16 marks on the PCB respectively.
If you wish to change the form factor of the Arduino PID controller, you can choose to use a straight pin header. In this form factor, the mounting holes in the PCB line up with the mounting holes on the LCD.
Step 6: ATmega328 and Final TestingCheck the notch marked on the ATmega328 chip and align it with the notch on the socket. Carefully push the chip into the socket.
Download and install the Arduino IDE V1.0 software.
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". If you connect it the wrong way, you will damage the ATmega328 chip. Open the Arduino software and click on Tools > Board and select Arduino Uno. Click Tools > Serial Port and select the com port the PCB is connect to.
To test the ATmega chip, 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 reads: "pinMode (13, OUTPUT)." Now change the 13 to 7. Also go to lines 15 and 17, and change the 13 to 7.
Click on the Verify button when it compiles, then click on the Upload 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 and release the Reset button.
If you receive an avrdude error, it means you didn't release the button soon enough or you have the wrong Arduino board selected under Tools. Make sure 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 will see the red LED begin blinking. This indicates that the Arduino is working correctly and you are now ready to upload the PID code.
Step 7: Programming the PID ControllerDownload this file for the controller named Espresso that has the highest version number 2.0 or above. Copy the contents of the extracted Libraries folder (not the Libraries folder itself) to your Arduino libraries folder.
Copy the Arduino_PID_Controller sketch to your Arduino Sketchbook folder. Close all Arduino IDE windows and restart the IDE.
Click on File > Sketchbook> Arduino_PID_for_Espresso_v2.0. Click on the Verify button and when it is done compiling, upload the code to the Arduino PID controller – don't forget the Reset button! Once it has uploaded successfully, remove the programming cable and power from the PID controller. The LCD screen should now be off. Connect the PID controller output pins ("-" is on the lower side and "+" 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 that the "-" output pin goes to "-" input of the SSR.
Warning: 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. Connect the ground ("-" input) of the SSR input side to the ground of the device being controlled. This will help prevent capacitive ground loops, which can cause erratic temperature readings.
Connect your thermocouple to the thermocouple input terminal connector. 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 and the "-" is the lower side.
Connect your wallwart to the DC jack on the PCB. The Arduino PID controller will boot and the LCD will say "Arduino PID for Espresso". After three 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 end that senses the temperature in your hand and you'll see the temperature reading on the LCD increase from your body heat. If it decreases, you have connected the thermocouple backwards.
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. Use some thermal compound to keep good thermal conductivity.
Step 8: Controller TuningThe Autotune function steps the output and observes changes in the input to calculate parameters for the proportional, integral and derivative bands.
Download an install this file and download and install the ControlIP5 library.
Where you extracted the Arduino PID ZIP, look for the "Autotune Front and Backend" folder. Copy the folder to your Arduino folder and open the Arduino IDE. Open the folder Autotune Front and Backend > AutotuneMAX31855Backend > AutotuneMAX31855. Double click on AutotuneMAX31855 to open the Backend of the Autotune code in the Arduino IDE. Hold down the CTRL and F keys, then type in "//EDIT" (without the quotation marks) and press Enter to find parameters than can be changed by the user. If you change parameters, save the code with a different name.
Upload the code to the Arduino PID controller (make sure the programming cable is oriented correctly and Reset button timing is correct). When finished programming, leave the cable connected (it will be used by the processing FrontEnd) and close the Arduino IDE.
Open the Processing IDE and click on File > Open. Find Autotune Front and Backend, ProcessingFrontend, PID_FrontEnd_v0_3. Select the file named PID_FrontEnd_v0_3. This will open the code in a new processing window.
Hold down the CTRL and F keys, then type in "//EDIT" (without the quotation marks) and press Enter. This will take your parameters, which may be adjusted by the end user before running the tuning front-end.
Click on Run (it looks like a Play button). This will open a window where you can manually tune or Autotune the controller. Using Autotune is far easier for beginners.
Check that the programming cable is still connected. The values to the right-hand side of the buttons in the processing window are the current values in use. The values to the left-hand side 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 right-hand side 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.
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. 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 through 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