## What is ZMPT101B Voltage Sensor?

##### Note

## ZMPT101B Voltage Module Pinout

ZMPT101B module has 4 pins:

**VCC:**Module power supply: 5 V**GND:**Ground**OUT:**Module output which is analog.

You can see Pinout of this module in the following image.

## Required Materials

### Hardware Components

### Software Apps

## Interfacing ZMPT101B Voltage Sensor with Arduino

### Step 1: Circuit

Connect the module to the Arduino according to the following image.

##### Warning

### Step 2: Code 1

Upload the following code to your Arduino and then open the **Serial plotter** window from the **Tools** menu. If nothing is connected to the module inputs (module input is 0 volts), your diagram will show a number around 512 (i.e. 2.5 volts).

If you apply 220V AC to the input, you will see a voltage sinusoidal diagram on the **Serial plotter**.

```
/*
ZMPT101B - AC Voltage sensor
Show AC wava in serial plotter
modified on 7 Sep 2020
by Mohammad Reza Akbari @ Electropeak
```Home

*/
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
Serial.println(analogRead(A0));
delay(100);

##### Note

Make sure the sine wave is complete in the serial plotter, specifically the minimum and maximum parts of the chart. If your voltage pattern is not complete, you have to turn the potentiometer on the module to display the full waveform.

If the waveform is cut from the top or bottom, you will see an error in your measurement in the next step.

### Step 3: Code 2

This module measures the peak-to-peak voltage. In this code, first it finds the maximum measured value (peak voltage) and then converts it to RMS value. You can see the result in the Serial Monitor.

```
/*
ZMPT101B - AC Voltage sensor
Calculate Voltage
modified on 7 Sep 2020
by Mohammad Reza Akbari @ Electropeak
```Home

*/
double sensorValue1 = 0;
double sensorValue2 = 0;
int crosscount = 0;
int climb_flag = 0;
int val[100];
int max_v = 0;
double VmaxD = 0;
double VeffD = 0;
double Veff = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
for ( int i = 0; i < 100; i++ ) {
sensorValue1 = analogRead(A0);
if (analogRead(A0) > 511) {
val[i] = sensorValue1;
}
else {
val[i] = 0;
}
delay(1);
}
max_v = 0;
for ( int i = 0; i < 100; i++ )
{
if ( val[i] > max_v )
{
max_v = val[i];
}
val[i] = 0;
}
if (max_v != 0) {
VmaxD = max_v;
VeffD = VmaxD / sqrt(2);
Veff = (((VeffD - 420.76) / -90.24) * -210.2) + 210.2;
}
else {
Veff = 0;
}
Serial.print("Voltage: ");
Serial.println(Veff);
VmaxD = 0;
delay(100);
}

You can see the results for measuring city electricity voltage in the figure below.

## Comments (27)

Abhishekhow the following formula is derived>?can you please explain?

Veff = (((VeffD – 420.76) / -90.24) * -210.2) + 210.2;

Mehran MalekiHello.

It’s actually a formula to calculate the input voltage RMS by using the maximum value of the sensor output voltage. And here’s how it’s derived: The graph of the sensor output voltage when it has the city electricity as its input is given as the result of the first code. You can see that the maximum voltage is somewhere around 600. And we already know that the input voltage RMS is 220V. First, the peak value of the sensor output voltage is divided by sqrt(2). -Since it is needed for calculating the RMS- Then the rest is just a linear transformation to get an output around 220 from the sensor output voltage.

FayyazAs salam alaikm dear

Fayyaz Hussain Here

I want to ask that what is the output of Module in form of DC voltages or AC if any one then what is the Mini and Max value of the Module for Arduino to formulate and display On LCD

like

220 AC voltage vs Module output voltage

Thanks

Mehran MalekiHi. As you can see in the article, the image of the output of this module is provided -right above the “step 3” section-. And you can see that the output is actually an AC voltage. In order to calculate the input AC Voltage, you need to find the maximum of the output -Vmax_v- and use the formula given in the second code -“step 3” section-.

ShaanHello

Can you please explain the linear formula you have given. I didnt understand your explanation on that in the commwnt section as well.

Thanks.

NasriI wont to ask you for using zmpt101b for mesuring up to 400v

Mehran MalekiHi,

As you can see in the first section of the tutorial, the ZMP101b module can only measure AC voltages up to 250 volts. So, I’m afraid it’s not suitable for your application.

A.SHi,

I have a question about analog output. The value for out put is sth between 0-5 V. in this situation if I connect the module to 120V and 230V, what we will be the value of output?

