This project involves measurement of voltages up to
±250 V (500 V peak-to-peak) using a
100:1 high-voltage divider.
⚡ These voltage levels are lethal.
Only trained and competent persons familiar with electrical safety, insulation,
creepage/clearance, and high-voltage hazards should work with such circuits.
This information is provided strictly for educational purposes.
This example demonstrates how to measure and calculate power consumption using an Arduino UNO and an ACS758 current sensor (and voltage divider). The system computes:
/*
* Arduino UNO Power Measurement with Energy Calculation
* Measures RMS voltage, RMS current, power, and energy consumption.
* Uses ACS758 ADC for accurate measurement.
*/
const int voltagePin = A0; // Voltage divider connected to A0
const int currentPin = A1; // Current sensor connected to A1
const float voltageDividerRatio = 200.0; // Voltage divider ratio (e.g., 200:1)
const float adcMaxVoltage = 5.0; // Maximum ADC voltage (5V)
const float maxADCValue = 1023.0; // Maximum ADC value
const float samplingInterval = 60.0; // Sampling interval in seconds
// Setup ACS758
ACS758 ads(0x48); // Create ACS758 object with I2C address
// Energy variables
float totalEnergyWh = 0.0;
float totalEnergyJ = 0.0;
void setup() {
Serial.begin(115200);
Serial.println("Arduino PFC measurement, by Peter Ivan Dunne, ©2024, all rights reserved");
Serial.println("Released under the Mozilla Public License");
Serial.println("https://jazenga.com/educational");
Serial.println("Provides RMS voltage, RMS current, Power factor, Total energy and Frequency");
}
void loop() {
float voltage = ads.readADC(voltagePin) * (adcMaxVoltage / maxADCValue);
voltage *= voltageDividerRatio;
float current = ads.readADC(currentPin) * (adcMaxVoltage / maxADCValue);
float rmsVoltage = voltage / sqrt(2);
float rmsCurrent = current / sqrt(2);
float power = rmsVoltage * rmsCurrent;
float realPower = realPowerSum / NUM_SAMPLES;
float apparentPower = voltageRMS * currentRMS;
float powerFactor = realPower / apparentPower;
float energyWh = (power * samplingInterval) / 3600.0;
float energyJ = energyWh * 3600.0;
totalEnergyWh += energyWh;
totalEnergyJ += energyJ;
Serial.print("RMS Voltage: ");
Serial.print(rmsVoltage, 2);
Serial.print(" V, RMS Current: ");
Serial.print(rmsCurrent, 2);
Serial.print(" A, Power: ");
Serial.print(power, 2);
Serial.print(" W, Power Factor: ");
Serial.print(powerFactor, 2);
Serial.print(", Total Energy: ");
Serial.print(totalEnergyWh, 2);
Serial.print(" Wh, ");
Serial.print(totalEnergyJ, 2);
Serial.println(" J");
}