The following code illustrates both the reading of a voltage with the Arduino and then adjusting it using the code from the Secret Arduino Voltmeter article by Scott Daniels:
Do some initialization stuff (obviously this is not Arduino code as I am using my interface library):
import time
from Py2Ard import interfaceClass
my_board = interfaceClass('/dev/ttyACM0')
Get the reference voltage and use it to calculate an adjustment from 5 volts:
if my_board.referenceVoltage() != 0:
print "Error"
else:
print
print "--------------------------------------"
refVoltage = float(my_board.returnValue) / 1000
print "Reference................. {0:.3f} volts".format(refVoltage)
adjustToRef = 1 + (refVoltage - 5) / refVoltage
print "Adjust to Reference....... {0:.3f}".format(adjustToRef)
print "--------------------------------------"
Get the voltage we are trying to measure and adjust it using the above factor. Note that the '* .0049' converts the analog return from reading the voltage to a five volt scale. The '* 2' then doubles that value to compensate for the voltage divider factor of 50%:
if my_board.pinModeInput(5) != 0:
print "Error"
if my_board.analogRead(5) != 0:
print "Error"
else:
mainVoltage = float(my_board.returnValue) *.0049 * 2
print "Input - As Read........... {0:.3f} volts".format(mainVoltage)
mainVoltage = mainVoltage * adjustToRef
print "Input - Adjusted.......... {0:.3f} volts".format(mainVoltage)
The actual voltage at this point in time is 7.82 as read from our meter so calculate an error percentage:
actualVoltage = 7.82
error = (actualVoltage - mainVoltage) / actualVoltage * 100
print "Error from Actual......... {0:.1f}%".format(error)
print "--------------------------------------"
print
The output from the above script is shown below. Note that I have also adjusted the Arduino referenceVoltage script provided by Scott Daniels as he suggests in his article (adjusting for the inaccuracy of the 1.1v reference by actually measuring the 5v Arduino output and adjusting for the difference).
--------------------------------------
Reference................. 4.910 volts
Adjust to Reference....... 0.982
--------------------------------------
Input - As Read........... 8.026 volts
Input - Adjusted.......... 7.879 volts
Error from Actual......... -0.8%
--------------------------------------
Caveat comes here...it feels like I am double adjusting things to arrive at the answer that I want rather than the right answer... I may post this on Scott's page and ask him if my not electronically oriented brain has miss interpreted things badly!
hi, I'm having a problem with my Arduino, I think I broke it. I tried to learn how to measure the voltage, I connected a wire to the 5V and a wire to the Ground and set my multimeter to 200V. After that operation, I connected the red probe from multimeter to 5V and the black to the Ground and my Arduino board started to heat.
ReplyDeleteAfter that operation I think I destroyed the board. Please leave me a comment about that problem, what happens when by mistake I set the multimeter to 200V instead of 20V and I want to know if my problem with the board is from that mistake?
Thanks!
P.S.: I'm using the same multimeter as yours.
Bogdy Padu:
ReplyDeleteI am certainly not an expert in things electrical, and I have also seen smoke a couple of time, but, it sounds like you short circuited your Arduino board through the multimeter. I don't think it matters what setting the meter was on, what is important that it acts pretty much as a straight passthrough and what it passed through was a short circuit. Do any of the other pins on the Arduino still work? I am not sure what to tell you. I would be interested in a little better description of what you hooked up where but the best place for you to get help might be to post this issue on the Arduino forum where there are some really knowledgeable folks!
http://arduino.cc/forum/index.php?action=forum
Will
Whats the voltage range one can measure and whats he accuracy?
ReplyDeleteThe Arduino measures voltage from 0-5V with 10 bits of accuracy (5v = 1023). You can, however get Analog Digital Convertors that will allow accuracy of 12 - 18bits. These are accessed via I2C or SPI.
DeleteYou can also use a voltage divider to measure voltages of higher than 5v (covered elsewhere in the blog).