Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Wi-Fi Controlled Battery Monitoring System with ESP8266 and TP4056

View and Edit Project In Cirkit DesignerImage of Wi-Fi Controlled Battery Monitoring System with ESP8266 and TP4056

Circuit Documentation

Summary

The circuit in question appears to be a smart device that monitors battery voltage and reports the data to a server via Wi-Fi. It includes a charging module for a 3.7V battery, an ESP8266 NodeMCU microcontroller for processing and Wi-Fi connectivity, IR sensors for input, a relay module for controlling DC motors, and passive components like resistors and a capacitor for voltage regulation and filtering. The circuit also features a bridge rectifier and a copper coil, which may be part of a power supply or charging system.

Component List

TP4056

3.7V Battery

ESP8266 NodeMCU

Resistor (100k Ohms)

DC Motor

5V 2-Relay Module (JD-VCC)

IR Sensor

Bridge Rectifier

Electrolytic Capacitor (2200uF)

Copper Coil

Wiring Details

TP4056

3.7V Battery

ESP8266 NodeMCU

Resistor (100k Ohms)

DC Motor

5V 2-Relay Module (JD-VCC)

IR Sensor

Bridge Rectifier

Electrolytic Capacitor (2200uF)

Copper Coil

Documented Code

#include <ESP8266WiFi.h>
 
String apiKey = "**************";
const char* ssid =  "**************";     // Enter your WiFi Network's SSID
const char* pass =  "**************"; // Enter your WiFi Network's Password
const char* server = "api.thingspeak.com";
 
int analogInPin  = A0;    // Analog input pin
int sensorValue;          // Analog Output of Sensor
float calibration = 0.36; // Check Battery voltage using multimeter & add/subtract the value
int bat_percentage;
 
WiFiClient client;
 
void setup()
{
  Serial.begin(115200);
  Serial.println("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, pass);
 
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(100);
    Serial.print("*");
  }
  Serial.println("");
  Serial.println("WiFi connected");
}
 
void loop()
{
  sensorValue = analogRead(analogInPin);
  float voltage = (((sensorValue * 3.3) / 1024) * 2 + calibration); //multiply by two as voltage divider network is 100K & 100K Resistor
 
  bat_percentage = mapfloat(voltage, 2.8, 4.2, 0, 100); //2.8V as Battery Cut off Voltage & 4.2V as Maximum Voltage
 
  if (bat_percentage >= 100)
  {
    bat_percentage = 100;
  }
  if (bat_percentage <= 0)
  {
    bat_percentage = 1;
  }
 
  Serial.print("Analog Value = ");
  Serial.print(sensorValue);
  Serial.print("\t Output Voltage = ");
  Serial.print(voltage);
  Serial.print("\t Battery Percentage = ");
  Serial.println(bat_percentage);
  delay(1000);
 
  if (client.connect(server, 80))
  {
 
    String postStr = apiKey;
    postStr += "&field1=";
    postStr += String(voltage);
    postStr += "&field2=";
    postStr += String(bat_percentage);
    postStr += "\r\n\r\n";
 
    client.print("POST /update HTTP/1.1\n");
    delay(100);
    client.print("Host: api.thingspeak.com\n");
    delay(100);
    client.print("Connection: close\n");
    delay(100);
    client.print("X-THINGSPEAKAPIKEY: " + apiKey + "\n");
    delay(100);
    client.print("Content-Type: application/x-www-form-urlencoded\n");
    delay(100);
    client.print("Content-Length: ");
    delay(100);
    client.print(postStr.length());
    delay(100);
    client.print("\n\n");
    delay(100);
    client.print(postStr);
    delay(100);
  }
  client.stop();
  Serial.println("Sending....");
  delay(15000);
}
 
float mapfloat(float x, float in_min, float in_max, float out_min, float out_max)
{
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

This code snippet is for the ESP8266 NodeMCU microcontroller. It reads an analog value from pin A0, calculates the battery voltage and percentage, and sends this data to ThingSpeak server using Wi-Fi. The mapfloat function is used to map the voltage to a percentage value. The code includes a calibration factor to adjust the voltage reading to match the actual battery voltage as measured by a multimeter.