How to connect ZMPT101B to Arduino

How to connect zmpt101b to arduino

Summary

If you're interested in measuring AC voltage using an Arduino, then the ZMPT101B voltage sensor is a handy tool to have in your electronics kit. In this blog, you'll learn what the ZMPT101B voltage sensor is, how it works, the components required for connection, the connection diagram, how to interface the ZMPT101B with Arduino, and how to upload the code to read RMS voltage. Keep reading to learn how to get started with this essential sensor for any electronic project.

What is ZMPT101B Voltage Sensor?

ZMP101B is an AC Voltage Sensor used in DIY projects for measuring accurate AC voltage. It can be used with a whole host of microcontrollers with analog inputs such as the Arduino and ESP boards.

The output of the sensor is analog and the onboard potentiometer can be used to calibrate the output value specific to the microcontroller being used.

How does ZMPT101B work?

ZMPT101B uses a transformer to step down AC from the mains to a much lower voltage while preserving the waveforms and shapes to be used in calculations

The following diagram shows the internal structure of the ZMPT101B transformer

 

how to connect zmpt101b to Arduino

 

read more :  How 433MHz RF Module Works & Interfacing With Arduino

 

The input voltage from the AC mains (230V) will look like below

 

How does ZMPT101B voltage sensor work

 

The output voltage from the transformer (with 5V VCC) will look like below

 

zmpt101b to arduino

 

The output voltage should then be DC-biased by VCC/2 of the microcontroller being used. This can be accomplished with the onboard potentiometer.

For example, if Arduino is being used - which operated on VCC = 5V, the output voltage of the module needs to be offset by +2.5V, to ensure that the negative part of the AC cycle also falls on the positive side.

 

read more : Interfacing MAX30100 Pulse Oximeter with Arduino

DC-biased voltage output will look like below

 

connect zmpt101b to arduino

 

Similarly if ESP is being used - which operates on VCC = 3.3V, the output voltage needs to be DC-biased by +1.65V. More on how to calibrate will be later down in the guide (procedure section)

Note: Some reports have suggested that some modules may not work properly with 3.3V input directly from the ESP. In this case, try powering the module externally with a dedicated 3.3V supply (and make sure to make the GNDs common with the ESP)

In short:

The input AC voltage will be stepped down by the transformer to 0-5V (if VCC is 5V). The analog pin on the Arduino will measure voltage between 0-5V and map it to a number varying from 0-1023. These are the raw values obtained from the sensor. When no voltage is detected, ie 0V, the output Arduino reading should be 512 which would correspond to +2.5V

Components Required for Connection

For this guide, we will be using Arduino as the microcontroller to use the ZMPT101b amplifier.

The circuit is very simple, so the required components are very minimal and are as follows

  1. Arduino
  2. ZMPT101B
  3. Male to Male jumper wires

read more : Arduino Interfacing with Ultrasonic Sensor

Connection Diagram

The connections are quite straightforward and is as follows

S.no

Arduino

ZMPT101B

1

5V

VCC

2

GND

GND

3

A0

OUT

Note: Only connect one of the GND pins on the module.

Interfacing the ZMPT101B with Arduino

Calibration

Step 1: Connect the module to the Arduino as described above

