I need 2 loops - A calibration loop and then a measurement loop.

Hi there....

I am using the Arduino to measure current from a current sensor.

In step 1 I would first like to read n samples of a 60 second period. This is the first loop and will be used to determine the calibration amount (if any) This will run during the initializing state when no appliances are plugged in. Once this state is complete a message will appear "Calibration complete...." and Step 2 (the main loop)will then run.

Step 2 runs the main measurement loop.

Here is the code. I have not coded step 1 yet. What I need to determine is where does it fit, How do I pass the variable - calibration to Step 2?


include "EmonLib.h" // Include Emon Library

EnergyMonitor emon1; // Create an instance

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

emon1.current(1, 10); // Current: input pin, calibration. }

void loop() { double Irms = emon1.calcIrms(1480); // Calculate Irms only

Irms = Irms - calibrationvalue Serial.print("Curent : "); Serial.println(Irms); // Irms delay(10); }


Kind Regards....

Put code to run once (i.e. calibration) in setup() and the measurement in loop().

Irms = Irms - calibrationvalueYou need to fix this line to allow the code to compile

Put code to run once (i.e. calibration) in setup() and the measurement in loop().

Declare calibrationvalue as a global variable so that its value is accessible in both setup() and loop()

Thanks for the help guys.
Will try those solutions…