So I have a project that is running on a mobile battery that is 5vdc with a capacity of 2000ma.I would like to be able to monitor the voltage that is in the battery .I know I should just be able to take an amperage reading and divide that into battery capacity and determine its life, what I would like to do is display or monitor it so I can put together a way to recharge it as needed. Problem is that A0 is currently being used.Also had to cut most of the code out, ran in to the 9000 character limit.
Arduino IDE 1.8.13
Windows 10 Pro
WeMos D1 mini
#include <Adafruit_Sensor.h>
#include <DHTesp.h>
// Loading libraries
#include <ESP8266WiFi.h>
#include "DHT.h"
// Uncomment one of the lines below for whatever DHT sensor type you're using
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
//#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
// REPLACE THOSE VARIABLES WITH YOUR SSID and PASSWORD
const char* ssid = "my home ";
const char* password = "my password";
// Web server runs on port 8888
WiFiServer server(8888);
// Header page
String header;
// GPIOs variables
String output1State = "Off";
String output2State = "Off";
int output1 = 16;
int output2 = 2;
// DHT sensor pin
const int DHTPin = 5;
// Initialize DHT sensor.
DHT dht(DHTPin, DHTTYPE);
// Temporary variables to store DHT data
static char celsiusTemp[7];
static char fahrenheitTemp[7];
static char humidityTemp[7];
// Smoke sensor pin
int smokePin = A0;
// Smoke threshold, you can adjust this value for your own readings
int smokeThres = 60;
// PIR mtion sensor
const int motionSensor = 4;
// Control variables for smoke and motion sensors
boolean armSmoke = false;
boolean smokeTriggered = false;
boolean armMotion = false;
boolean motionTriggered = false;
// LEDs for smoke and motion status
const int smokeLED = 13;
const int motionLED = 12;
// Buzzer pin
const int buzzerPin = 14;
// Timers auxiliar variables
unsigned long now = millis();
unsigned long lastSmokeCheck = 0;
unsigned long previousTime = 0;
// Define timeout time in milliseconds (example: 2000ms = 2s)
const long timeoutTime = 2000;
// Only runs once
void setup() {
// Preparing GPIOs
pinMode(output1, OUTPUT);
digitalWrite(output1, LOW);
pinMode(output2, OUTPUT);
digitalWrite(output2, LOW);
pinMode(smokeLED, OUTPUT);
digitalWrite(smokeLED, LOW);
pinMode(motionLED, OUTPUT);
digitalWrite(motionLED, LOW);
pinMode(buzzerPin, OUTPUT);
pinMode(smokePin, INPUT);
// Setting motionSensor as an interrupt
attachInterrupt(digitalPinToInterrupt(motionSensor), detectsMovement, RISING);
// Initializing DHT sensor
dht.begin();
// Initializing serial port for debugging purposes
Serial.begin(115200);
delay(10);
// Connecting to WiFi network
Serial.println();
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");
// Starting the web server
server.begin();
Serial.println("Web server running. Waiting for the ESP IP...");
delay(10000);
// Printing the ESP IP address in the serial monitor
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.println(":8888");
}