const int voltageSensorPin = A0; // Analog pin connected to the voltage sensor
const float voltageDividerFactor = 3.9; // Voltage divider factor used to calibrate the sensor
void setup() {
Serial.begin(115200); // Initialize serial communication
}
void loop() {
// Read the raw ADC value from the voltage sensor
int sensorValue = analogRead(voltageSensorPin);
// Convert the raw ADC value to voltage
float voltage = sensorValue * (3.3 / 4095) * voltageDividerFactor; // ESP32 ADC resolution is 12 bits (4095 levels)
// Print the voltage value to the serial monitor
Serial.print("Voltage: ");
Serial.print(voltage);
Serial.println(" V");
delay(1000); // Wait for 1 second before taking the next reading
}