Introduction: Air Purifiers - Arduino: Speed Control a 4pin Fan

I decided to make my own Air Purifiers.

The project is a basic idea, what can be done with hand tools and as cheap as possible. This is a single-fan filter, in the stores the prices of these devices are very high. I looked at several projects until I make my idea. I decided to buy a filter, not to make a filter (maybe I will make a filter in the next version). I'm using a P1 HEPA system filter. For the fan I use - Arctic 120mm PWM. I decided to do a control with NodeMCU - Arduino. My idea was to make an hourly schedule, when to blow strong and weak. I also added a temperature sensor, as there were free pins on the board. I am also waiting for a Dust Sensor PPD42NJ to see if there is a result of everything I did. The biggest problem is the management of the PWM FAN. It took me a long time to make it work and and also a long time to make it work hard.

Materials used:
Prices are approximate and by memory.

Step 1:

I made a wooden box of wooden profiles. It seemed to me easy and beautiful.

Step 2:

In the end, it was not very accurate. I did it on the kitchen counter. I am not very good with the saw.

Step 3:

I also put paddles on it to take the vibrations and not scratch the furniture.

Step 4: Way of Connection

Step 5: Arduin Code

This is the Arduin code

new code

What I understood based on my practices and on of many attempts

  • The NodeMCU and the fan must have a common GND.
  • I can not achieve the maximum fan speed.
  • The system operates unstable without a 560R resistor. I am not sure whether it is OK with other values.


int fanPulse = D3;

int fanControl = D2;

unsigned long pulseDuration;

int p = 0;

void setup() {


pinMode(fanPulse, INPUT);


pinMode(fanControl, OUTPUT); }

void readPulse() {

pulseDuration = pulseIn(fanPulse, LOW);

double frequency = 1000000/pulseDuration;

Serial.print("pulse duration:");


Serial.print("time for full rev. (microsec.):");


Serial.print("freq. (Hz):");





void loop() { analogWrite(fanControl,1200);







Step 6: ​Sources