Source: https://mokxi.com/libraries/zmpt101b
Updated: 2026-11-02

Libraries / Sensors
Arduino library · Sensors

# ZMPT101B: AC voltage as an RMS reading

The ZMPT101B is a small voltage transformer on a module with an op-amp and a trimmer. It isolates a mains-voltage input and puts out a small AC wave centered on half the board’s supply, which an analog pin can sample. The ZMPT101B library by Abdurraziq Bachmid samples that wave over whole cycles and returns its RMS voltage, the number a multimeter shows.

Open the example in the editor See the calls

Built in on Mokxi: #include <ZMPT101B.h> and it builds, with nothing to install. Free, and no account needed.

## What ZMPT101B does

The library has to know the mains frequency to sample whole cycles, so it is the second argument of the constructor: 50 Hz in Europe, Asia and Africa, 60 Hz in North America. The sensitivity, set with setSensitivity(), stands for the module’s trimmer position, and it is found by comparing the reading with a trusted meter and adjusting until they agree.

Mains voltage can kill. The module’s input side carries the full line voltage on exposed pins, so build and calibrate it in an enclosure, with a fused supply, or try the circuit in a simulator first. The board side is isolated by the transformer, but the screw terminals are not.

Library Manager name | ZMPT101B

Author | Abdurraziq Bachmid

Include | #include <ZMPT101B.h>

Boards | Arduino Uno, Arduino Nano, Arduino Mega 2560, Arduino Leonardo, SparkFun Pro Micro, Arduino Micro, Arduino Pro Mini 3.3 V, ESP8266 NodeMCU, ESP32 DevKit, ESP32-DevKitC V4, LOLIN32 Lite, Wemos D1 R32, Cheap Yellow Display, TTGO T-Display, ESP32-S3-DevKitC-1, Seeed XIAO ESP32-S3, Arduino Nano ESP32, Seeed XIAO ESP32-C3, Seeed XIAO ESP32-C6

In the simulator | Simulated: it runs against the part the way it does on the bench.

Parts it drives | AC voltage sensor, ZMPT101B

## Install it

It builds on Arduino Uno, Arduino Nano, Arduino Mega 2560, Arduino Leonardo, SparkFun Pro Micro, Arduino Micro, Arduino Pro Mini 3.3 V, ESP8266 NodeMCU, ESP32 DevKit, ESP32-DevKitC V4, LOLIN32 Lite, Wemos D1 R32, Cheap Yellow Display, TTGO T-Display, ESP32-S3-DevKitC-1, Seeed XIAO ESP32-S3, Arduino Nano ESP32, Seeed XIAO ESP32-C3, Seeed XIAO ESP32-C6.

In Mokxi it is built in: #include <ZMPT101B.h> and the sketch compiles, with no download, no zip and no Library Manager.

On a real board, install "ZMPT101B" by Abdurraziq Bachmid from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add ZMPT101B to lib_deps in PlatformIO. Mokxi follows the calls of release 1.0.1, so a sketch written here builds there too.

What to know in the simulator: The sensitivity is the part’s trimmer setting (its ratio), which a real board is calibrated for against a meter.

Arduino Uno · Arduino Nano · Arduino Mega 2560 · Arduino Leonardo · SparkFun Pro Micro · Arduino Micro · Arduino Pro Mini 3.3 V · ESP8266 NodeMCU · ESP32 DevKit · ESP32-DevKitC V4 · LOLIN32 Lite · Wemos D1 R32 · Cheap Yellow Display · TTGO T-Display · ESP32-S3-DevKitC-1 · Seeed XIAO ESP32-S3 · Arduino Nano ESP32 · Seeed XIAO ESP32-C3 · Seeed XIAO ESP32-C6

## The calls you will use

In the order a sketch meets them.

### ZMPT101B voltageSensor(A0, 50.0)

Creates the sensor on A0 for a 50 Hz supply. Use 60.0 for 60 Hz.

### voltageSensor.setSensitivity(500.0f)

Sets the sensitivity that matches your module’s trimmer. Adjust it until the reading agrees with a meter.

### float v = voltageSensor.getRmsVoltage()

Samples whole cycles and returns the RMS voltage.

### voltageSensor.getRmsVoltage(10)

Averages over ten cycles for a steadier number.

## Example: Mains RMS voltage from a ZMPT101B

On the Arduino Uno R3. It runs in the browser exactly as printed.

sketch.ino · Arduino Uno R3

### Wiring

- Arduino Uno R3 A0 to AC voltage sensor, ZMPT101B OUT
- Arduino Uno R3 5V to AC voltage sensor, ZMPT101B VCC
- Arduino Uno R3 GND to AC voltage sensor, ZMPT101B GND

Open it in the editor, wired and ready to run

## Common errors and how to fix them

### The voltage reads far too high or too low

The sensitivity does not match the trimmer. Measure the mains with a multimeter, then raise or lower the value passed to setSensitivity() until the two agree, and do not touch the trimmer afterwards.

### It reads a few volts with nothing plugged in

That is noise on the analog pin. Keep the module’s wires short, power it from the same supply as the board, and treat readings under about 10 V as zero in the sketch.

### Readings wobble by several volts

The frequency in the constructor is wrong for your country, so the library cuts cycles in the middle. Use 50.0 or 60.0 to match the mains.

## Keep going

### Learn

- Arduino PZEM-004T and ZMPT101B AC Energy Meter
- Arduino 0-25 V Voltage Sensor: Wiring and Code

### Parts

- AC voltage sensor, ZMPT101B

### More sensors libraries

- DHT sensor library
- DHT20
- VL53L0X
- Adafruit_VL53L0X
- HX711 Arduino Library
- MPU6050
- Adafruit MPU6050
- BME280

Every built-in library · Open the editor

## Try ZMPT101B without installing anything

Open the example, change the sketch, and keep your version in a free account.

Start building free

Open the editor
