Hi, I have a question for you as I could do to add a constant "float" constantly add up every second

Beforehand thank you very much.

Hi, I have a question for you as I could do to add a constant "float" constantly add up every second

Beforehand thank you very much.

What is the question? Please explain your project.

Ok, my project is an electric meter, the problem that I have when adding the constants of KWH I can not or I do not know how to do it

How about

```
//in setup()
const float kwh_per_meter_tick = 0.234; //some constant
float total=0; //total kwh
...
// in loop()
...
if (meter_just_ticked) total = total+kwh;
```

Javstah74:

Ok, my project is an electric meter, the problem that I have when adding the constants of KWH I can not or I do not know how to do it

It would be better to use unsigned long instead of float and count in terms of mWH instead. That would be more precise calculations certainly and shorter code and maybe even faster code.

Power=Current*(120);

delay(1000);

if(Current>=0.05){

KWH=Power*(1/Joules);

Sum=KWH+Zero;

Look at this I have then KWH is a value that varies a lot, the only thing that could vary the zero constant, What I need is for it to accumulate

```
KWH=Power*(1/Joules);
```

You won't get anywhere with nonsense like this.

You need some background. One place to start is openenergymonitor.org

Come back to the forum when you understand what a kilowatt-hour (kwh) is.

Yes and sorry sir

The code that I am designing is that it is a kwh

the counter that I'm designing measures it every second then

For example

1seg = 5W something that consumes that then

(1000w) (3600s) = 3600000J is to get it out in an hour

so

5W (1s) = 5 J / S (1s) = 5J

5J * (1kwh / 3600000) And so I take out kwh

I WANT TO RECALCAR LORD THAT I AM NOT AN ENGINEER THAT I AM A STUDENT AND I BELIEVE I FEEL TO NOT BE PERFECT.

Hiya Javstah74,

Are you a college student or a high school student - or whatever the equivalent is where you live? College generally starts with calculas at age 17 or so, and high school is before that and uses algebra. If you are a college student, you need to be studying electrical energy at a high level, the link jremmingtom gave you is an *excellent* way to start. If you are in high school, study the page, even though you lack the math to understand it completely. In that case you still need to learn the terminology. Simply applying dimensional analysis to a set of numbers is not understanding the problem.

Either way, shouting that you are not an engineer is not the way to elicit help! (Engineering) students are actually engineers in training, so buck up, and do your homework. Come back and ask for specific help with what you don’t understand. Ask smart questions, and you’ll get smart answers.

Javstah74:

Power=Current*(120);

delay(1000);

if(Current>=0.05){

KWH=Power*(1/Joules);

Sum=KWH+Zero;Look at this I have then KWH is a value that varies a lot, the only thing that could vary the zero constant, What I need is for it to accumulate

you have a fundamental coding problem.

in post 3 jermmington gave you a clue on how to get a running total.

your total is the old value plus the new value.

total = total + new

next :

if you use delay(), then your second will be your second, plus the scan time so you might calculate for 59 seconds a minute. not a big deal at this early stage, but put that on your 'need to fix' list.

recommendation :

what I think you should do, is to get the measurement parts fixed first.

use the serial monitor and create columns and watch what each column does.

your raw reading - corrected reading - reading times voltage - cumulative value

since each step effect everything after, you need to get the first column working before the second, then the second column before the 3rd...

you may find you need to add more columns

bigger issues :

measuring amps on a AC line is not like measuring the voltage on a car battery.

AC is alternating.

not sure how too make an example but if you were to take a look at the oar of a boat once a second, it would be all the way forward, all the way back or some place in between. since one look at it once a second, you will not know if it moved, or if it moved 1 times or 30 times.

here is one of the rules of the Universe.

your measurement needs to be at least 4 times faster and 4 times more accurate than the thing you want to measure.

AC runs in cycles, 50 Hz or 60Hz for most of the plants utilities. that is 60 cycles a second, 60 peaks, 60 valleys.

the reason you have been asked to study over at openernergy is because they show you the fundamentals of AC electric.

if you use their libraries, it will do the measurements for you in a time that is able to work with your AC lines.

then, all you need to do is to take a snap shot every second and use that to create your running totals.