Raspberry Pi

What are different methods to monitor the temperature of the Raspberry Pi 4

The Raspberry Pi 4 is a single board computer which means it has a processor or a CPU to process the commands and also has the RAM with other peripheral devices that a computer has like a keyboard. When we use the Raspberry Pi 4 to process different tasks it raises the temperature of the CPU of the Raspberry Pi. Temperature rise can damage the CPU. In this write-up, we will find out the methods by which we can monitor the temperature of the Raspberry Pi 4 and protect it from overheating.

How to monitor the temperature of the Raspberry Pi

We can monitor the temperature of the Raspberry Pi by different methods:

All these methods to find the temperature of the Raspberry Pi are explained in detail.

How to monitor the temperature of the Raspberry Pi by using Python script

We will create a file of name “temp.py” with the nano text editor, for this, we will use the command:

$ nano temp.py

When the file is opened, type the following Python code in the file to monitor the temperature of the Raspberry Pi 4:

import gpiozero as gz

#import gpiozero library

temp= gz.CPUTemperature().temperature

#save the value of temperature of Raspberry Pi in "temp" variable

round_temp= round(temp,1)

#round the value of temperature to one decimal

print ("The temperature of Raspberry Pi:")

print (temp)

print ("Temperature's value rounded to one decimal:")

print (round_temp)

#printed the values of temp and round_temp variables

Explanation of code: In the above code, we have to import the library of the gpiozero and then find out the CPU temperature and store the value in the “temp” variable. Then use the round() function to round off the store value of the temp variable and store it in the round_temp variable. Finally using the print command, we have printed both values on the screen.

The output of the above Python script to monitor the temperature can be checked by running the python code using the command:

$ python temp.py

How to monitor the temperature of the Raspberry Pi by using a bash command

If we want to display the temperature of the Raspberry Pi through the bash command, we will display the “/sys/class/thermal/thermal_zone0/temp” where the temperature of the Raspberry Pi 4 has been stored, for this purpose, we will use the command:

$ cat /sys/class/thermal/thermal_zone0/temp

The answer is without the decimal which means the temperature is 48.686 degrees.

How to monitor the temperature of the Raspberry Pi by using vcgencmd

We can also find out the temperature through the terminal of the Raspberry Pi 4 using the vcgencmd utility which comes pre-installed with Raspberry pi:

$ vcgencmd measure_temp

How to monitor the temperature of the Raspberry Pi by using a GUI

We can also use the graphical user interface to monitor the temperature and can set it on the top menu bar so it will continuously display the temperature of the Raspberry Pi 4, for this purpose, we will right-click from the mouse on the top menu bar of the desktop of Raspberry Pi, a drag-down menu will appear, choose the “Add/Remove Panel Items…”:

A window will appear, click on the “Add” button:

Find out the “Temperature Monitor” and click on the “Add” button to add it on the title bar of the desktop:

Set its position on the menu bar, as we want to set it between the Spacer and Digital Clock, we will place it in between by using the “Up” button:

Once the position is set, click on the “Close” button:

The temperature of the Raspberry Pi 4 is displaying on the top of the menu bar as highlighted in the figure below:

Conclusion

The temperature of the CPU rises with the excessive use of the Raspberry Pi 4 which can damage the board. There are different methods to find out the temperature of the board of the Raspberry Pi 4. In this write-up, we have discussed different methods to find out the temperature of the board of the Raspberry Pi 4.

About the author

Hammad Zahid

I'm an Engineering graduate and my passion for IT has brought me to Linux. Now here I'm learning and sharing my knowledge with the world.