I want to convert the Arduino PWM output that is in the range of 0 - 5V to an analog output in the range of 0-10V.
Here you can see a scheme of the circuit:
The circuit can be divided in two parts:
An RC filter to get an analog output from the PWM signal that Arduino outputs. I have read some information about this kind of filters and it's seems that there is a rule that establish the relation between the time constant of the RC filter and the period of the PWM signal: the RC time contant should be greater than the period. In my case the time constant is 100 times greater.
An operational amplifier with a gain of 2 to obtain the output in the range of 0-10V.
I have made some test with the circuit and seems to work properly but I don't have much experience with electronics so I would be grateful if someone can check if the design is correct.
PWM doesn't control voltage per say, it controls RMS power. The PWM signal is digital, switched between 0 an 5V (no intermediates) with a variable duty cycle (on/off ratio). This works well for controlling motors and LED's. If you want to create a variable DC output from a PWM input this is not trivial.
Looking at your circuit with an RC filter. This filter will smooth the edges of the digital PWM pulses. You could possibly tune the filter so that it approximates a half wave sinus for a specific duty cycle. When you change duty cycle however, the RC element will be out of phase and distort the waveform. Also it would have been simpler to just use a transistor to level shift 5V to 10V first and then apply the RC filter. Doing it this way will eliminate the op-amp from the circuit (there are also issues with op-amp's driven close to the rail supplies).
It is difficult to work around above issues - and if you get it right you will still have a pulsed AC voltage where you really need a variable DC voltage. It may very well be that the power supply you set out to control (for dimming) will not work with this signal as it may expect a fixed DC control signal (e.g. pot controlled).
Another approach is to create a buck (step-down) converter (that is if you already have the 10V supply). If all you have is 5V, you will need a buck-boost converter. If you want to build these yourself, you can do so with a feedback from the output to an analog input on the Arduino and use this to control the switching frequency.
More information on buck/boost rregulators are here:
Another alternative altogether is to look for a digital to analog converter chip or perhaps try to get the PWM version of the light supply dimmer rather than the DC controlled version.
First of all, thank you to everyone for the replies.
I need the version of the power supplies controlled by analog input because the behaviour is more accurate and I need precision. For example, the PWM version starts at 15% as the lowest level that you can achieve and the analog version starts at 5%.
I'm interested in the transitor + RC filter version. In fact, I designed this version but my knowledge about transistors isn't good enough.
I'm interested in the transitor + RC filter version
The BC547 will do just fine. The circuit as drawn will not work. Correcting and building this circuit however is not likley to do you any good since you will end up with an AC signal whereas a controllable DC voltage is required.
One possibility is to use a linear taper (digital pot meter) such as the following:
With this IC you can step voltage between 0 and 5V in 64 increments. You could then use an op-amp to convert this output to the 0-10V range as required.
I'm successfully controlling a PWM motor controller that expects an analog voltage between 0 - 12v. I'm doing this with a transistor and low pass filter. I guess it depends on the design of the controller. It's design may act as another filter.