Hi, i am doing a project where i am trying to build a new control unit for the roof at my cabriolet. I need to do some measurements to understand how the original control unit works, but i can't seem to figure out how to do a simple voltage measuring. I am trying to do it with a voltage divider(because of the arduinos 5V limit), which works just fine with one measuring. But when i'm trying to measure two voltages at once, something goes wrong. I believe it is the ground that is wrong.
For simplicity i am just measuring a 9 volt battery for testing. When i use this to measure, it measures about 4,1
voltage, but when i only use one of the dividers, i can measure 7,8 volt (I think the battery is low).
My code:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);}
void loop() {
// read the input on analog pin 0:
int sensorValue0 = analogRead(A0);
int sensorValue1 = analogRead(A1);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
// Multiplying by 5 because of the divider (2/10 ohm)
float voltage0 = (sensorValue0 * (5.0 / 1023.0))*5;
float voltage1 = (sensorValue1 * (5.0 / 1023.0))*5;
// print out the value you read:
Serial.println(String("A0: ") + String(voltage0, 2));
Serial.println(String("A1: ") + String(voltage1, 2));
delay(1000);
}
Hi, i am doing a project where i am trying to build a new control unit for the roof at my cabriolet. I need to do some measurements to understand how the original control unit works,
Really, you should get a multimeter... If your project needs to measure/monitor voltage you use the Arduino but it's not practical to build a voltmeter to use as a general-purpose tool.
Normally all of your grounds should be common and your measurement is made in the middle of the voltage divider. (And you need to flip your voltage divider around because you do want to measure across the 2K.)
If there is no common ground with the Arduino you can "float" the ground like that, but I wouldn't recommend it...
which works just fine with one measuring. But when i'm trying to measure two voltages at once, something goes wrong.
If you make 2 measurements in a row you may need a short delay between the 2 measurements because there is only one multiplexed (shared) analog-to-digital converter and it needs some settling time. But you've shown a setup where both analog inputs are at the same voltage so they should read the same (within resistor tolerance.)
Hi,
Your code needs some changes, using String with Arduino controllers can cause memory problems.
Reading two different analog inputs needs some time as @DVDdoug has said, due to the fact that there is only one AtoD converter and it is multiplexed between the inputs.
A solution is to read each input twice and only use the last value.
Hope this also helps.
int sensorValue0;
int sensorValue1;
float voltage0;
float voltage1;
void setup()
{
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
void loop()
{
// read the input on analog pin 0:
sensorValue0 = analogRead(A0);
sensorValue0 = analogRead(A0);
sensorValue1 = analogRead(A1);
sensorValue1 = analogRead(A1);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
// Multiplying by 5 because of the divider (2/10 ohm)
voltage0 = ((float)sensorValue0 * (5.0 / 1023.0)) * 5.0;
voltage1 = ((float)sensorValue1 * (5.0 / 1023.0)) * 5.0;
// print out the value you read:
Serial.print("A0: ");
Serial.println(voltage0, 2);
Serial.print("A1: ");
Serial.println(voltage1, 2);
delay(1000);
}
DVDdoug, yes i do now i could have used a multimeter, but i need to use the voltages later for the new control unit/arduino.
This was great TomGeorge:)
The reason that circuit is wrong is that the mid-points of a voltage divider must be completely unloaded.
The ADC input of the Arduino is (as close as makes no difference) infinite in resistance, and poses zero
load. Connecting two divider midpoints together mutually loads both.