# Variable voltage (0-12V) using PWM from Arduino

Hi,
I would like to make a regulated power supply system using the Arduino microcontroller. The system is supplied with voltage approx. 18V DC. The output voltage should be regulated in the range from 0 to 12V, the current MAX to 2A. 4 fans paralleled (12V, 0.6A) will be connected to the output.
I tried to make it as shown at the picture in attachment.

Voltage regulation via PWM works very well from 0V, but only without the load. The lowest possible setting the output voltage after connecting the load is 4-5V. How can I fix this?

I also have a problem with the measurement of the output voltage. Voltage measurement is needed to correct the voltage level (as feedback). I tried to measure the voltage with a voltage divider by the Arduino analog port, but it also did not work well.
How to perform the power supply to have established performance? How it could be controlled via PWM output voltage at the output at the same time? Do you have any proven circuit diagrams? Thanks in advance for suggestions.
Thanks for looking.

Is your output really between the +18v terminal and the transistor? You're doing low-side switching so the negative terminal of your output is floating somewhere between 0V and 18V. You don't seem to be measuring this voltage with that schematic. Because of the 5V regulator, the Arduino doesn't know anything about the 18v rail, so a voltage divider going to 18v is not going to return any useful information. Maybe you need another voltage divider to measure the 18v and then subtract in software.

That transistor is going to get hot. I hope it has a good heatsink.

You do realize that PWM is not DC, right?

A capacitor at the Arduino's ADC input will filter the PWM to give you an average. 1uF - 10uF should be about right with your 10K resistors. (Your voltage divider should be connected to ground, not 18V.)

Voltage regulation via PWM works very well from 0V, but only without the load. The lowest possible setting the output voltage after connecting the load is 4-5V. How can I fix this?

You can't get zero-volts across the load? You do need to measure across the load, since the ground is PWM switched and the 18V remains on.

How about if you turn and & off pin-9 digitally (without PWM)? If you're measuring PWM with a multimeter you won't generally read the average unless you have a mechanical/analog meter.

There is lots more wrong with that schematic as well. You seem to be feeding 5V into the Vcc pin, you need at least 6.5V in that pin to make the regulator work. You have probably blown up that analogue input because when your TIP122 is off there is in effect no current down the potential divider so you are blasting 18V into the analogue input.

Hi, If you are trying to measure the output voltage to the fans, the resistor network you have there will not do the job. The analog input of the YUN, measures voltage from gnd, your resistor network is not referenced to gnd.

To measure the voltage you want you will need to measure the voltage on the 18V rail, and measure the voltage on the transistor cathode, then subtract one from the other to get the voltage across your fans.

Tom... :)

7805 controller has of course the heat sink. But I wonder even the replacement of the DC-DC Buck Converter Step Down that shone less.

A capacitor at the Arduino’s ADC input will filter the PWM to give you an average. 1uF - 10uF should be about right with your 10K resistors.

I tried to change the resistor R6 to 10K and capacitor C3 to 1uF, 4.7uF and 10uF. But all changes resulted in maximum voltage at the output and the lack of adjustment possibilities.

I tried to measure the output voltage between pin 2 TIP122 transistor and GND, and then calculate the output voltage from the formula:

``````Vout = 18V - analogRead(A0) / 1024 * 5V * 4 (in sketch arduino)
``````

As shown in the picture in attachment. But such a voltage divider connected resulted in incorrect operation of the transistor.

PWM value on pin 9 set as follows:

``````int R = 200;
byte value = map(R, 0, 1023, 0, 255);
analogWrite(9, value);
``````

How about if you turn and & off pin-9 digitally (without PWM)? If you’re measuring PWM with a multimeter you won’t generally read the average unless you have a mechanical/analog meter.

After unplugging connection pin 9 the output voltage drops to 0V.

You have probably blown up that analogue input because when your TIP122 is off there is in effect no current down the potential divider so you are blasting 18V into the analogue input.

Can I connect a voltage divider as the attached picture, the analog input can be damaged?

To measure the voltage you want you will need to measure the voltage on the 18V rail, and measure the voltage on the transistor cathode, then subtract one from the other to get the voltage across your fans.

I tried to do that, but then did not work properly on the output voltage regulation.

