Hi everyone, i am quite new too programming however need to use it in my current dissertation. I am building a power meter what monitors voltage and current and used the Arduino to calculate the power consumed.

2 ADC inputs on the Arduino are wave forms (0-5v) proportional to the voltage and current wave-forms of the appliance. I have coded up until the point of calculating power.

i now have a defined power value in my code (voltage x current) which is constantly changing due to the voltage and current of the AC appliance always changing. I want to calculate an average of the first 192 power values obtained but finding it difficult. What would be the correct way of going about this? Thank you, my code is shown below.

float A = 426.666667; // Value needed to convert the voltage back to original float x = 0.030304329; // value needed to convert the voltage into current in secondry coil int y = 2000; // value needed to convert into current through the wire float OffsetI = 2.5; // 2.5v offset added in order to meet arduino input range of 0-5v float OffsetV = 0.75; // 0.75v offset on the voltage waveform int inputPin = A0; int inputPin = A1

void setup() { Serial.begin(9600);

} void loop() { int current; // declaring 'current' int sensorValue0 = analogRead(A0);// read the input on analog pin 0: float voltageI = sensorValue0 * (5.0 / 1023.0); // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V): current = (voltageI - OffsetI)*x*y; // Convert the voltage back into the initial current flowing through wire

int voltage; // declaring 'voltage' int sensorValue1 = analogRead(A1);// read the input on analog pin 1: float voltageV = sensorValue1 * (5.0 / 1023.0); // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V): voltage = (voltageV - OffsetV)*A; // Convert the voltage back into the mains voltage reading

int power = voltage*current;

}