0

I am using arduino Uno/Mega.

I am trying to output a range of 0-5v volts using PWM.

Is it possible to do it?

It’s would be nice to see some code or instructions, as far I have seen, they used external Module to get that voltage range, maybe I am wrong or I didn’t understand them well.

Thanks!

2
  • 1
    If you want a steady stable voltage at that level then no it isn't possible without external circuitry. If you just want PWM that averages at that level then check out the doc page for analogWrite on the arduino.cc website. It's basic stuff. Definitely not secret or hard to find.
    – Delta_G
    Commented Sep 21, 2020 at 23:12
  • just send it through a 2-stage low pass RC filter, then send the output to a unity gain opamp buffer, then send that through a series-pass voltage follower transistor if needed.
    – dandavis
    Commented Sep 22, 2020 at 21:25

2 Answers 2

5

Short answer: No.

Arduino Unos and Megas have PWM (Pulse Width Modulation) output, which rapidly turn the output on and off with a varying "duty cycle" (The ratio of on time to off time.) That is not the same thing as an analog output voltage.

If you have a constant load you can build a low pass filter that will smooth the output to a slightly dirty DC output based on the PWM output.

You're better off using an external DAC (Digital to Analog Converter.) You send that a digital value and it converts it to a clean, filtered analog output. Most modern DACs are fast enough to output complex waveforms like music.

Edit:

The Arduino zero apparently has a built-in DAC with up to 10-bit resolution. you could use that to output a low current DC voltage. However the zero is a 3.3V device.

1

The Arduino is a digital device; each output pin is either HIGH (+5v) or LOW (0v = GND), not in between.

For certain types of devices (motors, LEDs) there is a technique you mentioned called PWM, pulse width modulation, which turns the output on and off rapidly. It's still just a square wave alternating between 0 and 5v but it's doing it really fast. So for an LED for example, your eye will make you think it's at half-brightness even though it is flashing on and off very quickly.

To do this you need to use a pin that has "analog" ability and use the "analogWrite" command.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.