Example Code for Raspberry Pi – 130 DC Motor Fan
Last revision 2026/01/20
This article provides a detailed guide on how to control a 130 DC Motor Fan with a Raspberry Pi using Python and PWM pulse width modulation for speed adjustment, suitable for small DIY projects.
Introduction
This module is really interesting. It can be easily driven by Arduino without an additional motor driver board. You can also use the PWM pulse width to adjust its speed, which is suitable for light applications or small DIY. Simple, but useful.

Wiring Diagram
-
Power the Raspberry Pi on and install the Raspberry Pi expansion board correctly
-
Connect the fan to PWM port 0 on the expansion board, and the analog rotation sensor to analog port 0

Sample Code
-
Install Python dependency libraries and git, and you need to get your Raspberry Pi connect to internet for this step(skip if installed). In the terminal, type the following instructions and press ‘Enter’
sudo apt-get install build-essential python-dev python-smbus git -
Install the drive library and program. In the terminal, type the following instructions in order and press ‘Enter’
cd \~
git clone https://github.com/DFRobotdl/37\_Pcs\_Sensor.git
- Find 130_DC_Motor_Module.py in \37_Pcs_Sensor\7_130_DC_Motor_Module folder, open it with Thonny Pyth IDE and run it, the fan speed can be adjusted through the rotation sensor.


Was this article helpful?
