ARDUINO PROJECT: POWER MONITOR
Posted by kll on February 21 2013 22:58:54

Reading grid AC Volt and Ampere by a Arduino.

For isolation from AC level use transformer.


to get a AC measuring range use a virtual "NULL" 2V5
by a 5V divider, because tests with diode bridge after a current transformer ( 1 : 1000 )
did not work.

there is a good project for power monitoring online and
i run that software from EMON

its a statistic approach ( evaluate 3000 samples )
with RMS calc
i have some problems with real / apparent power, and get sometimes negative values

but for me i try first my scope software, then my serial menu software
combined them and improved the scope
but i also made it little bit slower,
i want to see in the one channel zoom window 5 sinus of 50Hz mains
as 512 samples ( 103 samples per sinus ) whats a sample rate of 5200Hz
and that gives a nice FFT also.

for the EMON tool, what i included also as default program
( reporting to USB ( terminal ))
i made a simulation in a ONLINE EXCEL ( public read write !!) EMON SIMULATION
have fun playing with it.

running EMON in Arduino i see 3000 samples need 1126 millis
thats 53 samples per 50 Hz sinus,
and 56.3 sinus together
whats a sample rate of 2664 Hz.
( sampling Volt and AMP, 2 Ain channel )


when i start the processing sketch on the arduino menu
the scope data transfer starts



each channel has a ZOOM button to transport a batch of fast one channel data
to a ZOOM window, calculates the FFT, shows the scope and FFT,
and saves data to CSV file

here the ZOOM of the VOLT



in the diag window a print of the first 10 FFT frequency amplitudes



here the ZOOM of the AMP to a LAMP with a DIMMER



and the CSV data file opened by CALC




in V0.3 of power meter i use a batch version of EMON reading Ain 1 ..5 for 5 consumer
shield layout , shield front , shield back

an other application, EMON with uSD card data storage
using the DFRobot interface shield and 4GB uSD card
shows EMON all 5 sec ( on terminal ) and store to uSD card all minute.



in a updated revision use Vcc_read to calibrate EMON


here the code
of POWER_meter_kll_V03 ( NOW arduino 1.0 and processing 1.5.1 (rev 0.3c) )

for the next step on this project, connecting a modem and send SMS ( and data) pls read at ARDUINO PROJECT: SERIAL LINK

hi, we are back, MODEM is connected on V5, D2(in), D3(out), GND,
using NEW SOFT SERIAL
and working on uSD_power_meter_kll_V08
at the first start there where some problems with SD init fails
the interface shield connects D3 to some ports, but SD is not using it.
( with the LCD.. connected there would be conflicts )
the power dropped as i run on USB, extremly when MODEM goes on air.
consumption is 20mA base and 80mA when activ.
need new arduino powersupply.

i read in the software from some GSM shields that they can power OFF ON the modem
by Dout, good idea to have a FLIGHT MODUS for my ARDUINO
if i dont find a AT command for that spec modem could use a relay to switch 5V supply.

the next software steps:
.. running low on SRAM i must save all diagnostic texts and all MODEM AT commands to FLASH
.. the modem SMS test was just a sending of AT commands, need a check routine for the MODEM answers
.. to send a ALARM SMS we need to define alarm limits on the measuring data
.. in menu a entry for test the sms's

here the code uSD_POWER_meter_kll_V08

a other idea is to feed the data via MODEM to a sql database in internet.
for this i want to use a test site with a installation of the CMS PHP-Fusion

for the new version V 7.02.03 of PHP-Fusion i made a new revision of my TABLE TOOL
( a project started 2007 about a data table tool, where no coding is needed,
using the GUEST, MEMBER, ADMIN, SUPER ADMIN structure of that CMS
a table ( existing or NEW ) can be configured as data source,
and view, detail and edit rights can be given for all 4 LEVEL.)

now i added a possibility for a modem to feed a string to a input field
and this is separated by "," checked on access right and stored as a new row in the selected database, a EMON table.


back to ARDUINO and MODEM
i could not find any code that worked for that modem to
connect to internet, despite its called a GPRS modem.

________________________________________________________