Thank you.

Mehran MalekiHi,

As you said, the output will be between 0 and 5 volts, but I can’t say the exact value. You need to test that yourself.

helal gamalcan i use this code with esp32?? if i cannt so what is the suitble code can i use?

Mehran MalekiYes, you can use almost the same code for ESP32. All you need to change is to replace “A0” in line 28 and 29 with any of the pins of ESP32. Also make sure you connect the output of the sensor to that particular pin.

Daniel Carboneis there any change in the code for standard 120v

Mehran MalekiHi.

Yes, you actually need to rewrite most of the formulas. First, you should use code 1 to get the maximum of the output voltage of the sensor. Then, you need to derive a formula between that maximum value and the RMS of the input voltage and use it in code 2.

david buiHow would you derive a formula please and thank you

Mehran MalekiHi,

It is already answered in the previous comments. This one might be good for you: “This is how it’s derived: The graph of the sensor output voltage when it has the city electricity as its input is given as the result of the first code. You can see that the maximum voltage is somewhere around 600. And we already know that the input voltage RMS is 220V. First, the peak value of the sensor output voltage is divided by sqrt(2). -Since it is needed for calculating the RMS- Then the rest is just a linear transformation to get an output around 220 from the sensor output voltage.”

You can do the same process for standard 120V.

HariHello, nice tutorial I tried your code and it’s Woking very well. What is the cause that the sensor can’t measure more than 250v? In the datasheet of zmpt101b transformer, it says it can measure upto 1000v.

SadevHi.. Can you please explain more about how to derive each value of the equation.. [Veff = (((VeffD – 420.76) / -90.24) * -210.2) + 210.2]. I’m try to implement 3 phase voltage meter using esp32.. I also note that the value you get as 511 is different when we consider esp32 since its ADC is 4096.. It would be highly appreciate, if you can give me a hand.. Thanks

Mehran MalekiHi,

The question you’re asking is almost the same as an older comment. So, I give you the same answer.

“It’s actually a formula to calculate the input voltage RMS by using the maximum value of the sensor output voltage. And here’s how it’s derived: The graph of the sensor output voltage when it has the city electricity as its input is given as the result of the first code. You can see that the maximum voltage is somewhere around 600. And we already know that the input voltage RMS is 220V. First, the peak value of the sensor output voltage is divided by sqrt(2). -Since it is needed for calculating the RMS- Then the rest is just a linear transformation to get an output around 220 from the sensor output voltage.” Ask me if you need any further information. And about ESP32, you need to replace 511 with 2050. Also, remember that ESP32 is a 3.3V microcontroller and 4096 means 3.3V.

Tamer SalmemHello!

I have a 120V 60Hz power network.

I cannot adjust the potentiometer, even after 1 hora spinning for both directions. The wave form doesn’t change at all.

Would you have any tip to help me?

Thank you!

Mehran MalekiHi,

The potentiometer on this module is multi-turn. So, you probably need to turn it more to see a difference in the output wave form.

halawhat would i change to measure 2 volts ?

Mehran MalekiHi.

As you can see in the article, this module is designed to measure high voltages up to 250V. So. you can’t use it to measure 2 volts. Actually, to measure 2 volts, you don’t need to use any module. You can directly connect that wire to any of the analog pins of your Arduino board and use the “analogRead()” function to measure the voltage.

Fatah Ridha BaskaraHello.

I use 2 moduls ZMPT to measure AC voltage, can you help me to explain more about using this moduls in one project?

thank you for being willing to help

Mehran MalekiHi.

What exactly is your problem? There is no significant difference between interfacing one ZMPT101B module and two ZMPT101B modules with Arduino. You just need to use two analog pins to read the output of your modules.

BadarDoes it also calculate Current???

Mehran MalekiHi.

Actually, no, it can only measure AC voltage. For measuring current, you can use the following tutorials:

https://electropeak.com/learn/interfacing-acs712-current-module-with-arduino/

https://electropeak.com/learn/interfacing-ina219-current-sensor-module-with-arduino/

https://electropeak.com/learn/interfacing-zmct103c-5a-ac-current-transformer-module-with-arduino/

SalomónHi! I am working whit this module and a ESP32. I already read the above comments, but i do not understand the changes that i have to make in this line: Veff = (((VeffD – 420.76) / -90.24) * -210.2) + 210.2;

Where did the conversion for the 12 bits work for the ESP32? I also change the 511 for the 2050 that i read in the answers.

Thank you!