Introduction: Raspberry Pi CPU Temperature Indicator

Previously I had introduced simple raspberry pi (Hereinafter as RPI) operational status indicator circuit.

This time, I’ll explain some more useful indicator circuit for RPI running as headless (without monitor) manner.

The circuit above shows CPU temperature into 4 different levels such as:

- Green LED turned on when CPU temperature is within 30~39 degree

- Yellow LED indicates temperature is increased in range of 40 to 45 degree

- 3rd Red LED shows CPU become a little bit hot by reaching 46 ~ 49 degree

- Another Red LED will blink when temperature is exceeding more than 50 degree

The above CPU temperature ranges are my personal design concept (Other temperature ranges can be configured by changing test conditions of python program which control this circuit).

By using this circuit, you are not necessarily executing “vcgencmd measure_temp” command frequently on console terminal.

This circuit shall inform current CPU temperature continuously and conveniently.

Step 1: Preparing Schematics

Although you can control 4 LEDs directly by utilizing only python codes, control logics of the program will load RPI and as a result, CPU temperature will be increased more because you should running a little bit complex python code continuously.

Therefore, I’m minimizing python code complexity as simple as possible and off-loading LED control logic to external hardware circuit.

The CPU temperature indicator (Hereinafter INICATOR) circuit consists with the following major parts.

- Two opto-couplers are connected to RPI GPIO pins to get temperature level data such as 00->LOW, 01->Medium, 10->High, 11->Need cooling.

- 74LS139 (or 74HC139, 2-to-4 decoder and de-multiplexer) control outputs (Y0, Y1, Y2, Y3) according to the inputs (A, B)

- When temperature is within 30 ~ 39 degree, python code output 00 to GPIO pins. Therefore, 74LS139 get input data 00 (A->0, B->0)

- As 00 is entered, Y0 output becomes LOW. (Please refer truth table of 74LS139)

- When Y0 output become LOW, it activating 2N3906 PNP transistor and as a result, Green LED is turned on

- Likewise, Y1 (01 -> CPU temperature medium) shall turn on Yellow LED and so on

- When Y3 becomes LOW, DB140 activating NE555 LED blinking circuit (this is common 555 IC based LED blinker) which is load of BD140 PNP transistor

The most important component of this circuit is 74LS139 which decoding 2 digits input into 4 different single output as shown in the truth table below.


Input | Output


G (Enable) | B | A | Y0 | Y1 | Y2 | Y3 |


H | X | X | H | H | H | H |

L | L | L | L | H | H | H |

L | L | H | H | L | H | H |

L | H | L | H | H | L | H |

L | H | H | H | H | H | L |

As 74LS139 output becomes LOW, PNP type transistor can make overall circuit simple as PNP transistor is turned on when base terminal becomes LOW. (I’ll show NPN version at the end of this story)

As 100K potentiometer is included to the NE555 LED blinker circuit, Red LED ON/OFF time can be adjusted freely according to the needs.

Step 2: Making PCB Drawing

As operating scheme of the INDICATOR is explained, let’s start to make the circuit.

Before soldering something on universal board, preparing the PCB drawing shown above is helpful to minimize any mistakes.

The drawing is made by using power-point to locate each part on the universal board and making wiring patterns among parts with wires.

As IC and transistor pin-out images are co-located along with PCB wiring pattern, soldering can be performed using this drawing.

Step 3: Soldering

Although original PCB drawing is made not using single wires to connect components on PCB, I’m soldering somewhat differently.

By using single conductor of wires (not tin wire), I’m trying to reduce universal PCB size which containing INDICATOR circuit.

But as you can see on the soldering side of PCB, I’m using tin wire also according to the patterns depicted in the PCB drawing.

When each component is connected according to the original design of PCB drawing, soldering completed PCB board including INDICATOR circuit will operate correctly.

Step 4: Testing Preparation

Before to RPI connection, the finished circuit requires testing.

As any soldering mistakes can exists, DC power supplier is used for preventing damages when shorts or wrong wiring is occurred.

For testing of INDICATOR, two additional power supply cables are connected to circuit’s 5V power supply connector.