again play with EMON, grid power measurement
but from a different viewpoint,
if some more analyzing tools are needed,
a new version of EMON,
-- EMON ( Volt A0, Current A1 )
-- FFT of A0 ( in Arduino )
-- with Serial print A0
-- with Serial print A0,A1
! EMON and FFT can run alternating !
optional sampling and processing time / Hz can be displayed
or just show A0 .. A5

++ EMON sample length ( 3000) adjustable
++ FFT can have a microseconds delay adjusted
_ its a 128 sample FFT what needs about 16.5 msec for sampling.
_ one 50Hz sinus is 20ms, so to calibrate the FFT to see 2 sinus
_ in that 128 samples, slow it down by add 184usec delay after analog in.
_ ! RESULT: 0,0,30,0 == 0 + 0*sin(25Hz) + 30*sin(50Hz) + 0*sin(75Hz)
tuning tool
+++ a 2 channel scope with
zoom function ( 512 samples , about 4 of 50Hz sinus )
as Processing ADDON is also provided
pls checkout the code POWER_meter_FFT
or better the code POWER_meter_FFT_V04 what now also includes a MANUAL

________________________________________________________
working with the new EMON software library
there is a big improvement
a batch startup checks for Voltsignal crossing "zero=512" ((sampleV < 550) && (sampleV > 440))
and start the batch
and from then on counts the half waves until your adjusted limit ( 20 )
what is 10sinus=200mS(50Hz)
i call it FULL WAVE EMON

actually i try to do this new EMON tool in a arduino WIFI WEBSERVER
see my WIFI blog.



________________________________________________________

now i try to pack all options to one pack of code,
but because of size / memory usage they can not run together.
new name: POWER_METER_TOOL ( see download )
using compiler options there now you can select
//#define useMENU // switch use user menu on USB port

//#define usememcheck // switch memory check
//#define useSD // switch use SD card / shield ( useEMON must be defined )
//#include change manually

//#define useEE // switch use EE PROM storage of setup variables ( useEMON must be defined )

//#define usemodem // switch use GPRS SIM 900 modem shield ( useEMON must be defined )
//#define useSMS // switch use send alarm SMS ( usemodem must be defined )
//#define useGPRS // switch use send EMON data INTERNET ( usemodem must be defined ) HOLD!

#define useVCC // switch use read VCC in setup using emon1.readVCC ( useEMON must be defined )
#define useEMON // switch use emon power measuring / calc VOLT pin A0, Current1 pin A1
#define useXEMON 5 // number of current inputs, pin A 1,2,3,4,5
#define useKWH // switch use emon power measuring and calc kWh
//#define useFFT // switch use FFT
//#define useOSCI // switch use 6 channel /zoom oscilloscope in processing
//#define useWIFIserver // switch use WIFI arduino
( but because compiler switches dont work down into a library now new default emon works with
Hz and kWh calculation )

working on new powermeter hardware


first plastic box and AC part, VT and fuse, CT, looped in a old extension cable
and according this circuit



warning, that is a old circuit, later i changed to independent 2V5 for each Ain.

again i use one common 2V5 ( not according EMON circuit ) with HF filter caps
regarding this possible problems i will connect the 2V5 point to a Ain (A2)
so later i can show you the SCOPE snapshot of that voltage
the electrolyt and the ceramic capacitors are selectable by jumpers for this test.

for the passive elements of that circuit i use a experiment board ( with copper stripes )
and wires to arduino connector ( 90deg angled pins )




idea is that the box works with
- arduino
- wifi arduino
- arduino with GPRS shield ( see ext antenna connector )
? could i use same antenna for GPRS and WIFI ?

start with testing and tuning and found that i need far off tuning values
for current ICAL and PHASECAL

angry that i have to look at bad measuring results but don't know the
real measuring signal i started with a new diagnostic module for EMON
( my SCOPE is nice but only show 1 channel, for emon need VOLT and CURRENT )

i made a 2 channel measurement to array ( of 64 samples )
and tuned it with a delay timer ( 86 microseconds after each reading ) to 20ms / one sinus / result: 19970 micros batchtime
thats close/better to the 52 measurements/sinus by EMON
as output i use a print routine like a old CHART RECORDER ( but to terminal )

also can extract the data from a terminal (HTERM) output storage and use in a spreadsheet



