Voltage Reading problem in 10 Channel Battery capacity tester

I want to make a 10 channels Arduino mega-based battery capacity tester using 4.7 ohms 10w resistors controlling them with IRFZ44n MOSFETs with respected digital pins. An 8.4V battery powers the Arduino (do not consider the buck converter in the picture) . I am debugging my project step by step. When I read voltages of individual batteries by corresponding analog pins without turning On 'MOSFET-Gate pins' then Arduino measures the voltages correctly but when I turn on the gate pins then Arduino measures voltage incorrectly.
Thanks in advance. :blush:

Here is the Circuit Diagram of my project:

Here is the Code of my project:

long readVcc() {
  // Read 1.1V reference against AVcc
  // set the reference to Vcc and the measurement to the internal 1.1V reference
  #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
    ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
  #elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
     ADMUX = _BV(MUX5) | _BV(MUX0) ;
  #else
    ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
  #endif  
  ADCSRB &= ~_BV(MUX5); 
  delay(2); // Wait for Vref to settle
  ADCSRA |= _BV(ADSC); // Start conversion
  while (bit_is_set(ADCSRA,ADSC)); // measuring

  uint8_t low  = ADCL; // must read ADCL first - it then locks ADCH  
  uint8_t high = ADCH; // unlocks both

  long result = (high<<8) | low;

  result = 1125300L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000   //1126400L internalRefVolt(1.1) * 1023 * 1000; code can more precse by calculating internalRefVolt(1.1)
  return result; // Vcc in millivolts
}

void setup() {
  Serial.begin(115200);
  delay(3000);
 pinMode(22,OUTPUT);//***Mosfet Gate Pins********
 pinMode(23,OUTPUT);
 pinMode(24,OUTPUT);
 pinMode(25,OUTPUT);
 pinMode(26,OUTPUT);
 pinMode(27,OUTPUT);
 pinMode(28,OUTPUT);
 pinMode(29,OUTPUT);
 pinMode(30,OUTPUT);
 pinMode(31,OUTPUT);
 
   digitalWrite(22,LOW);//***Initially low the Mosfet Gate Pins********
   digitalWrite(23,LOW);
   digitalWrite(24,LOW);
   digitalWrite(25,LOW);
   digitalWrite(26,LOW);
   digitalWrite(27,LOW);
   digitalWrite(28,LOW);
   digitalWrite(29,LOW);
   digitalWrite(30,LOW);
   digitalWrite(31,LOW);




}
/**********************************Void Loop******************************************************/
void loop() {
   float voltRef = readVcc() / 1000.0;

   
   digitalWrite(22,HIGH);//*** High the Mosfet Gate Pins********
   digitalWrite(23,HIGH);
   digitalWrite(24,HIGH);
   digitalWrite(25,HIGH);
   digitalWrite(26,HIGH);
   digitalWrite(27,HIGH);
   digitalWrite(28,HIGH);
   digitalWrite(29,HIGH);
   digitalWrite(30,HIGH);
   digitalWrite(31,HIGH);
   
   
   float volt0 = analogRead(A0)*(voltRef/1024);
   delay(10);
   volt0 = analogRead(A0)*(voltRef/1024);
  /* if(volt0>3.0){
    digitalWrite(22,HIGH); // High = Mosfet ON
    digitalWrite(36,HIGH); // High = LED Turn OFF
    
   }*/

   
   float volt1 = analogRead(A1)*(voltRef/1024);
   delay(10);  
   volt1 = analogRead(A1)*(voltRef/1024);

   
   
   float volt2 = analogRead(A2)*(voltRef/1024);
   delay(10);
   volt2 = analogRead(A2)*(voltRef/1024);

   
   
   float volt3 = analogRead(A3)*(voltRef/1024);
   delay(10);
   volt3 = analogRead(A3)*(voltRef/1024);

   
   
   float volt4 = analogRead(A4)*(voltRef/1024);
   delay(10);
   volt4 = analogRead(A4)*(voltRef/1024);

   
   
   float volt5 = analogRead(A5)*(voltRef/1024);
   delay(10);
   volt5 = analogRead(A5)*(voltRef/1024);

   
   
   float volt6 = analogRead(A6)*(voltRef/1024);
   delay(10);
   volt6 = analogRead(A6)*(voltRef/1024);

   
   
   float volt7 = analogRead(A7)*(voltRef/1024);
   delay(10);
   volt7 = analogRead(A7)*(voltRef/1024);

   
   
   float volt8 = analogRead(A8)*(voltRef/1024);
   delay(10);
   volt8 = analogRead(A8)*(voltRef/1024);

   
   

 
   float volt9 = analogRead(A9)*(4.95/1024);
   delay(10);
   volt9 = analogRead(A9)*(4.95/1024);
  

//*****************************************************************************
   Serial.print("B0= ");
   Serial.println(volt0);

   Serial.print("B1= ");
   Serial.println(volt1);

   Serial.print("B2= ");
   Serial.println(volt2);

   Serial.print("B3= ");
   Serial.println(volt3);

   Serial.print("B4= ");
   Serial.println(volt4);

   Serial.print("B5= ");
   Serial.println(volt5);

   Serial.print("B6= ");
   Serial.println(volt6);

   Serial.print("B7= ");
   Serial.println(volt7);

   Serial.print("B8= ");
   Serial.println(volt8);

   Serial.print("B9= ");
   Serial.println(volt9);
  
    
    Serial.println("");
    Serial.println("==========================");
   delay(500);
      
}

Very hard to see what is happening in your picture. Try drawing a schematic. Have you tried doing it for 1 battery only. What is an “incorrect measurement”?

Arrays will be your friend

1 Like

Yes, I tried it with a single battery. Inaccurate meaning I connect a multimeter with the battery and the analog pin at the same time and the value is pretty much the same like 3.70 volt for the multimeter and 3.72 for analog pin but when I turn On the gate in of the MOSFET the Arduino value like 3.18V and Multimeter volt= 3.37.
Here is the simple circuit diagram for better understanding:
capacity

Have you looked into using the reference voltage as a comparator rather than vcc. Maybe it does this looking at your code.

How can I use reference voltage as a comparator?

I would imagine that the problem is due to the way that you have wired up the MOSFET/Load.

If the load current is flowing through the conductor between the battery and the Arduino ground pin then there will be a voltage drop along that conductor giving the incorrect results.

Can you show us a photograph that clearly shows the wiring?

1 Like


Yes, you are right. Because If I connect the multimeter +ve probe with battery +ve and the -ve probe of the multimeter with battery -ve then the result is different if I connect the -ve probe of the multimeter with the Arduino GND. In White colour is depicted as a GND wire which is a very tiny wire. Now, how can I solve the problem?
Should I replace the ground wire?

IRFZ44N is NOT a logic level MOSFET, 5V on gate may not be enough to saturate it fully and the drain to source resistance may be throwing your measurement off. Measure the voltage from source to drain while the MOSFET is conducting the test current. You need an IRLZ44 (or better).

Hi,
As you are discharging at nearly 1A, you need to dress your wiring to suit and use sized wire to minimise the voltage drop.

The gnd connection to each of the MOSFETs needs to be looked at as ALL the discharge current flows through it.

Tom... :smiley: :+1: :coffee: :australia:

1 Like

The main problem was the battery holder default wire, those wires were have high resistance. After changing those wire the problem was solved. Thank you everyone.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.