How to connect ZMPT101B to Arduino

Welcome! Today we will have detailed information over what the ZMPT101B sensor is? How does it work and how does it interface with Arduino? Let's begin!

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

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.

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

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

      <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

      Also Read - Interfacing Proximity Sensors with Ardunio

      Conclusion

      ZMPT101B is a low cost DIY way to measure and monitor AC voltage. It can be further paired up with displays and LCD to make yourself a mini AC voltmeter with loads of functionality and customizability. Further it can be integrated into larger projects where an accurate monitoring of an AC voltage source is required

        Leave a comment

        Please note, comments must be approved before they are published