This project is to demonstrate how to use a PWM pin to adjust the speed of a DC fan. The modulated signal from the Arduino PWM pin we use to activate a MOSFET, which then from this MOSFET gives power to the fan corresponds to the signal intensity of the PWM pin.

to adjust the speed digitally can see on https://arduinoproyek.wordpress.com/2018/10/15/speed-control-dc-fan/

DC fan speed

#define fadePin 3 // PWM pin

int pot = A2;

int t2 = 0;

void setup(){


pinMode(fadePin, OUTPUT);

pinMode(pot, INPUT);


void loop(){

//calculate sin of angle as number between 0 and 255

float t2= analogRead(pot);

int sinOut = t2*255/1023;


analogWrite(fadePin, sinOut);


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s