Not able to generate different voltages from Arduino PWM & MOSFET

Hi, I have prepared a code and Circuit which was working fine on simulator, and giving different output voltages as per mentioned in code, but when made physical circuit with IRF 530 MOFET, it is giving constant 11.9VDC from drain as given additional by additional voltage source 12VDC.


#define pwm 3
void setup() 
{
  // put your setup code here, to run once:
  pinMode(pwm,OUTPUT);
   analogWrite(pwm,0);
  pinMode(13,OUTPUT);
  }

void loop() 
{
  //analogWrite(pwm,0);
  int i=0;
  float val[4]={63.5,136.5,185.5,250};
  for(i=0;i<5;i++)
  {
    analogWrite(pwm,0);
    digitalWrite(13,LOW);
    delay(2000);
    analogWrite(pwm,val[i]);
    digitalWrite(13,HIGH);
  delay(2000);
      }
  analogWrite(pwm,0.0);
}

So am i making any mistake please reply.
Thanks

That MOSFET is not logic level, so the 5V signal from the Uno cannot operate the MOSFET.

Also, analogWrite() does not produce a controllable voltage on Uno. Uno has no analog output pins, only PWM pins.

You can make the IRF530 work for you by adding an additional bipolar transistor and a few resistors.

Look for Q26 in Post #3 in This Thread.

AnalogWrite is expecting int data type.
Change float val[4]....
To int val[4].... and remove the decimals

Your circuit drawing is unreadable. Please supply a digital circuit diagram, at least of the MOSFET and load. I suspect that you missed to add a load.

1 Like

PWM can lower the average voltage to "simulate" analog and control the speed of a motor, dim an incandescent light, or make an LED appear dim.

It can also be low-pass filtered to get true-analog but that doesn't work very well with a high current load and you can sometimes end-up frying a MOSFET.


Please find attached drawing. I have not attached load to drain, currently i am just doing measurement by Voltmeter connected in between drain and Positive terminal of Battery.

Hi,
You need to configure your circuit like this, so you are measuring the output voltage.
A load resistor of 1K0 Ohms should be enough.


Your DMM, in DC Volts, will then measure the Average voltage, depending on the duty cycle of the PWM signal.

This will only give reliable results if the MOSFET is in this case a logic level type, any other may work but not as predictably.

Tom.. :grinning: :+1: :coffee: :australia:

You want about a 10K resistor Gate to Source and you want about a 220 Ohm resistor in your gate circuit (between Gate and PWM. You also as mentioned earlier need to be using a Logic Level MOSFET. What MOSFET are you using? The IDF 530 as drawn is not a logic level MOSFET. Read the data sheet.

Ron

Hi,
With @Ron_Blain additions;

Tom.. :grinning: :+1: :coffee: :australia:

1 Like

Thank You. :slight_smile:
Ron

Thank you.

It appears you are trying to make a D/A converter with an IRF530 and PWM. that would work at the low currents you apparently are trying to use. The MOSFET will not be close to being fully enhanced so not much current will be available. The duty cycle will control the voltage but you also need some capacitance to maintain the voltage when the MOSFET is off. Simply add a capacitor across your volt meter. What you are actually adding is a low pass filter. The circuit may sort of work as shown but it is dependent on the voltmeters capacitance and response. Put a scope across it and see what you really have.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.