In this guide, we will be showing you how to read the temperature of the Raspberry Pi using a simple command.
Monitoring the temperature of your Raspberry Pi can be a critical task. This is especially true when you are using the device in areas with little airflow.
Officially the Raspberry Pi’s processor is built to withstand temperatures from -40°C to 85°C.
As the Raspberry Pi’s temperature gets closer to its upper limit, the system will automatically begin to throttle the processor to try and help the board cool back down.
This throttling makes it crucial to manage your Raspberry Pi’s temperature to stop the device from losing performance. The throttling can be extra problematic when you are trying to overclock your device.
Reading the temperature of your Raspberry Pi’s processing core is a simple task and can be done using a single command.
Getting the Raspberry Pi Temperature Using the Terminal
Luckily for us, the Raspberry Pi’s processor features an inbuilt temperature probe that we can access.
To be able to retrieve the temperature of the Raspberry Pi, you will need terminal access.
Once you have access to the terminal through SSH or physical access, then you can proceed.
1. To retrieve the temperature of your Raspberry Pi, we can utilize the following command.
/usr/bin/vcgencmd measure_temp
2. From this command, you should get a result like we have below with specifying the temperature of your Raspberry Pi.
temp=42.0'C
One thing that you will notice is that all results from this command are provided in degrees centigrade.
3. If you are in a country that uses Fahrenheit, then you can convert this number by using the following formula (celsius * 1.8) + 32
Alternatively, you can utilize the following command, which will automatically retrieve the value and convert the Raspberry Pi’s temperature to Fahrenheit for you.
/usr/bin/vcgencmd measure_temp | awk -F "[=']" '{print($2 * 1.8)+32}'
Creating an Alias to Retrieve the Pi’s Temperature
If you check the Raspberry Pi’s temperature often and would like to simplify the command, you can make use of bash aliases.
1. Let’s go ahead and start creating the bash aliases file within the pi user’s home directory by running the command below.
nano /home/pi/.bash_aliases
2. Within this file, enter the following line.
alias temp='/usr/bin/vcgencmd measure_temp'
What this line does is make it so that whenever we type in the word temp
, the temperature of the Raspberry Pi will be outputted to the command line.
Once you have entered this line, please save the file by pressing CTRL + X then Y followed by ENTER
3.Before you can use this new alias you need to quit out of the current session and open a new one.
Once you have exited out of the terminal session and gone back in, you will now be able to use the temp
command to get your Raspberry Pi’s temperature.
temp
Reducing your Temperature
If you are having trouble with maintaining your Raspberry Pi at reasonable temperatures, here is a quick couple of tips on how to help.
Add a heatsink
Adding a heatsink is one of the easiest ways of reducing the temperature of your Raspberry Pi’s processor.
Heatsinks work by increasing the amount of surface area from which heat can dissipate.
Increasing Airflow
One of the other best ways of improving your Pi’s temperatures is to increase the airflow around the board.
Airflow is one of the best and cheapest ways of efficiently removing heat from your Raspberry Pi.
The easiest way of increasing airflow is to make sure you don’t put the Pi in too much of a closed space as well as using a case that has proper ventilation
Using a fan
Adding a fan to your case is another way of reducing the temperatures of your Raspberry Pi.
The advantage of a fan, of course, is that it helps quickly remove heat from around the device and drag in cooler air.
The most significant disadvantage of using a fan, of course, is the extra noise it will produce.
At this point, you should now have an idea on how to retrieve the temperature of your Raspberry Pi’s processor using a simple command.
If you have any questions or feedback, then feel free to drop a comment below.
Nice thank you, it was really helpful <33
In the latest Raspbian, vcgencmd is in /usr/bin rather than in /opt/vc.
Hi Salsaman,
Thank you for pointing out that this is now the norm for both the 32-bit and 64-bit release of Raspberry Pi OS.
I have updated the tutorial to point to the new locations.
Cheers,
Emmet
What are appropriate thresholds for the temperature on a raspberry pi 4 model B? Thanks!
Hi Milan,
The CPU on the Raspberry Pi is rated to operate between -40°C and 85°C. However other components on the board have tighter temperature requirements such as the LAN chip is only rated between 0°C to 70°C.
I hope that this answers your question.
Cheers,
Emmet
For purposes of monitoring the temperature throughout the day,
Is there a way to output the temperature to a file with date/time at regular intervals, say every hour?
You can create a small script to get the date, the temp etc, and output that to a file.
The file you could read and graph with e.g.
gnuplot
.With cron you can run the script at regular intervals:
Cron:
Result (hostname of my pi is raspberry1):
i am getting this error ‘
bash: /opt/vc/bin/vcgencmd: No such file or directory
‘when i execute the command. please help i am novice.
Hi Pranka,
What Raspberry Pi are you using? Also what operating system are you running on your Pi.
I quickly tested this again on a Raspberry Pi 4 running the latest version of Raspberry Pi OS and it works as intended.
Cheers,
Emmet
Perhaps you did: bash /opt/vc/bin/vcgencmd?
No need for the bash. vcgencmd is the program in /opt/vc/bin
I have the same issue. I use a RaspberryPi 4 Model B 8Gb and I run the latest 64bit beta version of RaspberryPiOS Lite.
Already figured it out ^^. If you’re running the 64 bit version of RaspberryPi OS you need to replace the
/opt/vc
part of the command with just/usr/
. Hope this helps.Nice tutorial, thanks!
i only really want to find the current temp to test its working! I added a fan, then noticed in rpi-config gui you can set the fan to a gpio pin. maybe add that little detail to the tutorial?
liking the alias file 🙂 made a few of my own too
IT WORKED!!
I got the temp out with no error after creating the batch file!
Also thanks for the tutorial on installing Open Media Vault!
I did it with confidence and fast. I felt like a pro as I’m remembering many commands to do different things!
Anyways thanks again crew!
Keep the goodwork going please and I want you guys to know I been coming here everyday since last week trying everything tgat I can so with my Rasp PI
Thanks, Michael C.
First I wanted to say thank you for you sharing your knowledge!
I have bookedmarked your site from the day I found it on duckduckgo.com and I became imediately a loyal visitor when your tutorials helped me fast and easy when ever I have a problem or want to try out your other tutorials to keep learning more about my raspberry pi questions, problems and solutions.
Thank You!
But I have a question about this tutorial, I receive a error on the terminal app after executing this command on the terminal.
“/opt/vc/bin/vcgencmd measure_temp | awk -F “[=\’]” ‘{print($2 * 1.8)+32}'”
Output error that I recieve is…
awk: warning: escape sequence `\” treated as plain `”
106.34
I can see the temperature but I just wanted to ask you if its a error what do you suggest!
Michael
The error message come from awk. I think that the characters surrounding the = are an attempt to prevent it’s being treated as a special character. They’re not needed here. Just change “[=\’]” to = and you’ll be OK.
/opt/vc/bin/vcgencmd measure_temp | awk -F = ‘{print($2 * 1.8)+32}’ will print the temp in Fahrenheit without the error message.
Michael,
This may help:
/opt/vc/bin/vcgencmd measure_temp | awk -F[=\’] ‘{print”temp=”$2″ C “($2 * 1.8)+32″ F”}’
The ‘ for the separators (after -F) has to be escaped, but it shouldn’t have to be in quotes.
If you edit .bashrc (nano ~/.bashrc) you could add these lines:
(This only works logged into root)
alias temp=”_tempf”
_tempf() {
/opt/vc/bin/vcgencmd measure_temp | awk -F[=\’] ‘{print”temp=”$2″ C “($2 * 1.8)+32″ F”}’
}
Ctrl-X and Y to save, then run bashrc (. ~/.bashrc) to update.
the temp command should give:
temp=41.8 C 107.24 F
Hope this helps
LaDell