Analog fluctuating

Hey there!

I am looking for help here. I am trying to measure 12V 3s battery pack. The voltage is higher than the Arduino voltage so I can not measure it directly so I measure every cell individually with optocoupler H11F1.

float tempVal1;
float posVal1 = 0;
float tempVal2;
float posVal2 = 0;
float tempVal3;
float posVal3 = 0;
void setup() {
 Serial.begin(9600);
 pinMode(2, OUTPUT); 
 pinMode(3, OUTPUT); 
 pinMode(4, OUTPUT); 
 pinMode(5, OUTPUT); 
 pinMode(6, OUTPUT); 
 pinMode(7, OUTPUT);  
 pinMode(A0, INPUT);
 pinMode(A1, INPUT);
 pinMode(A2, INPUT);
}

void loop() {

digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
tempVal2 = analogRead(A1);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
delay(200);
Serial.print (tempVal2);
Serial.print ("     ");
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
tempVal3 = analogRead(A2);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
Serial.print (tempVal3);
Serial.println ("     ");
delay(200);
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
tempVal1 = analogRead(A0);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
delay(200);
Serial.print (tempVal1);
Serial.print ("     ");

 }

Process: connect + and - of first cell, measure, disconnect and connect the second cell and so on. This works perfectly with 0.01 precision but there is a lot of fluctuation with value of analog PIN A0. The other two values are perfect but why there is fluctuation in value of A0? I know that there is a fluctuation in analog PIN when nothing is connected but why only A0 value is fluctuating here and the others are ok?

I attached wiring diagram and measured values in serial monitor. Left column is A0.

Thank you for your help!

It appears the ground is common to the arduino when the 3 cells are in series. I would suggest you set up a voltage divider where you connect a 1K resistor to ground and the analog pin. Then connect a 2K resistor from the analog pin to the top battery (12V). This will give you 4 volts when the battery is at 12. This gives you some headroom for charging etc. You can use the map instruction to scale the voltage to what you want. You can actually calibrate your output with a decent volt meter. If the reading is off adjust 1 resistor value in the calculations. You simply connect when you want a reading. the lower resistance of the voltage divider will help stabilize the measurements. You can add a bypass cap from the junction of the two resistors to ground.

Please edit your drawing with pin numbers on the H11F1s and / or make a drawing of one channel using this symbol.

H11F1.png

H11F1.png

JCA34F:
Please edit your drawing with pin numbers on the H11F1s and / or make a drawing of one channel using this symbol.

H11F1.png

I redrawed the wiring. Pin 1 is connect to digital pin of the Arduino through 500 ohm resistor. Pin 2 is connected to the Arduinos ground. Pin 4 is connected to the +/- terminal of the battery and pin 6 connected to the Arduino analog PIN/ Arduino groind. Arduino gives a command to connect digital pin on H11F1, the optocoupler connects pins 4 and 6 so there is a battery voltage on Arduino analog PIN. This happens for every cell individually. If I would do it for all of them at once then Arduino would burned because can not handle 12v. I might have used voltage dividers but I wanted mmore sofisticated solution with much better precision.

gilshultz:
It appears the ground is common to the arduino when the 3 cells are in series. I would suggest you set up a voltage divider where you connect a 1K resistor to ground and the analog pin. Then connect a 2K resistor from the analog pin to the top battery (12V). This will give you 4 volts when the battery is at 12. This gives you some headroom for charging etc. You can use the map instruction to scale the voltage to what you want. You can actually calibrate your output with a decent volt meter. If the reading is off adjust 1 resistor value in the calculations. You simply connect when you want a reading. the lower resistance of the voltage divider will help stabilize the measurements. You can add a bypass cap from the junction of the two resistors to ground.

I need more precise measurement which I can not achieve with voltage divider. I tried a divider once but there was too great fluctuation, noises and it seemed like non-linear. I want precision of 0.01 volt. Arduino is powered with external insulated power source. Arduino has common ground with measured cell.

You can get a bit more precision using the internal 1.1 voltage reference and scaling your input to 4v .
Bear in mind you only have 1part in1024 resolution on the a/d and moving about the odd digit is normal on the output but will be better on the internal reference .
That gives you a resolution of around +- 4mV
More than good enough for monitoring battery voltage , you can’t get 1mV with that A/D.

As mentioned above a simple tap off the top of the battery , scaled down with a divider would still give you a resolution of 12mV still more than good enough for battery monitoring . Still use the internal ref tho !

Those are clever opto isolated fet switches - hadn't come across them before.

Should work fine if the Arduino is fully isolated from all but one cell at a time, your fluctuations may
simply be a bad connection.

However this circuit is only safe if the software never turns on the photo-FETs for multiple
cells simultaneously. Its intrinsically fragile to have a piece of hardware that can be destroyed
if the software has a fault, clever though this circuit is - for instance if the Arduino crashes
due to a power glitch, or RFI, it might go haywire and short the full 11V to itself and fry.

However this is easy to fix, add 10k resistors in series with each connection between the battery
and the photo-FETs.