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
voltage_current.ino (1.73 KB)