AC Energy Logger

For the discussion of Arduino related topics.

Moderator: phalanx

AC Energy Logger

Postby Matsume » Fri Oct 06, 2017 5:46 am

Hey Guys,

I've attached my circuit diagram below. I'm trying to build an energy logger which measures both voltage and current, but I've been experiencing some difficulties with measuring both of them.

Both the voltage and current keeps changing. I tried to get an average of the samples but it still doesn't remain constant. Maybe my program is wrong, I'm not sure what's wrong anymore.

I've placed the code below, Please check it out & help me find the main problem with it & the circuit diagram.


Here's my code:
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 7, 6, 5, 4);
int volt=A2;

float vin=0,num,input,ana,out;

void setup()
// put your setup code here, to run once:
lcd.begin(16, 2);


void loop()
// put your main code here, to run repeatedly:


void voltage()

num = analogRead(A2);


(92.78 KiB) Downloaded 12 times
Posts: 2
Joined: Sat Feb 18, 2017 12:37 pm

Re: AC Energy Logger

Postby DanV » Fri Oct 06, 2017 6:39 am

Make sure you have a delay after analogRead(A2) - before you analogRead(A0).
The site says :
"It takes about 100 microseconds (0.0001 s) to read an analog input, so the maximum reading rate is about 10,000 times a second. "

I just noticed that you're measuring current from an AC source.
That's likely to vary in magnitude especially if your filter cap is sized poorly.

And you're measuring voltage from a rectified AC source.
You surely can't expect that to not fluctuate widely without applying some smoothing capacitors.
Posts: 262
Joined: Sat Apr 25, 2015 9:29 am

Re: AC Energy Logger

Postby jremington » Fri Oct 06, 2017 8:59 am

See the great tutorial on the OpenEnergyMonitor site for other ideas on how to do AC line energy monitoring, safely and properly. ... gy-monitor
Support Volunteer
Posts: 2053
Joined: Fri Jun 15, 2007 9:41 pm
Location: Eugene, Or

Re: AC Energy Logger

Postby Anthony Fremont » Wed Oct 11, 2017 6:52 am

jremington wrote:See the great tutorial on the OpenEnergyMonitor site for other ideas on how to do AC line energy monitoring, safely and properly. ... gy-monitor
Great isn't a big enough word. That looks like a thesis for someone working on a PHD. I spent hours pouring through that. Thanks

Sent from my Moto G (4) using Tapatalk
Anthony Fremont
Posts: 23
Joined: Fri Oct 12, 2007 6:25 am

Return to Arduino

Who is online

Users browsing this forum: No registered users and 1 guest