HomeHow ToHow to Monitor the Raspberry Pi's Temperature

How to Monitor the Raspberry Pi’s Temperature

Raspberry Pi has gotten very powerful over the years, especially with the launch of Raspberry Pi 5. Putting things in perspective, currently, we are using our Raspberry Pi 4 (4 GB version) to run a VPN Server, 2 Instances of Transmission, a Files Server, a LAMP Server, a Pi-Hole, a Home Assistant, and many other services.

So, it becomes quite essential to monitor the temperature of your Raspberry Pi, especially if it runs 24×7. As per the official figures, it must stay under 85°C at all times to prevent any permanent damage. Raspberry Pi will start throttling the CPU/GPU performance once it reaches 80°C.

There are various methods via which you can get the current temperature of the Raspberry Pi; most of them are mentioned below.

Ways to Monitor the Raspberry Pi’s Temperature

1. Using Broadcom’s vcgencmd

One of the easiest methods to access the temperature data is by using the built-in command line tool vcgencmd. Type the command below:

vcgencmd measure_temp

This command will show you the Pi’s temperature in Celsius:

Vcgencmd Measure_Temp

However, this is a one-time output method. If you want to monitor the temperature continuously, try the method #3.

2. Reading Data with Thermal Zone Driver

Use the following command to read the raw temperature data.

cat /sys/class/thermal/thermal_zone0/temp

You will get the following output:

Cat /Sys/Class/Thermal/Thermal_Zone0/Temp

The number 48686 will need to be divided by 1000, which will be 48.68°C. Just like Method #1, this is also a one-time output method. For continuous monitoring, follow Method #3.

3. Using Watch Command with Method #1 or #2

We can use the watch command to execute any command at a specified interval.

watch -n [seconds] [command]

Here, replace [seconds] with number of seconds to wait before repeating the command and [command] with any one-time output command.

Use the following command to refresh the output of Method #1 every one seconds:

watch -n 1 vcgencmd measure_temp
Watch -N 1 Vcgencmd Measure_Temp

The same can be repeated with Method #2 using the command below:

watch -n 1 cat /sys/class/thermal/thermal_zone0/temp
Watch -N 1 Cat /Sys/Class/Thermal/Thermal_Zone0/Temp

To exit the watch command, Press Control + C.

4. Using Python & Built-In Libraries

If you prefer using Python scripts over Bash, we have prepared a small Python code that will update the temperature on your terminal every second.

You can change the time interval by modifying the number in the sleep() function.

  1. Create a new file named “temperature_monitor.py” using the following command.
nano temperature_monitor.py
  1. Paste the following code:
import gpiozero as gz
from time import sleep
import os

while True:
    print(round(gz.CPUTemperature().temperature, 1))
    sleep(1)
    os.system('clear')
  1. Press Control + X, Type ‘Y’, and press Enter to save and exit the editor.
Nano Temperature_Monitor.py
  1. Type the following command to run the script and Control + X to exit.
python temperature_monitor.py
Python Temperature_Monitor.py

5. Monitoring temperature with Raspberry Pi Desktop UI

If you are not running Raspberry Pi in headless mode and using it as a normal computer with a display, this method might come in handy. You can simply add the temperature monitor as a panel item in the Taskbar.

  1. Right-click the Task Bar and select Add / Remove Panel Items to open Panel Preferences.
Raspberry Pi Taskbar Right Click
  1. Go to the Panel Applets Tab and Click Add.
Raspberry Pi Taskbar Panel Preferences
  1. Select CPU Temperature Monitor and Click Add.
Raspberry Pi Taskbar Add Plugin
  1. Close the Panel Preferences; now you will see the CPU Temperature and a Mini Graph on the Taskbar.
Raspberry Pi Taskbar With Temperature

Bonus Tip: Creating Alias for Terminal Command to Read Temperature

Suppose you frequently use some commands, for example, to check the temperature, as mentioned in earlier methods. In that case, creating an alias is the easiest way to execute them without remembering the entire command. Here is how to do so:

  1. Create bash aliases file using the command below:
nano ~/.bash_aliases
  1. Type the following in the file:
alias pitemp='[command]'

Replace [command] with any command mentioned in the earlier methods. Here, we are using ‘vcgencmd measure_temp’

Nano ~/.Bash_Aliases
  1. Press Control + X, then Type Y and Enter to save the changes to the file.
  2. Close the current terminal session for the changes to take effect. Open a new terminal session and type:
pitemp
Pitemp

You can do the same with any commands you intend to use frequently.

Also read: How to Automatically Spin Down or Sleep HDD on Raspberry Pi

So, those are almost all the ways you can check and monitor the temperature of your Raspberry Pi. If you think we missed anything, enlighten us in the comment section below.


“As an Amazon Associate & Affiliate Partners of several other brands we earn from qualifying purchases.” [Read More Here]


Mehul Boricha
Mehul Boricha
Mehul Boricha is the driving force behind Tech Arrival. He is a computer and smartphone geek from Junagadh, Gujarat, India. He is a Software Engineer by Education & a Blogger by Passion. Apart from technology geek, his free time is dedicated to cybersecurity research, server optimization, and contributing to open-source projects.

Leave a Comment

Please enter your comment!
Please enter your name here


By submitting the above comment form, you agree to our Privacy Policy and agree with the storage and handling of your data by this website.


Stay Connected