I wrote a sketch to apply a voltage to the digital pin 9 with a duty cycle of 10 (~200 mV) and measure the same using the analog pin A0. I am using the internal reference to improve the accuracy. The problem is that for any value other than 0 or 255 the serial monitor shows 0 in between the actual voltage values. I have attached the screenshot of the serial monitor output and my sketch for reference. Could anyone please explain why I am seeing these 0’s in between my actual voltage readings? I am also using a fluke multi-meter to measure the actual voltage applied using the arduino pin 9. Does this have something to do with the pwm frequency? If so how to get around this problem? Thanks in advance.
PWM outputs are, by their nature, either 5V or 0V. They do not provide an analogue output with a variable voltage.
Please post your sketch here in a form that can be copied to an editor.
Hi. Thanks for the reply. I have attached the sketch I wrote.
test_3.ino (535 Bytes)
Just a clarification. When I change the value to any number between 0-255 I am able to see the change in both my serial monitor display and the fluke multi-meter. It is the zero's in between the values in serial monitor that is troubling me. Any help is highly appreciated. I have posted my code in the last post. Here is the cut and paste version:
int analoginput = 0; // analog pin
int analogamount = 0; // stores incoming value
double voltage =0; // used to store voltage value
analogReference(INTERNAL); // use AREF for reference voltage
voltage=analogamount*(value0.01914828431); //calibration factor = value1000/(51*1024)
Please read the section “measurement time” on this URL: http://www.radio-electronics.com/info/t_and_m/digital-multimeter/how-a-dmm-works-operation.php.
In particular, look at “signal measurement time”. Your Fluke cannot possibly measure a rapidly varying signal as DC voltage. You will get some attempted value, but is meaningless.