Countdown Timer With Kwh

Recommended Posts

I am creating a interactive interface to use with a bicycle powered generator system.  My goal is for a person to ride the bike, press a 'Start' button and then have a 60 second countdown timer displayed while counting the cumulative kWh they produce.

I have hooked up my LabJack U3 to the bikes and have successfully measured the Volts, Amps created an output for Watts, but I am in the dark about how to measure the kWh and the timer.  I have searched the previous boards for a solution but haven't had any luck.

Can someone help point me in the right direction of a solution, or help give me a general idea of what sort of sequencing I will need to create the pull this off.  I am new to coding, but if I had a general idea of whats to expect I think I could handle it.

Thanks!

Share on other sites

There are two parts to this, one is calculating cumulative kWh, the other is timing for 60 seconds.

1) cumulative kWh: first you need to create another channel to store the kWh values.  Call it whatever you want, device type Test, Timing = 0.  Then, in either your volts or amps channel's event you need to add some code.  You just want it in one of these channels, and it should be the one with the larger LabJack channel #.  The script is simply (assuming you named the kWh channel kwh):

kWh.addValue(kWh[0] + (volts[0] * amps[0]) * (volts.time[0] - volts.time[1]) / 3600)

What this does is takes the wattage (volts * amps) and multiplies by the deltaT between readings (in seconds) then divides by 3600 to get from kWsecs to kWh.  Then, we add it to the previous kWh reading to get cumulative.

This only works once you initialize kwh to 0:

This you'll probably do in the second part

2) When you click the start button you should have it start a script:

delay(60)

The problem is you want kWh to stop accumulating when the sequence is not running, so you'll need to add script to the event of part 1.  Let's say the sequence you just created is called "doRun".  Then change the event script to:

if (sequence.doRun.running)

kWh.addValue(kWh[0] + (volts[0] * amps[0]) * (volts.time[0] - volts.time[1]) / 3600)

endif

Share on other sites

You might also record in a channel instantaneous power in watts or kw, rather than accumulating in the channel, then you can decide the interval on the fly after the fact.

Mean(power[systime(), systime() - interval]) * interval

or whatever other historical interval you want to display.  Also, the energy generated will probably be more impressive if you display it in watt-hours or watt-minutes as opposed to KWh.

Share on other sites

.....or put the kwh for the sampling interval in the channel values and use sum() in that say way, using an interval you can define later.

IOW, if you had 2.8 watt-seconds during the sampling interval, record 2.8, rather than a running total.