Step 5: Testing (CPU Temperature Is Medium Level)

When no 5V input is applied then 74LS139 decoding input and activating output Y0 as LOW (Green LED turned on).

But 5V applied to input A, output Y1 of 74LS139 activating (LOW).

Therefore, Yellow LED is turn on as shown in the picture above.

Step 6: Testing (CPU Need Cooling Level)

When 5V applied both inputs (A and B) of 74LS139, 4th Red LED is blinking.

Blinking rate can be changed by adjusting 100K VR as shown in the picture above.

When testing is completed, two Molex 3 pin female cables can be removed.

Step 7: Power Supply to INDICATOR Circuit

For powering INDICATOR circuit, I’m using common hand-phone charger which output 5V and USB type-B adaptor as shown in the picture above.

To avoid problem with RPI by connecting 3.3V GPIO and 5V powered INDICATOR circuit, signal interface and power supply are totally isolated each other.

Step 8: RPI Wiring

For interfacing INDICATOR circuit with RPI, two GPIO pins should be dedicated along with two ground pins.

There is no specific requirement for choosing GPIO pins.

You can use any GPIO pins for connecting INDICATOR.

But wired pins should be designated as inputs to 74LS139 (e.g. A, B) in python program.

Step 9: Python Program

As circuit is completed, making python program is required to use INDICATOR function.

Please refer flow chart above for more detail about program logic.


#-*- coding:utf-8 -*-

import subprocess, signal, sys

import time, re

import RPi.GPIO as g

A = 12

B = 16


g.setup(A, g.OUT)

g.setup(B, g.OUT)


def signal_handler(sig, frame):

print('You pressed Ctrl+C!')

g.output(A, False)

g.output(B, False)



signal.signal(signal.SIGINT, signal_handler)


while True:

f = open('/home/pi/My_project/CPU_temperature_log.txt', 'a+')

temp_str = subprocess.check_output('/opt/vc/bin/vcgencmd measure_temp', shell=True)

temp_str = temp_str.decode(encoding = 'UTF-8', errors = 'strict')

CPU_temp = re.findall("\d+\.\d+", temp_str)

# extracting current CPU temperature

current_temp = float(CPU_temp[0])

if current_temp > 30 and current_temp < 40:

# temperature low A=0, B=0




elif current_temp >= 40 and current_temp < 45:

# temperature medium A=0, B=1




elif current_temp >= 45 and current_temp < 50:

# temperature high A=1, B=0




elif current_temp >= 50:

# CPU cooling is required high A=1, B=1




current_time = time.time()

formated_time = time.strftime("%H:%M:%S", time.gmtime(current_time))




The main function of python program is like below.

- Firstly setting GPIO 12, 16 as output port

- Defining Ctrl+C interrupt handler for closing log file and turn off GPIO 12, 16

- When enter to infinite loop, open log file as append mode

- Read CPU temperature by executing “/opt/vc/bin/vcgencmd measure_temp” command

- When temperature is in range 30 ~ 39 then output 00 to turn on Green LED

- When temperature is in range 40 ~ 44 then output 01 to turn on Yellow LED

- When temperature is in range 45 ~ 49 then output 10 to turn on Red LED

- When temperature is more than 50 then output 11 to make Red LED blinking

- Write time stamp and temperature data to log file

Step 10: INDICATOR Operation

When everything is OK, you can see each LED is turn on or blinking according to the CPU temperature.

You don’t need to enter shell command to check current temperature.

After collecting data in the log file and rendering text data into graph by using Excel, result is shown the picture above.

When applying high loads (Running two Midori Browsers and playing Youtube video), CPU temperature is spike upto 57.9C.

Step 11: Alternative Making (Using NPN Transistor) and Further Development

This is previous INDICATOR project example utilizing NPN transistors (2N3904 and BD139).

As you can see one more IC (74HC04, Quad invertors) is necessary to drive NPN transistor as HIGH level voltage should be applied to base of NPN to turn on transistor.

As a summary, using NPN transistor add unnecessary complexity to make INDICATOR circuit.

For the further development of this project, I’ll add cooling fan as shown in the picture above for making INDICATOR circuit more useful.