ZMPT101B
How to use ZMPT101B Voltage Sensor Module with Arduino
Manufacturer
unknown
Overview
Part: ZMPT101B Voltage Sensor Module
Type: Voltage Sensor Module
Key Specs:
- null
Features:
- null
Applications:
- Used with Arduino
Package:
- null
Applications
- Electrical energy meters
- AC Voltage measurement
- Household electrical equipment
- Industrial apparatuses
- Electrical testing equipment
Here is a connection diagram that can be used to interface the sensor with the Arduino
Connect the VCC, GND,& OUT pin of ZMPT101B to 5V, GND, & A0 of Arduino respectively.
AC Voltage Sensor Sample Program
7
8
9
Serial.println(analogRead(A0));
delay(100);
}
After uploading the code to your Arduino board, open the Serial Plotter from the Tools menu in the Arduino IDE. When nothing is connected to the module inputs, you should see a value of around 512 (2.5 volts) on the Serial Plotter. If you apply 220V AC to the input, you should see a sinusoidal voltage diagram on the Serial Plotter.
The Single Phase AC Voltage Module provides an analog output ranging from 0 to 1023, representing the measured voltage.
Turn the potentiometer on the module to get the most perfect sine wave possible, as in the following picture.
Note: Make sure the sine wave on the serial plotter is fully visible, including the
Source Code
Here is a sample code for interfacing the ZMPT101B Voltage Sensor module with Arduino.
Ac_Volt_Cal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
int adc_max = 0; // Variable to store the maximum sensor value
int adc_min = 1023; // Variable to store the minimum sensor value
long tiempo_init; // Variable to store the initial time
void setup() {
Serial.begin(115200); // Initialize the serial communication
tiempo_init = millis(); // Get the current time in milliseconds
}
void loop() {
if ((millis() - tiempo_init) > 500) { // Check if 500 milliseconds have passed
adc_max = 0; // Reset the maximum sensor value
adc_min = 1023; // Reset the minimum sensor value
tiempo_init = millis(); // Update the initial time
}
int sensorValue = analogRead(A0); // Read the analog input from pin A0
if (sensorValue > adc_max) {
adc_max = sensorValue; // Update the maximum value if a new maximum is found
} else if (sensorValue < adc_min) {
adc_min = sensorValue; // Update the minimum value if a new minimum is found
}
Upload the program: Ac_Volt_Cal
- This program is used to obtain calibration values for the sensor.
- Adjust the potentiometer to set the values of adc_max and adc_min .
- It is recommended to turn the potentiometer counterclockwise until adc_max reaches 700+.
- Take note of the values adc_max and adc_min .
- Use a multimeter to measure the AC voltage and record it.
Ac_Volt_inst
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
float volt_multi_p; // Peak voltage
float volt_multi_n; // Negative peak voltage
void setup() {
Serial.begin(115200);
volt_multi_p = volt_multi * 1.4142; // Peak voltage = RMS voltage * 1.4142 (
volt_multi_n = -volt_multi_p; // Negative peak voltage
}
void loop() {
float volt_rms = get_voltage(); // Root Mean Square voltage (V-RMS)
Serial.print("Vrms: ");
Serial.print(volt_rms, 3);
Serial.println(" VAC");
// Delay for a certain interval if needed
//delay(100);
}
float get_voltage() {
float adc_sample;
float volt_inst = 0;
float sum = 0;
float volt;
long init_time = millis();
int N = 0;
while ((millis() - init_time) < 500) { // Duration of 0.5 seconds (Approxima
adc_sample = analogRead(A0); // Sensor voltage
volt_inst = map(adc_sample, adc_min, adc_max, volt_multi_n, volt_multi_p);
sum += sq(volt_inst); // Sum of Squares
N++;
delay(1);
}
//Serial.print("N: ");
//Serial.println(N);
volt = sqrt(sum / N); // RMS equation
return volt;
}
Load the program: Ac_Volt_inst
- Set the values of adc_max and adc_min obtained from the calibration.
- Adjust the volt_multi variable to match the measured AC voltage (default is 222VAC).
Please note that this is just a basic overview. I will continue working on ZMPT101B and share my thoughts once I make more progress. I'm also interested to see if anyone else has made any new discoveries with this sensor module. Remember, expertise is for everyone!
Get structured datasheet data via API
Get started free