Can PWM pins (Any) be used to give DC voltages in steps?


I have an Arduino Uno based board with A0-A5 pins.

I would like to drive it using the analogWrite() command.

My experience of measuring the output as I change the value from 0 - 255, is that it doesn’t read correctly on a digitech (True RMS) MM. I get nothing until around 180 then almost full voltage thereafter.

I have tried between A1, A2, A3 due to A0, A4 and A5 being in use for communications.
I haven’t seen any problems with the communications and I halted them whilst testing.

My question(s) would be:

  • Is there any known solutions to be able to give a range of DC voltages from 0 to 5V?
  • Have I misunderstood that the averaging of PWM for a certain value should give an average DC voltage.

I intent to use the pin, and whatever components are needed to drive a Vdc to 4-20mA convertor to supply a circuit I am developing.

Any help will be much appreciated.


  1. You can't read PWM with a digital multi meter.

  2. analogWrite does NOT output an analog value.


The short answer to your question is NO.

analogWrite() creates a pulsed signal on a PWM pin. The ON (5v) period varies from 0% to 100% of the pulse interval. If you look at the signal with an oscilloscope you will see that it ie either 5v or 0 v with nothing in between.

You can use external circuitry to average the voltage but I am not an expert on that.

Are you just thinking of using the Arduino to test the 4-20mA converter? Or will the 4-20mA output always be "controlled" by the Arduino - in which case maybe there is another way to use the Arduino.

Another thought is to use the Arduino to control a digital potentiometer to vary a voltage.


analogWrite( ) filtered thru 4.7K resistor and 10uF cap, i.e RC low pass filter, can make nice voltage levels.
Here is analogWrite from 0, 25, 50, 75, 100, 125, 150, 175, 200, 225, 250, 0 filtered and viewed with a 'scope.

Other easy solution could be a DAC, like the MCP4921. With this one you'll have 12 bit resolution instead of 8. And is relative cheap too.

Cheers, Ale.

is that it doesn't read correctly on a digitech (True RMS) MM. I get nothing until around 180 then almost full voltage thereafter.

Interesting... I would have expected that to work... Mathematically, PWM (or DC) DOES have an RMS value...

Do you have the meter set to AC or DC? (I would not expect true-RMS to work on the DC range.)

I don't have a PWM signal handy at the moment, but I tried reading a DC voltage with my Fluke "true RMS" meter set to AC, and it read ZERO! I pulled-out the manual and it says the "Volts AC" range is AC coupled, but the "millivolts AC" range is DC coupled.

I tried a lower DC voltage in the Millivolt AC range, it DOES read DC accurately which seems to indicate that it is reading true RMS on that lower range.

You don't say which meter. Is it true RMS reading? How about frequency response? Most true RMS reading DMMs are only meant to make accurate readings at 50 or 60Hz.

The pins A0 to A5 [u]cannot[/u] be used as analog outputs, they are only either analog inputs or digital inputs/outputs. AnalogWrite can only be used on the PWM pins (Pins 3,5,6,9,10 and 11 of a Uno) and will give a square wave output with a variable mark/space ratio. There is no true analog output on a Uno, as it doesn't have that capability, but there are ways around this, as explained above.

And you can always use blink without delay programming to make any output have a PWM kind of output, as I did here to make a 13-note piano/organ with a 1284P (with its 32 IO pins, using 13 inputs & 13 outputs)

DVDdoug: Mathematically, PWM (or DC) DOES have an RMS value...

Which can be determined easily with an antique analogue VM. A DVM instead typically simply scales the measured peak voltage down to the RMS value of a sinusoidal signal. Since a PWM signal is not sinusoidal, the readings of a DVM are almost bogus.

Hi there,

Thanks for all the replies.

I wasn't clear perhaps in the original post on what I wanted to achieve.

  • I need a means from the arduino to produce a steady DC voltage, for extended periods of time, that has a fine tolerance of around 50uV but could limit this upwards to 100uV if technically too difficult. It can go across the 0-5VDC range. I will be using a 12VDC input to the Arduino via the input socket to ensure the voltage is stable.

  • I thought that the PWM would average out over a cycle and give a lower mean value as %duty reduced but this I guess distracting from the point of how to create steady DC voltages.

Thanks: - CrossRoads - ilguargua

Both good suggestions (although, I don't want to create any analogue waveforms for this.) but I think the low pass filter would the easiest.

If anyone has time to read the below and could point me to or keywords to be able to integrate a circuit that is controllable from one pin of the arduino and the output is a 4-20mA signal that is a little more refined, I would be most grateful :)


Essentially what I'm building is an encoder for up to 45 positions in Binary, BCD, Grey and mA loop. The mA loop is the most challenging for me as it requires external circuitry that I'm not familiar.

I am looking to have a means of controlling a pin on the arduino (PWM preferably) that then allows a number of steps on a receiving device.

The receiving device is a -20 to 20+ mA board which is used to represent taps on a transformer, in a tap changer circuit. The device receiving is a controlling device that requires constant position supervision, i.e. I need to provide constant mA DC levels for long periods of time.

The device is typically set to read the 4-20mA levels and therefore my spacing between "taps" at maximum tap range of 45 would be 355uA so I guess to be safe I would require the accuracy of the circuit to around 150uA.

Currently I have little experience in electronic complex circuits and have been using things lying around the office to help me.

I have a 0-5VDC to 4-20mA convertor which I thought would be easier than trying to develop my own circuit.

I have managed to write a clunky program to complete the same effect of tap position to the receiving device in its binary form for the encoding of binary, grey and BCD which all work reasonably well to an 8 pin output board.

The PWM smoothed voltage output is subject to changes in Vcc and is only 255 steps, so it is about 19.6mV per step.

You are talking about more than 10^5 steps, or 17 bits minimum. With an ultrastable reference.

I'd get an external 20 bit or more DAC with built-in reference voltage.