i'm using Arduino Mega and 25v voltage sensor from MH Electronic.
i'm trying to measure (some) battery voltage but it always displaying 0v.
but when i put VCC (sensor in) into 5v or 3.3v on the Arduino board, it can measure the voltage normaly.
What voltage are you trying to measure. Only DC with the right polarity will work.
Did you get the code from "Destructables".
Seems someone has pulled some random lines out of a hat.
"wire" is for I2C devices, "temp" is for a temperature sensor, and "4.096" seems to come from a 12-bit A/D.
Try this sketch.
25.0 is coming from the 1:4 voltage divider ratio (7k5 and 30k), multiplied with 5volt Aref (assuming you're using an Uno/Nano/Mega).
Leo..
Wawa:
What voltage are you trying to measure. Only DC with the right polarity will work.
Did you get the code from "Destructables". http://www.instructables.com/id/Arduino-Voltage-Sensor-0-25V/
Seems someone has pulled some random lines out of a hat.
"wire" is for I2C devices, "temp" is for a temperature sensor, and "4.096" seems to come from a 12-bit A/D.
Try this sketch.
25.0 is coming from the 1:4 voltage divider ratio (7k5 and 30k), multiplied with 5volt Aref (assuming you're using an Uno/Nano/Mega).
Leo..
The thing is just two resistors in series making a voltage divider. If you have a DVM, digital volt/ohm meter, check the resistance values. If no meter, look very carefully at the soldering job on all the connections. This is too simple to fail!
Wawa:
Tried what, and what are the results.
Again, what are you trying to measure (can't see what's connected to the screw terminal).
Random values from an unconnected pin is normal.
The purple wire (5volt) does nothing, and can be removed. See this tutorial.
Leo..
try the code embedded in your post.
yes, i already remove the + wire and still same result.
i'm trying to measure AA battery voltage (1,5v).
i connect sensor input :
VCC -> + battery
GND -> - battery
at first i think it's sensor failure, but i bought 10 pieces and i try it all, and the result is same : 0v.
but when i connect the VCC sensor input to 5v or 3.3v on arduino board, it's measure correctly WITHOUT connecting the GND sensor input to GND arduino board.
Have you tried measuring 3 or 4 AA batteries in series or perhaps a 9V battery? I wonder if 0.375V (1.5V/4) is below some threshold for your code. As Leo says try printing the actual result of the analogRead directly. Do you actually get literally all zeros?
Have you tried measuring 3 or 4 AA batteries in series or perhaps a 9V battery? I wonder if 0.375V (1.5V/4) is below some threshold for your code. As Leo says try printing the actual result of the analogRead directly. Do you actually get literally all zeros?
Steve
i have tried 9v battery, but with same result.
at first, the result is not 0v, 0.xx volt. but it only last for few loops (3-5 loops with delay 500) and then back to 0v again. it happened everytime i connect the VCC input sensor to + battery without connecting the - battery.
i tried to print the actual analogRead value, same pattern but with different value, it's end with 0 value.
sgun:
i have tried 9v battery, but with same result.
at first, the result is not 0v, 0.xx volt. but it only last for few loops (3-5 loops with delay 500) and then back to 0v again. it happened everytime i connect the VCC input sensor to + battery without connecting the - battery.
You can't expect to read anything without connecting BOTH terminals of the battery. You have to complete the circuit. If you're just connecting the battery +ve then you are getting what you should expect.
And before you say it works with the 5V from the Arduino, that's because you have that voltage's circuit completed via the output ground
slipstick:
You can't expect to read anything without connecting BOTH terminals of the battery. You have to complete the circuit. If you're just connecting the battery +ve then you are getting what you should expect.
And before you say it works with the 5V from the Arduino, that's because you have that voltage's circuit completed via the output ground
Steve
sorry if i missed something..
but the result is 0v with or without GND sensor input connected to - battery..
Take your 9V battery, makes sure it actually outputs 9V (use your multimeter to confirm this - you do have one, no? If not - do something about that!), connect it to the screw terminals, then use your multimeter to measure the voltage between the output pin and the GND pin. Now you should measure 2.25V.
Then you can connect the sensor to your Arduino - and measure again to make sure you see the same 2.25V on your analog pin (use the one you have set in your software).
And if you really still can't see any voltage it's just about possible that the input ground on the board is not connected.
If you have a meter that measures resistance check that there is zero resistance between the input and output grounds. If you don't have a meter try connecting your battery +ve to the Vcc screw terminal with your battery -ve connected to the OUTPUT - pin.