I am trying to use two voltage sensors connected to an Arduino Uno to measure the individual voltages of two battery cells connected in series.
When I connect a sensor with only one cell, it gives the individual voltage correctly. But when I connect both sensors to their individual cells, I get 0 V reading from one sensor and the combined series voltage of the two cells on the other. I have tried swapping the voltage sensors and batteries but the same thing happens.
Is there a way to measure the individual cell voltages without getting the series voltage?
Diagram :
Here is the code that I am using:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address
const int voltageSensor1Pin = A3; // sensor pin
float vIn1; // measured voltage (3.3V = max. 16.5V, 5V = max 25V)
float vOut1;
float voltageSensor1Val; // value on pin A3 (0 - 1023)
const int voltageSensor2Pin = A2; // sensor pin
float vIn2; // measured voltage (3.3V = max. 16.5V, 5V = max 25V)
float vOut2;
float voltageSensor2Val;
const float factor = 5.128; // reduction factor of the Voltage Sensor shield
const float vCC = 5.00; // Arduino input voltage (measurable by voltmeter)
void setup() {
pinMode(8, OUTPUT); // sets the digital pin 13 as output
pinMode(12, OUTPUT);
lcd.begin(20,4);
lcd.setCursor(0,0);
lcd.print("Voltage Measurement");
lcd.setCursor(0,1);
lcd.print("CELL1: ");
lcd.setCursor(0,2);
lcd.print("CELL2: ");
lcd.setCursor(8,3);
lcd.print("****");
Serial.begin(9600);
}
void loop() {
voltageSensor1Val = analogRead(voltageSensor1Pin); // read the current sensor value (0 - 1023)
vOut1 = (voltageSensor1Val / 1024) * vCC; // convert the value to the real voltage on the analog pin
vIn1 = vOut1 * factor; // convert the voltage on the source by multiplying with the factor
voltageSensor2Val = analogRead(voltageSensor2Pin); // read the current sensor value (0 - 1023)
vOut2 = (voltageSensor2Val / 1024) * vCC; // convert the value to the real voltage on the analog pin
vIn2 = vOut2 * factor;
Serial.print("Cell 1 Voltage = ");
Serial.print(vIn1);
Serial.println("V");
lcd.setCursor(8,1);
lcd.print(vIn1);
lcd.setCursor(12,1);
lcd.print("V");
Serial.print("Cell 2 Voltage = ");
Serial.print(vIn2);
Serial.println("V");
lcd.setCursor(8,2);
lcd.print(vIn2);
lcd.setCursor(12,2);
lcd.print("V");
delay(1000);
}