/**
* ESP32 zmpt101b AC Voltage Measurement
* Using the ZMPT101B library
*/
#include <ZMPT101B.h>
// Define sensitivity - you may need to calibrate this value
#define SENSITIVITY 500.0f
// Define the pin connected to ZMPT101B sensor output
#define ZMPT_PIN 34
// Create an instance of the ZMPT101B class - using pin 34 and 50Hz frequency
ZMPT101B voltageSensor(ZMPT_PIN, 50.0);
void setup() {
// Initialize serial communication
Serial.begin(115200);
delay(1000);
Serial.println("\nZMPT101B AC Voltage Measurement");
// Set sensitivity value
voltageSensor.setSensitivity(SENSITIVITY);
Serial.println("Sensor configured and ready");
delay(2000);
}
void loop() {
// Read the RMS AC voltage
float voltage = voltageSensor.getRmsVoltage();
// Display the results
Serial.print("AC Voltage: ");
Serial.print(voltage);
Serial.println(" V");
// Additional debug information
float rawVoltage = analogRead(ZMPT_PIN) * 3.3 / 4095.0;
Serial.print("Raw ADC voltage: ");
Serial.print(rawVoltage);
Serial.println(" V");
// Display information about the simulated voltage
Serial.println("------------------------------");
// Wait before taking another measurement
delay(1000);
}