-
Notifications
You must be signed in to change notification settings - Fork 0
/
My_CT1_Serial_single_input_L2.ino
80 lines (66 loc) · 1.7 KB
/
My_CT1_Serial_single_input_L2.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
EmonTx CT123 Voltage Serial Only example
Part of the openenergymonitor.org project
Licence: GNU GPL V3
Author: Trystan Lea
*/
#include "EmonLib.h"
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 4
#define TEMPERATURE_PRECISION 9
EnergyMonitor ct1;
const int LEDpin = 9;
void setup()
{
Serial.begin(9600);
// Calibration factor = CT ratio / burden resistance = (80A / 0.1A) / 33 Ohms = 24.24
ct1.current(1, 24.599);
// (ADC input, calibration, phase_shift)
ct1.voltage(0, 129.8, 1.7); //L2 - Furnace Outlet
// Setup indicator LED
pinMode(LEDpin, OUTPUT);
digitalWrite(LEDpin, HIGH);
while (millis() < 30000) {}
}
void loop()
{
unsigned long start = millis();
unsigned long finish = (((start + 30000) / 1000) * 1000);
float myPower1 = 0.0;
float myAPower1 = 0.0;
float myPowerFactor1 = 0.0;
float myVrms1 = 0.0;
float myIrms1 = 0.0;
float avgDenom = 0.0;
int ct = 0;
while (millis() < finish)
{
// Calculate all. No.of crossings, time-out
ct1.calcVI(20, 2000);
myPower1 += ct1.realPower;
myAPower1 += ct1.apparentPower;
myPowerFactor1 += ct1.powerFactor;
myVrms1 += ct1.Vrms;
myIrms1 += ct1.Irms;
ct++;
}
finish = millis();
avgDenom = 0.004 * (finish - start);
myPower1 = (myPower1 / ct) / avgDenom;
myAPower1 = (myAPower1 / ct) / avgDenom;
myPowerFactor1 = myPowerFactor1 / ct;
myVrms1 = myVrms1 / ct;
myIrms1 = myIrms1 / ct;
Serial.print(myPower1, 3);
Serial.print(",");
Serial.print(myAPower1, 3);
Serial.print(",");
Serial.print(myPowerFactor1, 5);
Serial.print(",");
Serial.print(myVrms1, 5);
Serial.print(",");
Serial.print(myIrms1, 5);
Serial.print(",");
Serial.println(ct);
}