Raspberry Pi Pico Based Temperature Controller

by Bardia Alikhan Afshar in Circuits > Raspberry Pi

10944 Views, 26 Favorites, 0 Comments

Raspberry Pi Pico Based Temperature Controller

4.jpg

Hi, everybody. Ok, I know there are so many temperature controllers with different software and hardware systems over the internet, but this can be interesting for you as I used raspberry pi pico as the central controller.

One of my friends has a refrigerated warehouse, and the controller used in the mentioned warehouse was broken. I told him that I would build you a controller. As I am a fan of C language and ARM-Cortex microcontrollers, At first, I decided to use STM32 for this purpose. By chance, I saw that I bought a raspberry pi pico a while ago, and I thought it would be fun if I use the raspberry pi to overcome this project. And Also, I can share it over the internet with you.

As the temperature in the warehouse does not fluctuate fast over time, I decided to use a thermocouple. The type of thermocouple that I used is K. for reading temperature from the thermocouple. I used MAX31855K from Maxim Integrated. Also, I used Alphanumeric LCD 16*2 as a display. The type of controller that I implanted on raspberry pi pico is an ON-OFF controller.

So with this intro, let's dig into it.

Supplies

Raspberry pi pico

MAX31855K

LCD 16*2

OMRON G3MB Series 5V SSR

K-Type Thermocouple

A custom PCB

Type of Controllers

1.png

As you probably know, there are different types of temperature controllers out there. For example, Proportional temperature controllers whose output is proportional to the differential of the setpoint and actual temp.

Moreover, there is a PID temperature controller which controls output with more advanced techniques. A PID controller continuously calculates an error as the difference between the desired setpoint and a measured process variable and applies a correction based on proportional, integral, and derivative terms.

The controller that we will deal with, the simplest one, is the ON-OFF controller. In this type of controllers, the output will be activated whenever the process value is under the setpoint. And after the process value reached the setpoint, the controller will deactivate output. There is a variable here which is called differential value. The controller will be ON again whenever the process value comes under the (Setpoint-Differential).

So with these principles in mind, let us start.

The LCD

115985288-60b96a00-a5c0-11eb-8046-87dbdacdbcee.jpg

The first thing that I noticed is that there is no appropriate library for character LCD based on GPIO over the net. I found many libraries based on I2C and PCF8574, which is an IO expander. So I wrote a library based on GPIO for raspberry pi pico. I uploaded it on my GitHub with a sample code. You can find it here.

MAX31855

MAX31855 is one of the best chips you can find out there. It has everything that you need for reading temperature from the thermocouple. Also, it can detect faults such as open connection or short circuit to ground and VCC. MAX31855 transfer its data throughout an SPI protocol. It can read a temperature as high as +1800 and as low as -270. The last letter of the code name indicates the type of thermocouple. In my case, I used MAX31855K, which is for K type thermocouple.

I used MAX31855 before for my projects. However, the language was in C. So I ported my library in python to use with raspberry pi pico. Again, You can find it here on my Github.

Putting All Things Together

As the raspberry pi pico has a 3.3-volt voltage regulator on board, you can use a 5-volt power supply for turning on the device. For producing this voltage, I used LM1117-5 from Texas Instruments. After that, you have to feed this 5 volt on pin39 of raspberry pi pico, which is VSYS. Moreover, this 5 volt should be used to power up LCD and its backlight. The SSR that is Used is G3MB from Omron. The control pins of this SSR is 5 volt, and it can drive 100-220Volt 2Ampere loads. As a result, to control the SSR, we have to benefit from mentioned 5Volt. Now let us look at the schematic. On the top left side, you can see the power supply part, which I said before. On the right side of that, you can find the LCD. I used GPIO pins to drive the LCD. On the bottom left, we have MAX31855, which is our main chip for reading temperature from K type thermocouple. Also, I used a noise filter to reduce noise on thermocouples input. On the bottom right side, there is an SSR. As the GPIO pins of raspberry pi pico have 3.3volt output, I used an NPN transistor to switch the relay on and off. At last, in the centre, we have our raspberry pi pico and the pushbutton. You can download the schematic below.

Downloads

Fluctuations? Use Kalman Filter

3.png

As you probably know(or heard), the Kalman filter is an algorithm that uses different observations over time to estimate a measured variable, and this can be more accurate than a single measurement. We will be using a one-dimensional Kalman filter to reduce the fluctuation of reading data. I wrote a simple Kalman filter on Micropython for this purpose and used it on this project. If you want to study and become familiar with the Kalman filter, you can use this website.

Code

I uploaded all codes below. You can use Thonny to place codes on the raspberry pi pico. Open all the codes on Thonny and save them with the exact same name on raspberry pi pico. Then click the run button, and the system will begin to work.

Printed Circuit Board

IMG_2353.jpg
IMG_2356.JPG
2021-06-15_141829.jpg
2021-06-15_141804.jpg
20210614_175122.jpg
2.jpg

After I tested the circuit on the breadboard, I decided to design a PCB to put all the components on it and make it a solid device. You can download the Gerber files for the PCB below.

Downloads