Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Lithium ION
Published © GPL3+

AC Power Monitoring Using BL0937 IC

A simple circuit to monitor AC power, Breakout board can be plugged anywhere and show voltage, current and power.

IntermediateFull instructions provided2 hours466
AC Power Monitoring Using BL0937 IC

Things used in this project

Story

Read more

Schematics

schematic_bl0937_2025-02-28_Wur6VNLMcb.pdf

Interfacing Circuit

Code

BL0937

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

volatile unsigned long pulseCountCF = 0;
volatile unsigned long pulseCountCF1 = 0;
unsigned long startTime;
const unsigned long interval = 1000; // Measurement interval in milliseconds

#define CF1_PIN 2    // Pin for CF1 signal (must be INT0)
#define CF_PIN 3   // Pin for CF signal (must be INT1)
#define SEL_PIN 4   // Pin for SEL control

LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27 for HW061 16x2 LCD

// Calibration factors (adjust manually based on measurements)
float voltageFactor = 0.083;  // Scaling factor for voltage conversion
float currentFactor = 0.00002; // Scaling factor for current conversion
float powerFactor = 0.65;    // Scaling factor for power conversion

void pulseISR_CF1() {
  pulseCountCF1++; // Increment CF pulse count
}

void pulseISR_CF() {
  pulseCountCF++; // Increment CF1 pulse count
}

void setup() {
  Serial.begin(9600);
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Initializing...");
  delay(2000);
  lcd.clear();

  pinMode(CF1_PIN, INPUT);
  pinMode(CF_PIN, INPUT);
  pinMode(SEL_PIN, OUTPUT);
  attachInterrupt(digitalPinToInterrupt(CF1_PIN), pulseISR_CF1, RISING);
  attachInterrupt(digitalPinToInterrupt(CF_PIN), pulseISR_CF, RISING);
  startTime = millis();
}

void loop() {
  if (millis() - startTime >= interval) {
    digitalWrite(SEL_PIN, LOW);
    delayMicroseconds(10); // Allow signal stabilization
    float currentFrequency = (pulseCountCF1 * 1000.0) / interval;
    float currentRMS = currentFrequency * currentFactor;


    digitalWrite(SEL_PIN, HIGH);
    delayMicroseconds(10); // Allow signal stabilization
    float voltageFrequency = (pulseCountCF1 * 1000.0) / interval;
    float voltageRMS = voltageFrequency * voltageFactor;
    Serial.print("Voltage: ");
    Serial.print(voltageRMS);
    Serial.println(" V");

    float powerFrequency = (pulseCountCF * 1000.0) / interval;
    float powerRMS = powerFrequency * powerFactor;
    Serial.print("Power: ");
    Serial.print(powerRMS);
    Serial.println(" W");
    float currentNEW = (powerRMS / voltageRMS);

    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("V:");
    lcd.print(voltageRMS);
    lcd.print("V");
    lcd.setCursor(0, 1);
    lcd.print("I:");
    lcd.print(currentNEW);
    lcd.print("A");
    delay(4000);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("P:");
    lcd.print(powerRMS);
    lcd.print("W");
    delay(2000);

    pulseCountCF = 0;
    pulseCountCF1 = 0;
    startTime = millis();
  }
}

Credits

Lithium ION
59 projects • 38 followers
A passionate electronics DIY boy. Currently improving in Embedded systems, soldering and programming.
Contact

Comments

Please log in or sign up to comment.