i have no idea what can cause that current indication,
a real current TO A WATERHEATER (ohm load)?
or bad CT signal
or electronic/circuit problem 2V5, zener diode??
there is no big problem with the common 2V5 ( 507 .. 512 ) or it would be on both readings.
doesn't it look like a current loading a capacitor by a AC voltage?

check deeper on the CT, resistor and CT flux saturation
TZ2L9 pdf not helps much, and the product page at taehwatrans finally gives the answer:

looks like 470ohm limits the current measurement to under 1.5A,
well i meant 47.0ohm for the 5A measuring range!
or make the range adjustable?
but never forget that CT's are dangerous, without a resistor
they can produce MEGA VOLT. so minimum one resistor must be soldered to the transformer,
a second parallel could be jumpered for range change,
and also cable connectors may be used after that only.

so with a 22ohm parallel to the 470ohm we can switch
Burden resistor 470ohm to 21ohm
from 1A range to 10A range
provided a different EMON tuning: ICAL=2.22 / ICAL=50.0
new circuit

and tuning the PhaseCAL back to 1.7
reading a small fan is possible but
_line, W , VA , Vrms , Irms, p , Hz, kWh,
A1,36.80,68.17,233.50,0.29,0.54,49.88,0.02,

with the waterheater:
_line, W , VA , Vrms , Irms, p , Hz, kWh,
A1,456.12,454.69,231.55,1.96,1.00,50.13,0.02,

while volt and amp and watt pretty good,
is the phase for the small fan current questionable
but i have no tools to check.
and i need a bigger LOAD to check for that CT saturation flux problem on high range.

____________________________________________________________________
when we test the 10A range
( CT(N2=1000) and 22ohm and ICAL=50 )
the ZERO goes up to 0.3 amp ( phase -0.3)
after many tests and use of the new PoorManScope sketch
the problem comes from a swing of the common 2V5 by the relatively big VT signal
amlified by a big ICAL when using a low ohm burden resistor for high amp range
.
for high amps the values perfect, for low amps the measurement good,
but the EMON indication bad, the current ZERO and use a FAN show same (0.3A),
the phase change from -0.3 to 0.3 ( and the Watt from -20W to 20W (delta 40W))
First approach to try to solve this bad ZERO was using a new Voltage resistor divider 10k/100R instead 10k/1k.
so the signal of VT smaller and variation of 2V5 smaller.
with this the ZERO improved but suddenly the Hz calculation ( possibly also the sinus detect code at batch start) not work in every cycle.

also changing the CT range burden from 22ohm to 100ohm, range from 10A to 4A
and tune ICAL down i got a improvement of the BAD ZERO from 0.3 to 0.03A.
But over all, i think better not use a common 2V5, make a 2V5 for each measurement
( like in the original EMON circuit ) but see their forum, many people experiment on this.
new circuit
____________________________________________________________________

after power monitor "shield" ready, start working again on the modem.
now i have two versions of the GPRS shield here: V1.0 and V1.2 but online documentation is now V1.4.
differences: SIM 900 S2 1040S Z09 old(1H) new (2V)
arduino header pins moved so with new version fits perfect on arduino
power jack changed from 2-pin JST connector to same like on arduino,
and on first moment i think that's good. BUT its a 4.8 .. 5VDC not 9 VDC input!( V1.2 )
there is still a powerkey ( push butten for wakeup ) but its also connected to D9
for software operation, so its actually not needed any more.
antenna connector is now soldered, box mounting now difficult.
backside is now add. to the SIM card holder a 3V CR 1220 battery holder
not mentioned in any documentation. if this is for a SIM 900 RTC could be very usefull.
the connection of A4 and A5 to modem is questionable, need to test the analog
inputs, if still working.

bad luck as usual, the used connection between A4 A5 and SIM900 shield,
needed to be cut on the PCB

but this project is installed and run some month now on a small malysia island
and SMS report to headoffice.

____________________________________________________________________

pls find new version of POWER METER TOOLBOX V1.1 including
new EMON LIB: FULL WAVE EMON,
ALARM and DATA SMS feature...
CHART recorder like PoorManScope2 (v2.2)

____________________________________________________________________
working on a new version what includes a ( hardware ) serial link to MEGA with LCD
see here