back to top
Saturday, December 7, 2024
spot_img

Raspberry Pi Automatic Fans Using L298n PWM

Share This Post

Welcome, We all know Raspberry Pi SBC Likes to get hot, and if your ambient temperature gets above 40 Degrees Celsius, A Pi will throttle down even at moderate loads. While the internet is filled with Cases, Heatsinks and Fans, we decided we need to combine all these things in order to get optimal performance from Raspberry Pi. Welcome to our guide of Raspberry Pi Automatic Fans Using L289N PWM.

Project Requisite for Raspberry Pi Automatic Fans Using L289N PWM.:

  • Heatsinks
  • Acrylic Case with Cooling Fan.
  • A 8×8 12v PC Cooling Fan.
  • L298N PWM Controller. Link
  • 12v 2A Power Supply.
  • Raspberry Pi 4.

Getting Started: Assembling the Case & Heatsinks:
Many raspberry cases support a mini fan that can be connected to the GPIO of Raspberry Pi. Like this one below:

Raspberry PI GPIO FAN
The well known Raspberry Pi Armour Case with GPIO Fan

We don’t recommend the above setup, I.E the case fan connected to the GPIO, as drawing power for the fan heats up the Raspberry Pi. This also results in fan being always on, which is unwarranted for its sound and wear-tear of brushed DC Motors.

While we assemble the case, lets also place heatsinks on our Pi. The hottest chips are the CPU, the Wi-Fi and the USB chip. So, the two ones with silver covers, and the largest of the 3 chips near the USB connectors.

This moves us one step closer to Raspberry Pi Automatic Fans Using L298n PWM module.

Attaching a Bottom Fan:

DC Fan

While the little top fan is nice and cute, We will be placing a PC radiator fan below our pi. You can get these 80x80mm DC 12V Cooling Fan for PC Case for as low as $5 (200 Rupees).
We will also have to mod our case, In our case, we cut the bottom acrylic plate along its corner with a hot knife, this allows maximum airflow to the bottom side of Raspberry Pi.

 

Setting up the L298n PWM Motor Driver with Raspberry Pi :

This L298N is a motor driver module for driving DC and Stepper Motors with Raspberry Pi. This module consists of an L298 motor driver IC and a 78M05 5V regulator. As L298N Module can control up to 4 DC motors (2 Motors per output), or 2 DC motors with directional and speed control.

Pin Name Description
IN1 & IN2 Motor A input pins. Used to control the spinning direction of Motor A
IN3 & IN4 Motor B input pins. Used to control the spinning direction of Motor B
ENA Enables PWM signal for Motor A
ENB Enables PWM signal for Motor B
OUT1 & OUT2 Output pins of Motor A
OUT3 & OUT4 Output pins of Motor B
12V 12V input from DC power Source
5V Supplies power for the switching logic circuitry inside L298N IC
GND Ground pin

Insert your Case fan inputs to IN1 on the L298N, and the bottom fans input at IN2. Don’t worry about the polarity of the wires since we can tweak it by code later. With the interfacing of L298N with the Raspberry Pi and both fans complete, We move onto mounting all these together in a nice package.

Mounting the Package:

We hope our Raspberry Pi Auto-Fans Using L298n PWM setup provides you with reference:

Raspberry Pi Automatic Fans Using L289N PWM.

The Top fan is mounted using screws, but we have changed the default motor supplied with the case with a custom motor from a DVD-Writer. This lets us spin the top fan with a little extra Oomph.

Raspberry Pi Automatic Fans Using L289N PWM 02 Image

Bottom Fan is stuck to the lower side of our Raspberry Pi Case using Super Glue. While this method makes removing of the case a bit difficult, the results are worth it.
We have used 3M Double Sided Adhesive Tape to stick the L298N PWM to the side of our Raspberry Pi. This makes all the wiring less cluttered and offers a nice mount to the module.

Python Script for L298n And Raspberry Pi Interfacing:

There are different ways in which you can set the fans to start. You can read the board temperature in Python using gpiozero package or you can set the fans to start at an interval for a period of time. We have set our fans to turn on for every 2 Minutes, every 5 Minutes using this script:

#!/usr/bin/python
import RPi.GPIO as gpio
import time
def init():
gpio.setmode(gpio.BCM)
gpio.setup(17, gpio.OUT)
gpio.setup(22, gpio.OUT)
gpio.setup(23, gpio.OUT)
gpio.setup(24, gpio.OUT)
def run(tf):
init()
gpio.output(17, False)
gpio.output(22, True)
gpio.output(23, False)
gpio.output(24, True)
time.sleep(tf)
gpio.cleanup()
print ("run")
run(120)

Save this as fan.py in your home folder. We will now add this program to our crontab, which would execute it every 5 Minutes. Open crontab by typing sudo crontab -e in the terminal, and adding these lines at the bottom of the file:

*/5 * * * * /home/pi/fan.py

Result of Raspberry Pi Automatic Fans Using L298n PWM :

In our case, Our Raspberry Pi runs a motioneye server, a SMB Server, some python scripts, and occasionally some media on VLC/Kodi. Our Temperature before average on Room Temperature 40 °C:

  • Idle: 60°C
  • Under Load: 80°C (Before Throttling)

Using this automatic fan setup for Raspberry Pi, we managed to get these temperatures:

  • Idle: 48°C
  • Under Load: 75°C (No Throttling)

Lower temperature increases the speed of your Raspberry Pi as well as provide a boost to board life. You can also overclock harder if your cooling setup if nice enough, like using the Active Cooler for the new Raspberry Pi 5 models.

Pilāni
clear sky
24.2 ° C
24.2 °
24.2 °
14 %
2.7kmh
0 %
Sat
22 °
Sun
25 °
Mon
21 °
Tue
22 °
Wed
22 °

Related Posts

Using Seeed Studio mmWave Module with ESPHome

In the ever-expanding universe of smart technology, the fusion...

MotionEye on Raspberry Pi: Proper Surveillance Software?

Welcome to another Raspberry Pi Post, this time we...

DIY Home Automation: ESP Home & Home Assistant

ESPHome is a powerful tool that simplifies the process...

Raspberry Pi Zero Explained: Comparing the Zero Family

The Raspberry Pi Zero series, known for its compact...

Aliens Guide to Earth’s Solar System

Position 00 - The Sun. Position: #0. The gravitational...

10 Best Gaming Mouse in India for Every Budget

Recently, my trusted old Logitech G602 gave out on...
- Advertisement -spot_img