Dear learned and wise of t'interweb,
Over the last few weeks I have been trying to develop a system to measure the mains current being drawn in a house, using a current transformer as an input. I have learned a lot on the way, but still consider myself a newbie. Just yesterday I discovered that some kind soul has written a library function that will do just what I want, and (damn it!) a lot better than my old sketch...though not quite, and it is the not quite part for which I crave your sympathy and assistance.
The question is quite simple, and I hope the answer is too.
This new sketch (see below) returns a variable 'Irms', and I believe that (please correct me if wrong) Irms is data type 'double'. Is there a simple way for a newbie to read the data type of a returned variable? I want to compare Irms with a second variable, and do something if Irms > secondVariable. I suppose this means that Irms and secondVariable must be the same data type. Is this so (simplified answers, please!)?
I have been guilty of failing to post code, posting snippets, and failing to provide schematics in the past. Though I feel they are verbose in this case, they are included below so that I don't transgress this time!
The link to the tutorial/project is How to Build an Arduino Energy Monitor - Measuring Mains Current Only — OpenEnergyMonitor 0.0.1 documentation
The code is
#include "EmonLib.h"
// Include Emon Library
EnergyMonitor emon1;
// Create an instance
void setup()
{
Serial.begin(9600);
emon1.current(1, 111.1); // Current: input pin, calibration.
}
void loop()
{
double Irms = emon1.calcIrms(1480); // Calculate Irms only
Serial.print(Irms*230.0); // Apparent power
Serial.print(" ");
Serial.println(Irms); // Irms
}
My (pseudo-code) addition to the code above will be something like:
If Irms > secondVariable
{
digital.write (pin13, HIGH);
}
else digital.write (pin13, LOW);
but (admittedly late!) last night I couldn't get my comparator to change the state of Pin13, though it had (within another sketch) produced the expected outcomes when comparing two integer variables, and by this I mean that despite there being numerous syntax errors in my pseudo-code above, I have grasped the basics of comparing two integers previously...it's the possible complications of trying to compare a 'double' (or whatever datatype Irms is) with another value that have me confused.
Perhaps you can point me to a tutorial on that very subject?
Your guidance gratefully received,
GM