Arduino with Mosfet !!! need help to control duty cycle.

Hello im a mechanical engineer and im working on controlling an automotive fan using arduino , mosfet and motor driver .

I know that MOSFET can be used as a switch. When sufficient Vgs is applied, MOSFET will turn on and so the load (fan).

This is my understanding of this circuit, please correct me if I’m wrong or missed anything?

5V PWM is a digital signal and by adjusting the duty cycle, I can control the average value.

For 100% duty cycle Average voltage = 5V For 50% duty cycle Average voltage = 2.5V For 0% duty cycle Average voltage = 0V

So in case if i want to control a duty cycle at 20% the voltage will be around 1 from the micro controller. So is there any Mosfet operate betwwen 1-5 V?

Note: i only need the mosfet to control the signal that goes to the driver .. Please recommend me a Mosfet .

So in case if i want to control a duty cycle at 20% the voltage will be around 1 from the micro controller. So is there any Mosfet operate betwwen 1-5 V?

The “average” isn’t important to the MOSFET which is switching between fully-on and fully-off.

The average voltage (and current) does relate directly to the energy sent to the motor to control the speed because the motor won’t start/stop instantly.

A “logic level” MOSFET can be controlled by 5V. You’ll need to find one that can handle the current (Amps) of the motor, and you may need a heatsink.

[u]Here[/u] is an example MOSFET driver circuit.

@DVDdoug
Thanks for your replay. im not controlling the motor directly with the mosfet but im using the mofset to control the signal wire that control the motor driver . to be more clear im using “ground switching” i will attach a picture for the schematic which may help more
for example
analogWrite( pin9, 51);
will set the pin nine at duty cycle of 10% which equal to 1volt but the mosfet only operates at min 2volts
so how i can pass this problem?

Why can't you control the motor driver signal directly from a GPIO pin?

root-shell: Hello im a mechanical engineer and im working on controlling an automotive fan using arduino , mosfet and motor driver .

I know that MOSFET can be used as a switch. When sufficient Vgs is applied, MOSFET will turn on and so the load (fan).

This is my understanding of this circuit, please correct me if I’m wrong or missed anything?

5V PWM is a digital signal and by adjusting the duty cycle, I can control the average value.

For 100% duty cycle Average voltage = 5V For 50% duty cycle Average voltage = 2.5V For 0% duty cycle Average voltage = 0V

So in case if i want to control a duty cycle at 20% the voltage will be around 1 from the micro controller. So is there any Mosfet operate betwwen 1-5 V?

Note: i only need the mosfet to control the signal that goes to the driver .. Please recommend me a Mosfet .

You are not understanding PWM correctly.

PWM outputs turn on and off at a particular rate. However, the ON and OFF times are variable. Here's an example:

Imagine the PWM is running at 1000 Hz (that is, 1 millisecond or 1000 microseconds PER CYCLE).

Now imagine an imaginary 5 volt light bulb is connected to the PWM pin (forget the driver transistor or MOSFET for now).

If the pin stayed high, the light bulb would be full brilliance. But, to control is we use PWM...

Imagine the PWM pin is ON for 250 microseconds and OFF for 750 microseconds. The total cycle time is still 1000 Hz, but the pin in on only 25% of the time. Therefore, the bulb will be at 25% brightness (because the filament cannot possibly follow the on/off cycles... it "thermally integrates" the PWM input).

Now, let's set the PWM to 800 microseconds ON and 200 microseconds OFF. Again, the cycle time is 1000 Hz, but the average (integrated) power to the bulb is now 80 percent and it's much brighter.

You can go anywhere between 0/1000 (full off) to 1000/0 (full on).

Do you see the beauty of this? In the real world, you will be using a transistor or MOSFET to control a high power load.

If you did it purely analog, (say, 50 percent power), the load would get 50% and the MOSFET would burn off, as wasted heat, the other 50%, requiring a larger MOSFET (more $$$) and a big heatsink (more $$$ and more board space wasted).

But with PWM, the switching device (MOSFET, etc..) is either fully ON (virtually no voltage drop across it = minimal power lost) or it's fully OFF (again, open circuit draws no current = no power loss).

SO, with a relatively small MOSFET you can PWM control a large load and waste almost no power (i.e. the MOSFET stays cool).

Other devices can also be controlled the same way. A DC motor mechanically integrates the PWM pulses and spins smoothly.

An LED will follow the PWM and actually be blinking, but at 1000 Hz your own eyes cannot see the flicker and you VISUALLY integrate the average brightness value.

