Example Code for Arduino-PWM Speed Control
Last revision 2026/01/06
This article offers a detailed guide on Arduino PWM speed control, complete with hardware setup, software preparation, wiring diagrams, and example code to help you execute your project efficiently.
Hardware Preparation
- DFR0332 Gravity: DC Fan Module (SKU:DFR0332 x 1)
- DFRduino UNO R3 with IO Expansion Shield and USB Cable A-B (SKU:DFR0216-2 x 1)
Software Preparation
- Development Tool: Arduino IDE (version unspecified). Download link: Arduino IDE
Wiring Diagram

Sample Code
//Arduino Sample Code for Fan Module
//www.DFRobot.com
//Version 1.0
#define Fan 3 //define driver pins
void setup()
{
pinMode(Fan,OUTPUT);
Serial.begin(9600); //Baudrate: 9600
}
void loop()
{
int value;
for(value = 0 ; value <= 255; value+=5)
{
analogWrite(Fan, value); //PWM
Serial.println(value);
delay(30);
}
}
Result
The fan speed gradually becomes faster
Was this article helpful?
