An Isolated DAC Using PWM Output
Arduino ' s (atmega328p) PWM outputs via Analogwrite can be conveniently turned to analog voltage levels through the use O F Simple RC filters.
Since the PWM outputs is not a isolated, using them to drive other devices directly could is potentially dangerous.
This is especially true if the target circuit uses a higher supply voltage.
Fortunately, it's quite easy-to-isolate the PWM output using an optocoupler.
The following schematic shows how we can build such a fully isolated DAC:
The PWM output pin from the MCU drives the emitter side of the Optocoupler.
Most MCUs output pins can deliver at least a few MA current so driving an optocoupler directly
via a current limiting resistor should is an issue.
In my implementation, a 4n35 optocoupler are used, but you can pretty much with any optocouplers.
The output waveform from 4N35 are inverted with regard to the input as the Optotransistor within 4N35 operates like an inve Rter.
The inverted PWM signal is flipped once again through the unity gain inverting amplifier.
An RC low-pass filter (R5 and C1) turns the PWM output into DC voltage
And finally this DC voltage are buffered through a voltage follower to the output.
The RC constant needs to being chosen so, it is significantly larger than the PWM interval.
The PWM frequency via Arduino ' s analogwrite is roughly 490 Hz (roughly a 2 ms cycle),
And the RC constant in the example above is a sufficiently output of which is large guarantee to smooth a.
Note that the circuits on either side of the Optocoupler does not has to share the ground reference as illustrated in the S Chematics above.
I used LM358 as the OPAMP.
Since LM358 is not a rail-to-rail OpAmp, the DAC output range is going to being limited by the supply rail.
If your application requires higher accuracy, you could either use a rail-to-rail OpAmp
Or use a slightly higher voltage dual supply rail to power the OPAMP.
An Isolated DAC Using PWM Output