Can an Arduino UNO output variable a voltage?

I have an LED bar graph controlled by an LM3914 controller that is testing between 0v and 5V. Is there a way to output a variable voltage from an Arduino UNO into the LM3914's voltage input?

I want to control the bar using only the Arduino with code, aka I tell the UNO to output 2.5V and then five bars on the bar graph light up (0.5V per light).

Can the Arduino UNO do this on its own using like PWM or do I need to get an external DAC?

Hi jardane

Can the Arduino UNO do this on its own using like PWM

Yes, it can. You'll probably need to add an RC filter on the PWM output.

http://arduino-info.wikispaces.com/Analog-Output

Regards

Ray

1 Like

It's called a poor mans DAC. 4.7 K ohm resistor and 1 uF (or larger) cap RC filter.
I've used it to control the contrast voltage on an lcd.
But when you can get a 12-bit DAC for $5, why bother ?

raschemmel:
It's called a poor mans DAC. 4.7 K ohm resistor and 1 uF (or larger) cap RC filter.
I've used it to control the contrast voltage on an lcd.
But when you can get a 12-bit DAC for $5, why bother ?

MCP4725 Breakout Board - 12-Bit DAC with I2C Interface [STEMMA QT / qwiic] : ID 935 : Adafruit Industries, Unique & fun DIY electronics and kits

That actually makes logical sense, the capacitor fills in when pwm is off giving you a more stable signal. How do I calculate what kind of capacitor to use?

How do I calculate what kind of capacitor to use?

Do you mean value or type? For 1uF, you can get ceramic capacitors, or a small electrolytic.

If you mean value, there is some guidance in the link I posted. But easiest would be to use the values raschemmel suggested.

The LM3914 does not require any current to speak of for the input voltage. It is a high impedance input since it really is just an array of voltage comparators. Consequently the only thing you need is the voltage. The RC filter does not need to supply any current.
It should be fine with the values stated.

raschemmel:
The LM3914 does not require any current to speak of for the input voltage. It is a high impedance input since it really is just an array of voltage comparators. Consequently the only thing you need is the voltage. The RC filter does not need to supply any current.
It should be fine with the values stated.

How will the resistor and cap affect the voltage? If the pwm is putting out a signal of something around 2.5 V will that be lower on the other end of the resistor and cap? I am new to a lot of this but willing to learn.

PWM is not analog . It is duty cycle controlled digital. The only way to convert a switching digital signal to steady state analog is a low pass filter. Google RC LOW PASS FILTER. The output voltage is across the cap. The resistor is in series with the pwm and the cap
(which is connected from the 4.7 k ohm resistor to ground. ) The other end of the 4.7 k ohm resistor goes to the PWM pin.

While your at it google PWM so you won't need to ask questions like this:

How will the resistor and cap affect the voltage? If the pwm is putting out a signal of something around 2.5 V will that be lower on the other end of the resistor and cap? I am new to a lot of this but willing to learn.

If the pwm is putting out a signal of something around 2.5 V will that be lower on the other end of the resistor and cap?

The input of the LM3914 has a high impedance, which is why it draws very little current from the voltage source you are feeding it from. Very little current means very little voltage drop across the RC filter.

raschemmel:
PWM is not analog . It is duty cycle controlled digital. The only way to convert a switching digital signal to steady state analog is a low pass filter. Google RC LOW PASS FILTER. The output voltage is across the cap. The resistor is in series with the pwm and the cap
(which is connected from the 4.7 k ohm resistor to ground. ) The other end of the 4.7 k ohm resistor goes to the PWM pin.

While your at it google PWM so you won't need to ask questions like this:

How will the resistor and cap affect the voltage? If the pwm is putting out a signal of something around 2.5 V will that be lower on the other end of the resistor and cap? I am new to a lot of this but willing to learn.

I think I will just use the adafruit DAC, I can just tell it what voltage I want it to output.

jardane:
I think I will just use the adafruit DAC, I can just tell it what voltage I want it to output.

I'm late to the party, but for anyone else finding this thread in the future, I found this helpful:

http://sim.okawa-denshi.jp/en/PWMtool.php

@Late2theParty,
Using your tool, I determined that the RC values I orignally chose (4.7 k ohm/1uf) resulted in a lot of ripple and by just substituing a 4.7 uF cap and leaving the 4.7 k , the performance was greatly improved and the ripple drastically reduced.

Incidentally, my values came from here (even though they are the same values I wound up with after trial and error before I found that link. XD)
Coincidentally, it is the same link posted in Reply#1 of this thread by HackScribble.
http://arduino-info.wikispaces.com/Analog-Output

What is it you want to achieve? You have some variable, you convert it into a range of 0..5 Volts, then you feed it out of a PWM pin, smooth it with a low-pass filter, then connect it to a circuit that displays a DIGITAL bar graph display...
Maybe there is a simpler solution without that much conversion

I don't know what he wants the bar graph for but he said the RC filter was too much trouble so he'd rather use a DAC when you think about it, all you need is a simple sketch that increments the pwm value , prints it to the serial port and waits a second and
you could find out what range of values light what number of bars on the led bar graph by watching the display for a change and then reading the value on the serial monitor. That takes a lot less time than ordering a DAC and waiting for it to arrive.

A bar graph? There's a lot to be said for using a MAX7219 instead. True, it does require three pins to interface, but two of them can generally be shared with other similar functions.

And one MAX7219 can control say, four 16-LED bar graphs simultaneously. Why muck about with just one? :smiley:

I don't understand what this means :

then five bars on the bar graph light up (0.5V per light).

This is statement about the resolution of the 10 bar bargraph driven by a maximum voltage of 5V =>10V/5V = 0.5V/bar, right ?

I think the OP was giving an example where the output was 2.5V and half the LED bars should light.

2.5v/ 0.5v =5 Bars.
same thing.

By using a RC combination you will get a voltage drop across the resistor thereby not getting an accurate input into the LM3914.

What would the effect be of just using the capacitor and no resistor in this application?

lemming:
What would the effect be of just using the capacitor and no resistor in this application?

That's a good question. When the Arduino pin goes HIGH the cap will draw as much current as it can, possibly damaging the Arduino pin. Similarly, when it goes LOW (which means the Arduino pin is connected directly to ground), excessive current may be sunk through the Arduino pin.

It will be very hard to eliminate ripple in this scenario as the cap wants to change voltage as quickly as possible (limited only by the capacitor's own internal resistance and the voltage source's ability to supply current).

By using a RC combination you will get a voltage drop across the resistor thereby not getting an accurate input into the LM3914.

Yes you're right, but the effect should be slight as long as whatever you're driving with the RC filter is high impedance (doesn't draw much current). The relationship between voltage and current is inverse; the lower the current being drawn from the output of your RC filter, the higher the voltage will be.

The LM3914, as a TTL device should have a nice high impedance input (on the order of megaohms and microamps), so my wild uneducated guess is that the voltage drop across the resistor might perhaps be something rather less than 0.1V and can probably be ignored for all practical intents and purposes.

If you're putting a significant load on your RC filter, for example if you want to filter the PWM output to drive a motor or something, then yes, the resistor becomes a significant or even insurmountable problem. The resistor has to be small (or eliminated) which means you need a massive capacitor, which quickly becomes impractical for larger loads.