Using an Arduino timer with a kettle efficiency test rig

Hello Everyone,

I have a question about my Arduino's Kettle Efficiency project related to timings.

My project measures power and temperature of a kettle using an arduino and a CT sensor and some circuity . I have the Power measurement working and would like to measure the time taken to boil from when the CT sensor reads current to when it doesn't.

So far I have research about Milli() and delay() but not sure how i can incorporate this into reading my CT sensor.

See attached what I have written so far.

// EmonLibrary examples openenergymonitor.org, Licence GNU GPL V3

#include "EmonLib.h" // Include Emon Library
EnergyMonitor emon1; // Create an instance
unsigned long startMillis;
unsigned long currentMillis;
const unsigned long period = 1000; //the value is a number of milliseconds, ie 1 second
int current_state = 0;
void increase_state()
{
current_state++;
Serial.println(current_state);
}
void setup()
{
Serial.begin(9600);

emon1.voltage(A4, 225,1.7); // Voltage: input pin, calibration, phase_shift
emon1.current(A5, 111.1); // Current: input pin, calibration.
long timenow, timelong=500;
int current_state = 0;
}

void loop()
{
{

emon1.calcVI(20,2000); // Calculate all. No.of wavelengths, time-out

float realPower = emon1.realPower; //extract Real Power into variable
float apparentPower = emon1.apparentPower; //extract Apparent Power into variable
float powerFActor = emon1.powerFactor; //extract Power Factor into Variable
float supplyVoltage = emon1.Vrms; //extract Vrms into Variable
float Irms = emon1.Irms; //extract Irms into Variable
}
{
if (emon1.Irms > 3)

currentMillis=millis(); //get current time
increase_state(); // increase by 1
while (digitalRead(emon1.Irms > 3)) //check if the button is still pressed
{
//rapidly increase "current_state" by 1 if button is pressed more than 500ms with interval of 50ms.
if ((millis()-startMillis)>currentMillis)
{
increase_state();
delay(50);
}
}
{
Serial.println(emon1.Irms);
Serial.println(emon1.Vrms);
}
}
}
Thanks in advance for reading and any help

Cheers

Tom :slight_smile:

voltage_current.ino (1.73 KB)

I have the Power measurement working and would like to measure the time taken to boil from when the CT sensor reads current to when it doesn't.

As you have not posted your code here I am going to make a guess.

Save the millis() value when the process starts. Save the millis() value when the process ends. The difference between the two is the time taken in milliseconds.

Hi

Thanks for your reply.

How would I write this and do I need to declare anything in the scope?

Thanks

Tom

Here is the OPs code better formatted

// EmonLibrary examples openenergymonitor.org, Licence GNU GPL V3

#include "EmonLib.h"             // Include Emon Library
EnergyMonitor emon1;             // Create an instance
unsigned long startMillis;
unsigned long currentMillis;
const unsigned long period = 1000;  //the value is a number of milliseconds, ie 1 second
int current_state = 0;
void increase_state()
{
  current_state++;
  Serial.println(current_state);
}
void setup()
{
  Serial.begin(9600);
  emon1.voltage(A4, 225, 1.7); // Voltage: input pin, calibration, phase_shift
  emon1.current(A5, 111.1);       // Current: input pin, calibration.
  long timenow, timelong = 500;
  int current_state = 0;
}

void loop()
{
  {
    emon1.calcVI(20, 2000);        // Calculate all. No.of wavelengths, time-out
    float realPower       = emon1.realPower;        //extract Real Power into variable
    float apparentPower   = emon1.apparentPower;    //extract Apparent Power into variable
    float powerFActor     = emon1.powerFactor;      //extract Power Factor into Variable
    float supplyVoltage   = emon1.Vrms;             //extract Vrms into Variable
    float Irms            = emon1.Irms;             //extract Irms into Variable
  }
  {
    if (emon1.Irms > 3)
      currentMillis = millis(); //get current time
    increase_state(); // increase by 1
    while (digitalRead(emon1.Irms > 3)) //check if the button is still pressed
    {
      //rapidly increase "current_state" by 1 if button is pressed more than 500ms with interval of 50ms.
      if ((millis() - startMillis) > currentMillis)
      {
        increase_state();
        delay(50);
      }
    }
    {
      Serial.println(emon1.Irms);
      Serial.println(emon1.Vrms);
    }
  }
}

Note that several pairs of braces are unnecessary.

Where in the code does the sensor read current consumption ?

Hi,

Below is the section that reads it:

emon1.current(A5, 111.1); // Current: input pin, calibration.

From the EmonLib.h library

It is then extracted using the float command into a variable using the following code:

float Irms = emon1.Irms; //extract Irms into Variable

Then serial printed.

Regards,

Tom

It is then extracted using the float command into a variable using the following code:

float Irms = emon1.Irms; //extract Irms into Variable

Then serial printed.

No such thing as the float command. The variable named Irms, which is of type float, holds the value of the current. What sort of values do you see when you print it and why the test to see whether it is greater than 3 ? Is that your indication that the kettle is taking power ?

Looking back to your original post you said

would like to measure the time taken to boil from when the CT sensor reads current to when it doesn't.

Is there an automatic cutoff that takes the current to zero once the kettle boils ?

Incidentally, having read the current into the Irms variable it is bad practice to read it again later in the same iteration of loop() as it may have changed. Read it once per loop() then use the Irms value in further comparisons.

Hi,

When the kettle is on I see 8 amps as the kettle is rated to 2200W with a voltage input of 240V. The library then uses ohms law to calculate the power.

When the kettle is boiled it will automatically switch off. The CT will then therefore read no current sometimes 0.8 if there is noise. I set it to 3 because I know while I'm testing this specific kettle the current produced will not go below.

Thanks again for your continuing help on this really appreciate it.

Regards,

Tom