Controlling 24V Fans with Arduino Nano

Hello everyone,

I need to control four 24V 0.18A (each) fans for a 3D printer with Arduino (I am using a Nano in this case).
So I thought the best would be to use a mosfet, but I only had an IRF520.

I am using a very basic circuit: I have a 24V 3.5A transformer powering arduino nano through a MP1584EN step down converter (I bring the power down to 5V), a rotary encoder is used to set the PWM value on the mosfet gate which, in turn, control the power of the fans.

From the transformer another line bring the positive directly to the fans (which are all in parallel) while the negative is connected to the source of the mosfet.

For PWM I use only 5 values (20/40/60/80/100 power), 51, 102, 153, 204, 255.

Everything works fine but the problem is that the fans, even at what should be full speed (PWM 255), run very slow.
With a multimeter (in series with the fans) I've measured the Amps and, even when 4 fans are running, I have a max consumption of 0.018 Amps (which is what just one fan is rated).
If I connect only one fan it runs faster, at 100% power it burns 0.018 Amps again.

It seems like that the MOSFET only output 0.018A?

I have also measure the Volts and they range from somewhere around 20/21 V at 20% power, till 24V when at full power.

To connect the fans to the transformer I use a 1.5mt long 22AWG cables.
I tried to use shorter ones but the result is the same.

I am really a bit lost, any suggestion would be great!

Thank you very much!

Alessandro

Attache a wiring diagram as well as the code and please use code tags. Do You use one rotary encoder per fan? Why use rotary encoder at all? What's the idea?

Ale_V:
From the transformer another line bring the positive directly to the fans (which are all in parallel) while the negative is connected to the source of the mosfet.
Alessandro

transformer? is this 24V AC?

Thanks all,

I will post the code tomorrow, first thing in the morning.

The transformer is AC/DC 24V 3.5A.

I thought of using the rotary encoder so to be able to change the power of the fans: the rotary encoder changes a variable which is value of the pwm for the gate of the mosfet.
Any suggestion about how to vary the power if not with a rotary encoder?

Thanks a lot guys!

Alessandro

Could you post a picture of your transformer? I’m not sure if we have a mix up in terminology. Transformers only couple AC.

Hello,

sorry for the late reply.

This is the transformer I am talking about.

I've made a scheme with Fritzing, just keep in mind that the fans are 4, put in parallel. For schematic reasons I put just one...
The 5 LEDs are just to have a visual reference of the output power: every 20% more energy a new LED lights up.

And here is the code (is split in two part):

Main

// LIBRARIES
#include <Encoder_Polling_V2.h>

// METHODS DECLARATIONS
void encoder_read();

// ROTARY ENCODER INPUT PINS
const int pin_A = 4;  
const int pin_B = 5;

int fanspeed = 0;
byte led_A = A1;
byte led_B = A2;
byte led_C = A3;
byte led_D = A4;
byte led_E = A5;

#define gate 10

void setup() {
  Serial.begin(9600);
  
  pinMode (gate, OUTPUT);
  
  pinMode (led_A, OUTPUT);
  pinMode (led_B, OUTPUT);
  pinMode (led_C, OUTPUT);
  pinMode (led_D, OUTPUT);
  pinMode (led_E, OUTPUT);
    
  // ENCODER INITIALIZATION
  encoder_begin();  // Start the library
  attach_encoder(0, pin_A, pin_B);  // Attach an encoder to pins A and B

  // FANS START OFF
  digitalWrite (gate, LOW);
}


void loop() {
  encoder_read();
  analogWrite (gate, fanspeed*2.55);
  Serial.print("Corrected Fanspeed: "); Serial.println(fanspeed*2.55);  // To double check that the moltiplied values are correct
}

First Tab

