Using MOSFET to Measure Internal Resistance

Hi guys! I'm my lithium-ion batteries using this schematic.. I used a IRFZ44N MOSFET. my problem is I'm not getting the voltage at no load (vtgBatUnloaded) . can you please look at my code? Will surely appreciate your help. thanks guys!

#define STATE_WAITING 0
#define STATE_MEASURING 1
#define STATE_MEASURING_ENDED 2
#define BAT_LI 0


float vtgBatUnlod;
float vtgBatLoaded;
float vtgBatUnloaded;
float vtgLoad;
float vtgDropOnLoad;
float vtgDropRin;
float rLoad= 10.0 ; //resistanse of the load in Ohms
float rIn;
float batCurrent;
float mAh;
uint8_t FET_Base=7;
uint8_t state=STATE_WAITING;
float cutoff;
boolean DischargeAllowed=false;
String BatTypeString;



void setup() {

Serial.begin(9600);

pinMode(FET_Base,OUTPUT);
digitalWrite(FET_Base,LOW);

}

void loop() {
  // put your main code here, to run repeatedly:

   if (state==STATE_MEASURING)
   {
  
  vtgBatUnloaded=analogRead(0)*5.0/1024.0; //get the voltage of UNLOADED battery

   }
  
  if (vtgBatUnloaded<cutoff)
  {
    state=STATE_MEASURING_ENDED;
  
  }
  
   digitalWrite(FET_Base,HIGH); //turn the MOSFET on
   
   delay(1000);
   
   vtgBatLoaded=analogRead(0)*5.0/1024.0;   //get the voltage of LOADED battery
   
   vtgLoad=analogRead(1)*5.0/1024.0;
   
   digitalWrite(FET_Base,LOW);//turn the MOSFET off
   
   vtgDropOnLoad=vtgBatLoaded-vtgLoad;

 rIn = ( 10 * ( vtgBatUnloaded - vtgDropOnLoad )) / vtgDropOnLoad ; 

Serial.print(abs(vtgDropOnLoad));
Serial.print(" V");
Serial.println();

Serial.print(vtgBatUnloaded); 
Serial.print(" V");
Serial.println();

Serial.println("Rin= "); 
Serial.print(rIn);
Serial.println();

delay(3000);
  
    
   }

Int Res.PNG

The only state transition that I'm seeing in the entire code is: state=STATE_MEASURING_ENDED;

How is it supposed to enter "STATE_MEASURING"?

stuart0:
The only state transition that I'm seeing in the entire code is: state=STATE_MEASURING_ENDED;

How is it supposed to enter "STATE_MEASURING"?

I updated the code.. And now the result I'm getting is only the vtgBatUnloaded.. Can you help me pleaseeee.. this is the code... I'm getting zero at vtgDropOnLoad.. I need to measure the internal resistance

#define STATE_WAITING 0
#define STATE_MEASURING 1
#define STATE_MEASURING_ENDED 2
#define BAT_LI 0


float vtgBatUnlod;
float vtgBatLoaded;
float vtgBatUnloaded;
float vtgLoad;
float vtgDropOnLoad;
float vtgDropRin;
float rLoad= 10.0 ; //resistanse of the load in Ohms
float rIn;
float batCurrent;
float mAh;
uint8_t FET_Base=7;
uint8_t state=STATE_WAITING;
float cutoff;
boolean DischargeAllowed=false;



void setup() {

Serial.begin(9600);

pinMode(FET_Base,OUTPUT);
digitalWrite(FET_Base,LOW);

}

void loop() {

   if (state==STATE_MEASURING)
   {
  
  vtgBatUnloaded=analogRead(8)*5.0/1024.0; //get the voltage of UNLOADED battery
  
  if (vtgBatUnloaded<cutoff)
  {
    state=STATE_MEASURING_ENDED;
  
  }
  
   digitalWrite(FET_Base,HIGH); //turn the MOSFET on
   
   delay(1000);
   
   vtgBatLoaded=analogRead(8)*5.0/1024.0;   //get the voltage of LOADED battery
   
   vtgLoad=analogRead(9)*5.0/1024.0;
   
   digitalWrite(FET_Base,LOW);//turn the MOSFET off
   
   vtgDropOnLoad=vtgBatLoaded-vtgLoad;


  vtgDropRin=vtgBatUnloaded-vtgBatLoaded;
 

 rIn = ( 10.3* (vtgBatUnloaded - abs(vtgDropOnLoad) ) / abs(vtgDropOnLoad));


   }
   
   else if (state==STATE_WAITING)
   {
digitalWrite(FET_Base,LOW);//turn the MOSFET off
     vtgBatUnloaded=analogRead(8)*5.0/1024.0; //get the voltage of UNLOADED battery

 Serial.println(vtgBatUnloaded);
 Serial.println(vtgDropOnLoad); Serial.print("vtgdr");
 
   }    

   else if (state==STATE_MEASURING_ENDED)
   {
   digitalWrite(FET_Base,LOW);//turn the MOSFET off
    vtgBatUnloaded=analogRead(8)*5.0/1024.0; //get the 

    Serial.println(vtgBatUnloaded);
  

   }

   }

Somewhere, there has to be a statement like:

state = STATE_MEASURING;

If not, this:

   if (state==STATE_MEASURING)
   {

Will never be executed.