3
0

17 lines
1020 B
C

/* Battery interfacing (ADC sense + FET drive) - NodeMCU-32S */
#ifndef BATTERY_INTERFACING_H
#define BATTERY_INTERFACING_H
/*PINOUT DEFINITIONS FOR USING THE BOARD's MECHANISMS
FOR MONITORING BATTERY LEVEL VIA ADC (USING VOLTAGE DIVIDER SUBCIRCUIT)
BY TOGGLING THE FET SWITCHES PRESENT ON THE IoT Carrier
ADDITIONALLY PROVIDED A CONSTANT,BASED ON BOARD's COMPONENT VALUES
THIS CONSTANT IS TO BE USED WHEN CALCULATING BATTERY LEVEL
DO NOT CHANGE PIN AND CONSTANT DEFINITIONS*/
#define BATTERY_ADC_PIN 33 /* ADC input pin,whose function is to gauge battery level via the voltage divider on the PCB */
#define FET_DRIVE_PIN 18 /*FET enable pin, to drive the NMOS switch to close,in order to close the PMOS switch as well,which allows reading the battery voltage */
#define ADC_DIVIDER_GAIN 1.5f//V_ADC = VBAT * (R15 / R14 + R15), therefore VBAT = V_ADC * ((R14 + R15)/ R15). The latter is the formula to be used to get the battery level by using the ADC input. The resistor ratio is 1.5
#endif