I am trying to output analog voltage (400 mV) using Arduino Nano PWM pins. Is it okay to directly connect (using jumper wires) the PWM pins to the Vin+ of the INA219 current sensor?
I badly need it for my graduation project. Thanks for the help.
PWM pins don't output analog voltages. They output pulses of 5V. You then need to average the output in order to get an actual analog voltage out of it. You should be able to use a capacitor and resistor to average out the voltage of the PWM pin, making a low-pass filter. You won't get exactly to 400mV. If I remember correctly the PWM pin has a value of 0 - 255, and 1/255 is 0.0196 V after a good low-pass filter, or 19.6 mV, so
analogWrite(pin,20) should get close to the 400mV you want.
Another option would be to use a voltage divider to the output to get the output you want. That way you can use the full range of
analogWrite() in producing the 400 mV and smaller voltages, thus gaining precision. Then again, if all you want is a fixed 0 or 400mV you could accomplish that with a digital output pin and a fixed voltage divider - no need for PWM.
Of course it's possible !
Duncan you made a little error of 10^2 ;)
5V / 1023 = 0.004887.. = 4.88mV
For 400mV you got 400/4.88 = 81.9.
So in the arduino a value of 82 (0-1023) will send you an output of 400.16mV after beeing redressed by a RC filter.