I know that my system contains faults and I am looking for some better solution to the problem. I found something like this:
http://www.edn.com/design/analog/4363990/Control-an-LM317T-with-a-PWM-signal
Is the implementation of such a solution would be better? Unfortunately, the chip LM317T has only 1.5A output. And I need at least 2A output. Is it possible to replace it with something more efficient?

Hi, using the last circuit, Sup2, you would assume that the 18V will be constant for your load.

You would then regulate for 18 - 12 = 6V on the collector of the transistor.

Dont forget its PWM so you may need to place a low pass filter between the resistor array and the analog input.

Also, if the voltage sensed is too low, that is less than 6V, which means you have more than 12V output, you will need to increase the PWM duty cycle.

Tom... :)

If you look at the data/applications for the LM317 you will find how to get more current control.

TomGeorge: Dont forget its PWM so you may need to place a low pass filter between the resistor array and the analog input.

I thought that too but if you look carefully, you will see that he has an RC filter before the output transistor. The transistor will be operating in a linear (analog) mode and it will get hot.

This circuit is totally broken, sorry to say!

• Why would you be using an Arduino YUN rather than a Pro Mini?
• The 7805 is still shown feeding “VIN” instead of the 5V line. If you have a 5V regulator, connect it to the 5V terminal. The regulator will not be significantly loaded by the circuit shown, only a concern if there are other systems involved.
• What is the purpose of these attempts at sensing the motor voltage anyway? What are you really attempting to do? Use the Arduino to provide a regulated 12V supply? Forget that! Use a 7812 regulator. You need 2 Amps? Just use two 7812 regulators.
• Now, you want to speed control the fans? Use PWM to do that. No capacitors.
• Don’t use Darlington pairs, they are inefficient. Just use a suitable FET (someone will no doubt suggest) controlled directly by an Arduino output. You are connecting the grounds together anyway, so isolation is not relevant.

Do not insist on such a scheme, as I showed earlier. I want to be able to set a voltage of 0 to 12 V in steps of 1V. Setting will be done remotely (therefore YUN). The system will power the constructions 4 fans that draw about 1.6A at 12V (But it will also be connected to the bulb 6V). To get to the 12V fan I have to give the input of about 16V (for voltage drop). Measurement of the output voltage is used to correct the voltage to a predetermined value.

I found and adapted to their needs such a solution as in the diagram. Would that be a better solution than the previous one? Is there a chance that you can adjust the output voltage?

That does look a lot better. It's still an unconventional way to do it. The LM317 means that you can never have your output go below 1.25v. Do you never want to switch this regulated output completely off?

You have issues around the +ve input of U5. Op amps work off voltage Inputs not current. That opto isolator output is not going to be able to control the output of U5.

You have issues around the +ve input of U5. Op amps work off voltage Inputs not current. That opto isolator output is not going to be able to control the output of U5.

Therefore, the low-pass filter is bad? Do you mean other connection?

That does look a lot better. It’s still an unconventional way to do it. The LM317 means that you can never have your output go below 1.25v. Do you never want to switch this regulated output completely off?

I have a converter system built on the chip LM2596. It has a feature on / off. For 0V I could turn it off using the Arduino software. I do not know if we can control, drive it from the output of the op amp. This could look like the diagram …

This is a chance to work?

No I mean that there is no change in the input to that op amp no matter what the state of the opto LED is. It either connects the input to the supply through a small resistor, when the LED is on, or through a high resistor ( transistor leakage ) when it is off. The result is that the input to that op amp is always the full 18V.

Is a resistor on pin 5 opto-isolator will solve the problem? What should have value? 1k enough?

No a resistor on pin 5 will not solve the problem.

I found some other connection of opto-isolator. Will it be better?

Looks better. :)

No, not completely better. Somewhat better. It is charging through 20k and discharging through 10k.

Why do you have an optoisolator? Why not just PWM through an RC network?

I cannot find the thread here now. Drive it with the Arduino output and smooth it in an RC network. Feed that to an Op Amp with a gain sufficient to change 5V into 12V. The Op Amp needs to be rail to rail, or you need to use a 15V supply voltage. An LM358 will only go to 1.5V below its supply voltage.

Or use an external DAC.

Or use a digital pot as part of the feedback/voltage set network on a linear regulator.

This SPI interface DAC chip is available in surface mount or PDIP for \$6 each, minimum 2 from Linear Technologies. It can run on up to 15V and so can output 0-12V directly.

http://www.linear.com/product/LTC1257