Interfacing ZMPT101B Voltage Sensor with Arduino

Table of Contents

What is ZMPT101B Voltage Sensor?

The ZMPT101B is a voltage transformer used to measure AC voltage. You can measure AC voltages up to 250 volts by using this module. The output of this sensor is analog. if you change input voltage, the output voltage will change as well.
Note
When there is no load on output (nothing is connected to infput), the sensor has an initial voltage (Offset) of VCC/2. That is, if nothing is connected to the input and the supply voltage of the module is 5 volts, the output of the module will be 2.5 volts.
ZMPT101B voltage sensor module

You can download the ZMPT101B voltage sensor datasheet here.

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

Arduino UNO R3 × 1
ZMPT101B AC Voltage Sensor Module × 1
Male to Female jumper wire × 1

Software Apps

Arduino IDE

Interfacing ZMPT101B Voltage Sensor with Arduino

Step 1: Circuit

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

Warning
Be aware of safety tips when you connect the input voltage (e.g. 220 volts).

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.

Liked What you see?

Get updates and learn from the best

More To Explore

Comments (34)

  • Abhishek Reply

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

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

    March 19, 2021 at 6:17 am
    • Mehran Maleki Reply

      Hello.
      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.

      March 22, 2021 at 4:44 pm
  • Fayyaz Reply

    As 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

    May 19, 2021 at 3:18 pm
    • Mehran Maleki Reply

      Hi. 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-.

      May 22, 2021 at 8:43 am
      • Shaan Reply

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

        April 3, 2022 at 3:39 pm
  • Nasri Reply

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

    August 16, 2021 at 5:36 pm
    • Mehran Maleki Reply

      Hi,
      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.

      August 17, 2021 at 9:00 am
  • A.S Reply

    Hi,
    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.

    October 29, 2021 at 2:05 pm
    • Mehran Maleki Reply

      Hi,
      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.

      October 31, 2021 at 6:37 am
  • helal gamal Reply

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

    November 15, 2021 at 9:08 pm
    • Mehran Maleki Reply

      Yes, 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.

      November 16, 2021 at 8:35 am
  • Daniel Carbone Reply

    is there any change in the code for standard 120v

    December 1, 2021 at 4:09 pm
    • Mehran Maleki Reply

      Hi.
      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.

      December 4, 2021 at 6:36 am
      • david bui Reply

        How would you derive a formula please and thank you

        March 17, 2022 at 9:19 pm
        • Mehran Maleki Reply

          Hi,
          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.

          March 19, 2022 at 8:08 pm
          • Hari

            Hello, 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.

            June 14, 2022 at 11:12 am
  • Sadev Reply

    Hi.. 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

    December 4, 2021 at 3:17 am
    • Mehran Maleki Reply

      Hi,
      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.

      December 4, 2021 at 6:30 am
  • Tamer Salmem Reply

    Hello!
    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!

    December 11, 2021 at 4:50 pm
    • Mehran Maleki Reply

      Hi,
      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.

      December 13, 2021 at 5:43 am
  • hala Reply

    what would i change to measure 2 volts ?

    December 17, 2021 at 10:43 pm
    • Mehran Maleki Reply

      Hi.
      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.

      December 18, 2021 at 6:45 am
  • Fatah Ridha Baskara Reply

    Hello.
    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

    January 11, 2022 at 4:00 am
    • Mehran Maleki Reply

      Hi.
      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.

      January 11, 2022 at 5:57 am
  • Badar Reply

    Does it also calculate Current???

    January 16, 2022 at 8:33 am
  • Salomón Reply

    Hi! 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!

    August 22, 2022 at 8:50 pm
  • Glenn Reply

    Can the analog output be used to determine frequency and count cycles to detect a cycle drop or glitch ?

    December 21, 2022 at 7:13 pm
    • Ali Abdolmaleki Reply

      Hi dear
      yes it can. you need a zero crossing unit to estimate every period of wave for frecuency measurment.
      just read analog measurment when signal is equal to zero.

      February 28, 2023 at 3:19 pm
  • Abhishek Reply

    Hi
    Can You please help me how I can use this conversion with raspberry Pi 3 .
    Please suggest how should I calibrate the analog value using raspberry Pi 3?

    January 1, 2023 at 6:33 pm
  • Bimoputra Reply

    Hi
    I am getting strange results, when there is no 650V mains, when there is 830V mains. Where did the error occur?

    January 23, 2023 at 2:49 am
    • Ali Abdolmaleki Reply

      Hi dear
      this module is used for AC Voltage
      Are your sure about the AC/DC Voltage?
      Please note that the maximum measurable range of this module is 250VAC

      February 28, 2023 at 2:20 pm
  • John Reply

    Hello.
    I want to measure energy consumption without using the software, only to be displayed on the LCD, is it Possible?

    February 17, 2023 at 7:21 pm

Leave a Reply

Your email address will not be published. Required fields are marked *