Smart Control of Raspberry Pi Fan Using Python & ThingSpeak

A Python script monitors CPU temperature and controls the fan using on-off control with temperature hysteresis.

Brief overview

By default, the fan is directly connected to the GPIO – this implies its constant operation. Despite the relative quiet operation of the fan, its continuous operation is not an effective use of an active cooling system. At the same time, the constant operation of a fan can just be annoying. Also, if Raspberry Pi is turned off, the fan will still work if the power is connected.

This article will show how, using simple and not complicated manipulations, turn an existing cooling system into a smart one, which will only be turned on when the processor really needs it. The fan would be turned on only when there is heavy usage, thus reducing fan power consumption and noise. Also extending fan life by keeping it off when not needed.

What You Will Learn

  • How to implement a Python script to control a fan based on the current temperature of Raspberry CPU using On-Off control with temperature hysteresis.
  • How to transport data from your RaspberryPi to Things Speak Cloud.

Items for Getting Started

The components you will be required for this project are as follows

Building the circuit

The circuit is pretty simple. The power to the fan is cut off using NPN transistor. In this configuration, the transistor is acting as a low-side switch. Resistor is only required to limit the current through GPIO. The Raspberry Pi’s GPIO has a maximum current output of 16mA. I used 330 ohms which gives us a base current of about (5-0.7)/330 = 13mA. I selected a NPN transistor S8050, so switching a 400mA load from both fans is no problem.

Perform connections as shown in the following schematic diagram above.

Log CPU temperature with ThingSpeak

ThingSpeak is a platform for projects based on the Internet of Things concept. This platform allows you to build applications based on data collected from sensors. The main features of ThingSpeak include: real-time data collection, data processing and visualization. ThingSpeak API not only allows you to send, store and access data, but also provides various statistical methods for processing them.

ThingSpeak can integrate popular devices and services such as:

  • Arduino
  • Raspberry pi
  • ioBridge /
  • Electric imp
  • Mobile and Web applications
  • Social networks
  • Data Analysis in MATLAB

Before we start, you need an account at ThingSpeak.

  • Go to the following link and sign up to ThingSpeak.
  • After your account activation, sign in.
  • Go to Channels -> My Channels

Source: Smart Control of Raspberry Pi Fan Using Python & ThingSpeak

About The Author

Muhammad Bilal

I am highly skilled and motivated individual with a Master's degree in Computer Science. I have extensive experience in technical writing and a deep understanding of SEO practices.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top