Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO and ZMPT101B-Based AC Voltage Monitor with I2C LCD Display

View and Edit Project In Cirkit DesignerImage of Arduino UNO and ZMPT101B-Based AC Voltage Monitor with I2C LCD Display

Circuit Documentation

Summary

This circuit is designed to measure and display the AC voltage using a ZMPT101B voltage sensor and an Arduino UNO. The measured voltage is displayed on a 16x2 I2C LCD, and a buzzer is activated if the voltage goes out of a specified range. The circuit is powered by a 220V AC power source.

Component List

ZMPT101B

Arduino UNO

16x2 I2C LCD

Power 220V

Wiring Details

ZMPT101B

Arduino UNO

16x2 I2C LCD

Power 220V

Code Documentation

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

// Create an LCD object. Adjust the address (0x27 or 0x3F) based on your module.
LiquidCrystal_I2C lcd(0x27, 16, 2);

const int voltagePin = A0; // ZMPT101B output connected to A0
const int buzzerPin = 8;   // Buzzer connected to digital pin 8

// Voltage thresholds
const float voltageHighThreshold = 250.0; // High voltage limit (in volts)
const float voltageLowThreshold = 180.0;  // Low voltage limit (in volts)

// Calibration factor for ZMPT101B
const float calibrationFactor = 110.0;

// Voltage detection threshold
const float detectionThreshold = 10.0; // Voltage (in volts) to detect live AC

void setup() {
  pinMode(buzzerPin, OUTPUT);
  digitalWrite(buzzerPin, LOW); // Start with buzzer off
  lcd.init();                   // Initialize the LCD
  lcd.backlight();              // Turn on LCD backlight
  Serial.begin(9600);

  // Display initial message
  lcd.setCursor(0, 0);
  lcd.print("Voltage: 0V");
  lcd.setCursor(0, 1);
  lcd.print("Waiting for AC...");
}

void loop() {
  // Measure RMS voltage
  float rmsVoltage = measureRMSVoltage();

  // Measure instantaneous AC voltage
  float acVoltage = measureACVoltage();

  // Check if AC voltage is detected
  if (rmsVoltage > detectionThreshold) {
    // Display live voltage
    lcd.setCursor(0, 0);
    lcd.print("AC: ");
    lcd.print(acVoltage, 1);  // Display AC voltage
    lcd.print("V    ");       // Clear remaining characters

    lcd.setCursor(0, 1);
    lcd.print("RMS: ");
    lcd.print(rmsVoltage, 1); // Display RMS voltage
    lcd.print("V    ");       // Clear remaining characters

    // Check voltage thresholds and activate buzzer if out of range
    if (rmsVoltage > voltageHighThreshold || rmsVoltage < voltageLowThreshold) {
      digitalWrite(buzzerPin, HIGH); // Turn on buzzer
      Serial.println("Voltage out of range! Buzzer activated.");
    } else {
      digitalWrite(buzzerPin, LOW); // Turn off buzzer
    }
  } else {
    // If no significant voltage is detected, display "Waiting for AC"
    lcd.setCursor(0, 0);
    lcd.print("Voltage: 0V   "); // Show "0V" when no AC is detected
    lcd.setCursor(0, 1);
    lcd.print("Waiting for AC...");
    digitalWrite(buzzerPin, LOW); // Ensure buzzer is off
  }

  delay(500); // Wait before next reading
}

// Function to measure RMS voltage using ZMPT101B
float measureRMSVoltage() {
  const int sampleCount = 500; // Number of samples for RMS calculation
  float sum = 0.0;

  // Collect multiple samples
  for (int i = 0; i < sampleCount; i++) {
    int rawValue = analogRead(voltagePin);
    float voltage = (rawValue / 1023.0) * 5.0; // Convert to actual voltage (5V reference)
    float centeredVoltage = voltage - 2.5;    // Remove DC offset
    sum += centeredVoltage * centeredVoltage;
    delay(1); // Small delay for stability
  }

  // Calculate RMS
  float meanSquare = sum / sampleCount;
  float rmsVoltage = sqrt(meanSquare) * calibrationFactor;
  return rmsVoltage;
}

// Function to measure instantaneous AC voltage (waveform)
float measureACVoltage() {
  int rawValue = analogRead(voltagePin);
  float voltage = (rawValue / 1023.0) * 5.0; // Convert to actual voltage (5V reference)
  return voltage * calibrationFactor;       // Scale by calibration factor
}

This code initializes the LCD and sets up the pins for the voltage sensor and buzzer. It continuously measures the RMS and instantaneous AC voltage, displays the values on the LCD, and activates the buzzer if the voltage is out of the specified range.