### Calculating the kwh in the arduino

hi need some help on calculating the kwh in the arduino

I already have the arduino reading the current and multiplying by 230v i have the  power  calculated.
As i will read the the data from the arduino by modbus tcp to my scada software i also want co calculate  the kwh on the arduino
What i want is something that will calculate the kwh usage along the 24h and then reset it back to zero so i have the kwh reading by day...

Can someone please give me a help with algorithm to calculate the kwh ?

thanks

### Re: Calculating the kwh in the arduino

The energy value you require is the integral over the 24 hour period of the power.

So in very general terms you must measure the power at intervals and multiply by the time period. That assumes that the power is constant over the period in question so the more frequently you measure the power and compute the energy, the more accurate your total accumulated energy value will be. Then you need to know the time of day in order to reset the accumulator. In the emonGLCD, the time is requested from the server where emoncms is running. You could use that, or Internet time from an NTP server, or you could add a radio code clock or another real time clock to your Arduino.

You will find some code that might help you in the emonGLCD sketches.

### Re: Calculating the kwh in the arduino

thanks , i will have the a RTC connected to arduino..

but forgetting the 24h so... i will read the power average it and then divide by 3600.... bit lost

i will check the glcd skteches

### Re: Calculating the kwh in the arduino

Still lost on this tried to search info on this here and internet and nothing

some help appreciated

thanks

### Re: Calculating the kwh in the arduino

kwH is a measure of energy, and energy is power times time.  To find the total amunt of energy that has flowed, you need to add together all the individual energy contributions.  If your energy calculations occur every N seconds, then each one will be the average power times the period for which that power was flowing (i.e. N seconds)

As has been discussed recently on the forum, it's a good idea to record the consumption of each whole Watt Hour separately.  So, every time your accumulator exceeds 3600, just subtract 3600 from its value and add one to your WattHour register.  At the end of the day, your kWH value is just the WattHour value divided by 1000.

There's a simple description of power and energy in pages 1 & 2 of my PV Router article which you may find helpful.

### Re: Calculating the kwh in the arduino

fca,

Hi .... In my derivative of Robin's and other's codes, I calculate energy imported, exported, and diverted in kwh and accumulate the values over a 24 hour period. The values are displayed on an LCD, and reset every night at midnight. I use an RTC to keep track of time. More detail and the Arduino sketch can be found on this thread.

keduro

## Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.