battery voltage monitor with NodeMCU (error message)

Hello everyone
I’m trying to make a bateery voltage monitor using the NodeMCU Wi-Fi module. after uploading the code i get this message and the program doesn’t work correctly.

Executable segment sizes:
IROM   : 245700          - code in flash         (default or ICACHE_FLASH_ATTR) 
IRAM   : 27244   / 32768 - code in IRAM          (ICACHE_RAM_ATTR, ISRs...) 
DATA   : 1268  )         - initialized variables (global, static) in RAM/HEAP 
RODATA : 1116  ) / 81920 - constants             (global, static) in RAM/HEAP 
BSS    : 25016 )         - zeroed variables      (global, static) in RAM/HEAP 
Sketch uses 275328 bytes (26%) of program storage space. Maximum is 1044464 bytes.
Global variables use 27400 bytes (33%) of dynamic memory, leaving 54520 bytes for local variables. Maximum is 81920 bytes.
esptool.py v2.8
Serial port COM4
Connecting....
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 48:3f:da:7d:c8:b7
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 4MB
Compressed 279488 bytes to 205371...
Wrote 279488 bytes (205371 compressed) at 0x00000000 in 18.4 seconds (effective 121.3 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...

my code is as follow :

#include <ESP8266WiFi.h>
 
const char* ssid = "mohamed";
const char* password = "12345678";
 
int BAT= A0;              //Analog channel A0 as used to measure battery voltage
float RatioFactor=5;  //Resistors Ration Factor
WiFiServer server(80);
 
void setup() {
  Serial.begin(9600);
  delay(10);
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
 
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  server.begin(); // Start the server
  Serial.println("Server started");
  // Print the IP address on serial monitor
  Serial.print("Use this URL to connect: ");
  Serial.print("http://");    //URL IP to be typed in mobile/desktop browser
  Serial.print(WiFi.localIP());
  Serial.println("/");
}
 
void loop() {
  int value = LOW;
  float Tvoltage=0.0;
  float Vvalue=0.0,Rvalue=0.0;
  
  // Check if a client has connected
  WiFiClient client = server.available();
  if (!client) {
    return;
  }
  
  // Wait until the client sends some data
  Serial.println("new client");
  while(!client.available()){
    delay(1);
  }
 
  // Read the first line of the request
  String request = client.readStringUntil('\r');
  Serial.println(request);
  client.flush();

  // Match the request
  
  if (request.indexOf("/bat=ON") != -1)  {
    /////////////////////////////////////Battery Voltage//////////////////////////////////  
  for(unsigned int i=0;i<10;i++){
  Vvalue=Vvalue+analogRead(BAT);         //Read analog Voltage
  delay(5);                              //ADC stable
  }
  Vvalue=(float)Vvalue/10.0;            //Find average of 10 values
  Rvalue=(float)(Vvalue/1024.0)*5;      //Convert Voltage in 5v factor
  Tvoltage=Rvalue*RatioFactor;          //Find original voltage by multiplying with factor
    /////////////////////////////////////Battery Voltage//////////////////////////////////
    value = HIGH;
  }
 
  // Return the response
  client.println("HTTP/1.1 200 OK");
  client.println("Content-Type: text/html");
  client.println(""); //  do not forget this one
  client.println("<!DOCTYPE HTML>");
  client.println("<html>");
 
  client.println("Battery Voltage =");
  client.print(Tvoltage);
  client.println("
");

  if(value == HIGH) {
    client.println("Updated");
  } else {
    client.print("Not Updated");
  }
  client.println("--------");
  if(Tvoltage<=5){
    client.println("Battery dead OR disconnected");
    }
  else if(Tvoltage>5 && Tvoltage<=10){
    client.println("Need Imediate recharge");
    }
  else if(Tvoltage>10 && Tvoltage<=12){
    client.println("Recharge");
    }
  else{
      client.println("Battery Full");
      }
     
  client.println("

");
  client.println("<a href=\"/bat=ON\"\"><button>Status</button></a>
");  
  client.println("</html>");
  delay(1);
  Serial.println("Client disonnected");
  Serial.println("");
 
}

what is the problem ?

"what is the problem?"
It's uploading fine.

Perhaps you could describe the trouble you're encountering (what it does vs what you expect).

check this :

Ive also read somewhere you must declare if it's measuring internal vcc or pin value I dont remember , check that as well

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