Step 2: Copy the following simple analog read code below

    void setup() {
    Serial.begin(9600); 
    void loop() { 
    Serial.println(analogRead(A0)); 
    delay(100);
    }

     

    Step 3: Connect the Arduino to your PC, select the correct COM port and upload the code

    Step 4: Connect the AC supply to the L and N (live and neutral) terminals of the ZMPT101B.Be very careful while working with AC supply voltage.

    Step 5: Once connected, in Arduino IDE, go to Tools and open Serial Plotter.

    Step 6: If the connections are correct, you should be seeing a sinusoidal wave on the Serial Plotter, shown below

     

      connect zmpt101b to arduino

       

      <should preferably use our own digram from Arduino Serial plotter>

      • Ensure the waveform appears in full in the Serial plotter. In case the waveform looks like it is being clipped, adjust the onboard potentiometer till the waveform appears in full. This is a very important step, and after calibration, ensure that the potentiometer will not be further adjusted

      read more : Interfacing MPU-9250 9-DOF Sensor with Arduino

      <should have an example image of clipped waveform>

      Uploading the code to read RMS voltage

      • Once the above calibration is done, we can upload the code that calculates the correct RMS voltage value
      • Download the Filters library 
      • Install the library by going to Sketch > Manage Library > Add .zip file and browse for the downloaded file
      • Copy the code from below

      #include <Filters.h> //Easy library to do the calculations

       

      float testFrequency = 50;                     // test signal frequency (Hz)

      float windowLength = 40.0/testFrequency;     // how long to average the signal, for statistist

       

      int sensor = 0; //Sensor analog input, here it's A0

       

      float intercept = -0.04; // to be adjusted based on calibration testing

      float slope = 0.0405; // to be adjusted based on calibration testing

      float current_volts; // Voltage

       

      unsigned long printPeriod = 1000; //Refresh rate

      unsigned long previousMillis = 0;



      void setup() {

        Serial.begin(9600);    // start the serial port

        delay(5000);

      }

       

      void loop() {

        

        RunningStatistics inputStats;

        inputStats.setWindowSecs(windowLength);

         

        while(true) {   

          sensor = analogRead(A0);  // read the analog in value:

          inputStats.input(sensor);  // log to Stats function

              

          if((unsigned long)(millis() - previousMillis) >= printPeriod) {

            previousMillis = millis();   // update time every second

            

            // Calculations part

            

            current_volts = intercept + slope * inputStats.sigma();

            current_volts = current_volts*(40.3231);               

            

            Serial.print("\tVoltage: ");

            Serial.println(current_volts); //Displays the value

          }

        }

      }

      Upload the code and open the serial monitor

      Note: Some minor calibrations may be required to further bring the values closer to the actual values. If possible connect a TrueRMS multimeter and monitor the AC voltage simultaneously and try adjusting the slope and intercept variables to get a better result.

      For the above code, we make use of the Filters library to take care of the math and noise filtering that may be required to filter out noisy data received from the sensor

       

      read more : IR Sensor Interfacing with Arduino

       

      Conclusion

      In this blog post, we have learned that the ZMPT101B voltage sensor is a powerful tool for measuring RMS voltage in your electrical projects. By understanding how it works and the components required for connection, you can easily interface it with an Arduino to accurately measure voltage levels. With the help of our connection diagram and code, you can start experimenting with this versatile sensor right away. So why wait? Start exploring the potential of the ZMPT101B voltage sensor today and take your projects to the next level!

       

      If you appreciate our work don't forget to share this post and leave your opinion in the comment box.

       

      Please do check out other blog posts about Arduino Interfacing ACS712 with Arduino , Arduino Interfacing with Ultrasonic Sensor , LED Interfacing with Arduino , Interfacing GSM Module with Arduino , Interfacing MAX30100 Pulse Oximeter with Arduino , IR Sensor Interfacing with Arduino  and  How to use Buzzer with Arduino.

       

      Make sure you check out our wide range of products and collections (we offer some exciting deals!)

        Frequently Asked Questions

        1. What is ZMPT101B voltage sensor?

        The ZMPT101B voltage sensor is a small device that can detect single-phase AC voltage. It is capable of measuring AC voltage levels and is often used in do-it-yourself projects where precise measurements are necessary. This sensor can be connected to open-source platforms such as Arduino, ESP8266, and Raspberry Pi. It uses the high-precision voltage transformer from the ZMPT101B series.

        read more :  Arduino Sensor types and Applications

        2. How does ZMPT101B voltage sensor work?

        The ZMPT101B is an AC voltage sensor module that can measure AC voltages. Its output is analog and varies as the input voltage changes. The module uses a resistive voltage divider circuit-based DC voltage sensing device to generate an analog output. It typically operates at a rated current, and tutorials are available online for using it with microcontrollers.

        Back to blog

        Leave a comment

        Please note, comments need to be approved before they are published.

        You may also like to read