Lastly, there is an optimal PWM frequency for each use. A very high PWM frequency could, for example, be very inefficient driving a DC PM motor due to the high frequency being "lost" in the motor inductance.

A very low frequency might make an LED visibly blink, or a DC motor actually "cog" (speed up and slow down as it follows the slow on/off cycles).

A very high frequency can also waste energy in driving the gate of the MOSFET, so you see the PWM frequency is a compromise between two conflicting goals, and you have to choose the right frequency for each application.

Hope this all didn't overwhelm you... if you have any questions let me know.

@MarkDerbyshire Motor driver requires 12 volt to operate

@Krupski Thank you very much for elaborating for me. I understand that you meant for example :

digitalWrite(pin9,HIGH); delay(200); digitalWrite(pin9,LOW); delay(800);

This will give a 20%duty cycle and the voltage at pin9 will be 5 volts when it is high and zero when it s low. Lets say i want to use analog commands instead of digital one:

analogWrite(pin9, 51);

This will give a duty cycle of 20% and the voltage at the pin9 will be around 1 volt? am i right ? Then if i want to operate the MOSFET It won't work because the voltage is below 2.1 which is the minimum operating volt

Please correct me if im wrong im newbi.

The voltage will be 5V for 20% of the time and 0V for the remaining 80% of the time.

@sterretje Is that in the analog or digital command ?

root-shell: This will give a duty cycle of 20%

and the voltage at the pin9 will be around 1 volt? am i right ?

Only the first part is right. Voltage on the pin is either 0volt or 5volt. If you measure it with a DMM you might see 1volt, because the meter is averaging.

If you turn a heater on for 10 minutes, and off for 10 minutes, then it will be on half of the time. But it won't be half on all the time. Your room will get half the heat though.

I would say analogWrite is a PWM command. Leo..

root-shell:
@sterretje
Is that in the analog or digital command ?

That’s for analogWrite and also if you implement it using digitalWrites and delays as shown in an earlier reply.

root-shell:
@Krupski
Thank you very much for elaborating for me. I understand that you meant for example :

#1
digitalWrite(pin9,HIGH);
delay(200);
digitalWrite(pin9,LOW);
delay(800);

This will give a 20%duty cycle and the voltage at pin9 will be 5 volts when it is high and zero when it s low.

#2
Lets say i want to use analog commands instead of digital one:

analogWrite(pin9, 51);

This will give a duty cycle of 20% and the voltage at the pin9 will be around 1 volt? am i right ?
Then if i want to operate the MOSFET It won’t work because the voltage is below 2.1 which is the minimum operating volt

Please correct me if im wrong im newbi.

#1 - Completely correct. One small note though… 200 milliseconds plus 800 milliseconds is one second, so although you do indeed have a 20% duty cycle, it blinks on and off once a second. Way too slow for a motor or an LED, If you changed it to something like delay(2)+delay(8) you would have a more useful PWM.

Note though that toggling the pin on and off with a delay in between consumes 100% of the processor capacity and your code can do nothing else, whereas the Arduino HARDWARE PWM is a built in function that runs independently off the system clock. So, you could set the hardware PWM to 20% and it would stay there and put out 20% duty cycle pulses, consuming zero processor time (so your PROGRAM can do other things).

#2 - Wrong. 51 out of 255 is 20 percent, so the “analog” output would actually be a 20% duty cycle on/off pulse train consisting of 0 volts or 5 volts. The integrated AVERAGE is 1 volt, but the output (which would probably be driving a MOSFET) is still 0 volts or 5 volts. See the image below for clarification:

(edit to add): Notice that each “cycle” takes exactly the same amount of time… only the on to off RATIO changes.

(click image for full size)
pwm-explain.jpg

Wawa: Only the first part is right. Voltage on the pin is either 0volt or 5volt. If you measure it with a DMM you might see 1volt, because the meter is averaging.

If you turn a heater on for 10 minutes, and off for 10 minutes, then it will be on half of the time. But it won't be half on all the time. Your room will get half the heat though.

I would say analogWrite is a PWM command. Leo..

Arduino analogWrite() does indeed control the AVR PWM circuitry.

In your OP you mentioned a motor driver, can you post a link to that driver? I don't think you need an intermediate MOSFET.

AnalogWrite() has always really been AnalogWrong().

Its is a PWM pin option... that misleads everyone into thinking that it is the inverse of AnalogRead(), which it is not.

krupski: Arduino analogWrite() does indeed control the AVR PWM circuitry.

so that how to build pwm signal with arduino just with code analogWrite in the pwm pin? am i wrong?