Coder Social home page Coder Social logo

pwmfancontrol's Introduction

PWM Fan Control Service on Raspberry Pi

Overview

This project consists of a Python script and a systemd service unit file to control the speed of a 40mm 5V PWM fan on a Raspberry Pi. The fan speed is adjusted proportionally to the CPU temperature, ideal for setups like the Pi Desktop Case with an OLED Stats Display. The project is based on instructions and code by Michael Klements.

Files

  1. FanProportional.py - Python script to control the fan speed.
  2. systemd/pwmfancontrol.service - Systemd service unit file to run the Python script as a service.

FanProportional.py

This Python script reads the CPU temperature of the Raspberry Pi and adjusts the speed of a connected PWM fan accordingly. The fan speed is set between a minimum and maximum speed, corresponding to a defined range of CPU temperatures.

  • Dependencies: RPi.GPIO, time, subprocess
  • GPIO Mode: BCM
  • PWM Frequency: 100Hz
  • Temperature and Speed Range: Customize the minTemp, maxTemp, minSpeed, and maxSpeed variables as needed.

pwmfancontrol.service

This systemd service file is used to run FanProportional.py as a service on the Raspberry Pi, ensuring that it starts automatically on boot.

  • Service Type: simple
  • ExecStart: Path to the Python interpreter and the FanProportional.py script.
  • Restart Policy: The service will restart on failure.
  • User: root
  • Environment: PYTHONUNBUFFERED=1

Installation

  1. Place FanProportional.py in /opt/pwmfancontrol/.
  2. Place pwmfancontrol.service in /etc/systemd/system/.
  3. Make FanProportional.py executable: chmod +x /opt/pwmfancontrol/FanProportional.py.
  4. Reload systemd: sudo systemctl daemon-reload.
  5. Enable the service: sudo systemctl enable pwmfancontrol.service.
  6. Start the service: sudo systemctl start pwmfancontrol.service.

Usage

Once installed, the service will run automatically on boot. The fan speed will adjust based on the Raspberry Pi's CPU temperature.

Troubleshooting

  • Ensure the GPIO pin and PWM frequency in the Python script match your fan's specifications.
  • Check the status of the service with sudo systemctl status pwmfancontrol.service.

Credits

pwmfancontrol's People

Contributors

mklements avatar mrmstn avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.