void encoder_read() {
  int dir_0 = encoder_data(0);  // First encoder
  if(dir_0 != 0)  // Check for rotation
  {
    if(dir_0 == +1 && fanspeed < 100) fanspeed = (fanspeed + 20);
    if(dir_0 == -1 && fanspeed > 0) fanspeed = (fanspeed - 20);

     if(fanspeed == 0) {
      digitalWrite (led_A, LOW);
      digitalWrite (led_B, LOW);
      digitalWrite (led_C, LOW);
      digitalWrite (led_D, LOW);
      digitalWrite (led_E, LOW);    
     }
     if(fanspeed > 0 && fanspeed <= 20) {
      digitalWrite (led_A, HIGH);
      digitalWrite (led_B, LOW);
      digitalWrite (led_C, LOW);
      digitalWrite (led_D, LOW);
      digitalWrite (led_E, LOW);
    }
    if(fanspeed >= 30 && fanspeed <=40) {
      digitalWrite (led_A, HIGH);
      digitalWrite (led_B, HIGH);
      digitalWrite (led_C, LOW);
      digitalWrite (led_D, LOW);
      digitalWrite (led_E, LOW);
    }
    if(fanspeed >= 50 && fanspeed <= 60) {
      digitalWrite (led_A, HIGH);
      digitalWrite (led_B, HIGH);
      digitalWrite (led_C, HIGH);
      digitalWrite (led_D, LOW);
      digitalWrite (led_E, LOW);      
    }
    if(fanspeed >= 70 && fanspeed <= 80) {
      digitalWrite (led_A, HIGH);
      digitalWrite (led_B, HIGH);
      digitalWrite (led_C, HIGH);
      digitalWrite (led_D, HIGH);
      digitalWrite (led_E, LOW);      
    }
    if(fanspeed > 80) {
      digitalWrite (led_A, HIGH);
      digitalWrite (led_B, HIGH);
      digitalWrite (led_C, HIGH);
      digitalWrite (led_D, HIGH);
      digitalWrite (led_E, HIGH);      
    }
  }
}

Thank you very much for your help!

My very best,

Alessandro

Sorry,

I made a mistake in my first message:
fans are rated 0.18A but when I run them with Arduino they absorb 0.018A, basically exactly 1/10 of what is supposed to be.
(I will edit the first message).

If I run them directly from a 24V power source they sets correctly at 0.18A (I've taken measurements again to be sure).

Thanks,

Ale

Why not use a simple potentiometer to tell the fanspeed needed?

Yeah I know but I am more practical with rotary encoder and I had more...

You mean simply using a potentiometer without arduino?

No. Use the pot instead of the rotary encoder.
An Arduino handling the PWM will be handy.

But does it have any influence on all the rest apart from being more handy?
Because, apparently, the variable is correctly passed to the PWM from what I see.

Your transistor is not a "TTL level" device. The arduino can not fully turn it on at 5V on the gate. You need something like the IRLZ44. When looking at MOSFET devices, the datasheet needs to specify things in terms of Vgs=5V, not ones that have Vgs=10V or higher

Keep the rotary encoder if it is working, You can decode it etc..
It clearly looks like You use the wrong kind of transistor. Go for a so called "logic MOSFET".

Thank you guys,

I was close to figure it out I think...

It seems like it is almost impossible to find an IRLZ44 here, quickly, at the moment.
Any other suggestions for a specific MOSFET?

OR...could I drive the MOSFET I already have mounted if I place a step up converter (from 5V to 12V) in between Arduino PIN and the gate of the MOSFET?

Thank you very much!

My best,

Ale

Step up converter supplied from an Arduino output of 5 volt, 20 mA? I've never heard of that before. Get a logical MOSFET. They don't cost that much.

My problem is that I wouldn't know where to get them from quickly at the moment...
Any specific logical mosfet I could look for on Amazon.it?

Many many thanks!

Okey. No use for me to suggest MOSFETs not sold in Your area.
Make shure You get an N-channel logical MOSFET that manages both voltage and the need for current, with some margin.

Thanks a lot!

I tried to google I don’t know how many MOSFETs I found on italian amazon but in the datasheet I never find anywhere written “logical”.

Is there a way to spot them from the code? Like a letter or so? Just to narrow the research a bit...

Thank you very much!

Okey. The term "logical" is obviously not commonly used. The idea is that a gate voltage of 5 volt is enough to make the FET go at its maximum. I have forgotten the exact terminology to look for in the specs.
Make a search here in forum for "MOSFET gate voltage" and I'm sure You will find the magic Word.

They are commonly referred to as "logic level MOSTFETS"