Components and supplies
Arduino UNO
3.5mm female headphone jacks
Capacitor 10 µF
Arduino uno ethernet shield
My custom shield for CT hookup
100 Amp current transformer
Resistor 10k ohm
Project Box
Tools and machines
Plier, Side Cutting
Soldering iron (generic)
Solder Wire, Lead Free
Drill / Driver, Cordless
Apps and platforms
Blynk
Project description
Code
Sketch
arduino
Arduino Energy Monitor Code
1#include <SPI.h> 2#include <Ethernet.h> 3#include <BlynkSimpleEthernet.h> 4#include <TimeLib.h> 5#include <WidgetRTC.h> 6char auth[] = "your blynk token here"; // Put the token from your blynk project here 7double calibration = 0.32; // Modify this to calibrate your sensor o.32 should be accurent for a 100 amp CT 8double kilos0; 9double kilos1; 10double peakkilos; 11unsigned long startMillis; 12unsigned long endMillis; 13double RMSCurrent0; 14double RMSCurrent1; 15int RMSPower0; 16int RMSPower1; 17int peakPower0; 18int peakPower1; 19int TotalRMSPower; 20int current0 = 0; 21int maxCurrent0 = 0; 22int minCurrent0 = 1000; 23int current1 = 0; 24int maxCurrent1 = 0; 25int minCurrent1 = 1000; 26int zero0 = 516; 27int zero1 = 516; 28int Volts = 121.2; // Change this field to the voltage your house is supplied with 29BlynkTimer timer; 30WidgetRTC rtc; 31 32void setup() 33{ 34 Serial.begin(115200); 35 Blynk.begin(auth, IPAddress(***, ***, ***, ***), 8080); //Replace the astrics with the IP address of your local blynk server 36 setSyncInterval(10 * 60); 37} 38 39void loop() 40{ 41 if (Blynk.connected()) { // If connected run as normal 42 Blynk.run(); 43 rtc.begin(); 44 timer.run(); 45 } else { 46 Blynk.connect(); 47 } 48 readPhase(); 49 displayKilowattHours(); 50 displayCurrent(); 51 displayPower(); 52 if (hour() == 23 && minute() == 59) { 53 kilos0 = 0; 54 kilos1 = 0; 55 } 56 delay(100); 57 readPhase(); 58 delay(100); 59 readPhase(); 60} 61 62void clockDisplay() 63{ 64 String currentTime = String(hour()) + ":" + minute() + ":" + second(); 65 String currentDate = String(day()) + " " + month() + " " + year(); 66 Serial.print("Current time: "); 67 Serial.println(currentTime); 68} 69 70void readPhase () 71{ 72 maxCurrent0 = zero0; 73 minCurrent0 = zero0; 74 maxCurrent1 = zero1; 75 minCurrent1 = zero1; 76 for (int i = 0 ; i <= 200 ; i++) 77 { 78 current0 = analogRead(A0); 79 current1 = analogRead(A1); 80 if (current0 >= maxCurrent0) 81 maxCurrent0 = current0; 82 else if (current0 <= minCurrent0) 83 minCurrent0 = current0; 84 if (current1 >= maxCurrent1) 85 maxCurrent1 = current1; 86 else if (current1 <= minCurrent1) 87 minCurrent1 = current1; 88 } 89 zero0 = ((maxCurrent0 - minCurrent0) / 2) + minCurrent0; 90 zero1 = ((maxCurrent1 - minCurrent1) / 2) + minCurrent1; 91 RMSCurrent0 = (maxCurrent0 - zero0) * calibration; 92 RMSCurrent1 = (maxCurrent1 - zero1) * calibration; 93 RMSPower0 = Volts * RMSCurrent0; 94 RMSPower1 = Volts * RMSCurrent1; 95 TotalRMSPower = RMSPower0 + RMSPower1; 96 endMillis = millis(); 97 unsigned long time = (endMillis - startMillis); 98 kilos0 = kilos0 + (((double)RMSPower0 / 1000) * ((double)time / 3600000)); 99 kilos1 = kilos1 + (((double)RMSPower1 / 1000) * ((double)time / 3600000)); 100 peakkilos = kilos0 + kilos1; 101 startMillis = millis(); 102} 103 104void displayKilowattHours() //Displays all kilowatt hours data 105{ 106 Serial.print(kilos0); 107 Serial.print("kWh "); 108 Serial.print(kilos1); 109 Serial.println("kWh"); 110 Serial.print(peakkilos); 111 Serial.println("kWh"); 112 Blynk.virtualWrite(V2, peakkilos); 113} 114 115void displayCurrent() //Displays all current data 116{ 117 Serial.print(RMSCurrent0); 118 Serial.print("A "); 119 Serial.print(RMSCurrent1); 120 Serial.println("A"); 121 Blynk.virtualWrite(V0, RMSCurrent0); 122 Blynk.virtualWrite(V1, RMSCurrent1); 123} 124 125void displayPower() //Displays all watts 126{ 127 Serial.print(RMSPower0); 128 Serial.print("W "); 129 Serial.print(RMSPower1); 130 Serial.print("W "); 131 Serial.print(TotalRMSPower); 132 Serial.println("W"); 133}
Sketch
arduino
Arduino Energy Monitor Code
1#include <SPI.h> 2#include <Ethernet.h> 3#include <BlynkSimpleEthernet.h> 4#include 5 <TimeLib.h> 6#include <WidgetRTC.h> 7char auth[] = "your blynk token here"; 8 // Put the token from your blynk project here 9double calibration = 0.32; // Modify 10 this to calibrate your sensor o.32 should be accurent for a 100 amp CT 11double 12 kilos0; 13double kilos1; 14double peakkilos; 15unsigned long startMillis; 16unsigned 17 long endMillis; 18double RMSCurrent0; 19double RMSCurrent1; 20int RMSPower0; 21int 22 RMSPower1; 23int peakPower0; 24int peakPower1; 25int TotalRMSPower; 26int current0 27 = 0; 28int maxCurrent0 = 0; 29int minCurrent0 = 1000; 30int current1 = 0; 31int 32 maxCurrent1 = 0; 33int minCurrent1 = 1000; 34int zero0 = 516; 35int zero1 = 516; 36int 37 Volts = 121.2; // Change this field to the voltage your house is supplied with 38BlynkTimer 39 timer; 40WidgetRTC rtc; 41 42void setup() 43{ 44 Serial.begin(115200); 45 46 Blynk.begin(auth, IPAddress(***, ***, ***, ***), 8080); //Replace the astrics 47 with the IP address of your local blynk server 48 setSyncInterval(10 * 60); 49} 50 51void 52 loop() 53{ 54 if (Blynk.connected()) { // If connected run as normal 55 Blynk.run(); 56 57 rtc.begin(); 58 timer.run(); 59 } else { 60 Blynk.connect(); 61 } 62 63 readPhase(); 64 displayKilowattHours(); 65 displayCurrent(); 66 displayPower(); 67 68 if (hour() == 23 && minute() == 59) { 69 kilos0 = 0; 70 kilos1 = 0; 71 72 } 73 delay(100); 74 readPhase(); 75 delay(100); 76 readPhase(); 77} 78 79void 80 clockDisplay() 81{ 82 String currentTime = String(hour()) + ":" + minute() 83 + ":" + second(); 84 String currentDate = String(day()) + " " + month() + 85 " " + year(); 86 Serial.print("Current time: "); 87 Serial.println(currentTime); 88} 89 90void 91 readPhase () 92{ 93 maxCurrent0 = zero0; 94 minCurrent0 = zero0; 95 maxCurrent1 96 = zero1; 97 minCurrent1 = zero1; 98 for (int i = 0 ; i <= 200 ; i++) 99 { 100 101 current0 = analogRead(A0); 102 current1 = analogRead(A1); 103 if (current0 104 >= maxCurrent0) 105 maxCurrent0 = current0; 106 else if (current0 <= minCurrent0) 107 108 minCurrent0 = current0; 109 if (current1 >= maxCurrent1) 110 maxCurrent1 111 = current1; 112 else if (current1 <= minCurrent1) 113 minCurrent1 = current1; 114 115 } 116 zero0 = ((maxCurrent0 - minCurrent0) / 2) + minCurrent0; 117 zero1 = ((maxCurrent1 118 - minCurrent1) / 2) + minCurrent1; 119 RMSCurrent0 = (maxCurrent0 - zero0) * calibration; 120 121 RMSCurrent1 = (maxCurrent1 - zero1) * calibration; 122 RMSPower0 = Volts * RMSCurrent0; 123 124 RMSPower1 = Volts * RMSCurrent1; 125 TotalRMSPower = RMSPower0 + RMSPower1; 126 127 endMillis = millis(); 128 unsigned long time = (endMillis - startMillis); 129 130 kilos0 = kilos0 + (((double)RMSPower0 / 1000) * ((double)time / 3600000)); 131 132 kilos1 = kilos1 + (((double)RMSPower1 / 1000) * ((double)time / 3600000)); 133 134 peakkilos = kilos0 + kilos1; 135 startMillis = millis(); 136} 137 138void displayKilowattHours() 139 //Displays all kilowatt hours data 140{ 141 Serial.print(kilos0); 142 Serial.print("kWh 143 "); 144 Serial.print(kilos1); 145 Serial.println("kWh"); 146 Serial.print(peakkilos); 147 148 Serial.println("kWh"); 149 Blynk.virtualWrite(V2, peakkilos); 150} 151 152void 153 displayCurrent() //Displays all current data 154{ 155 Serial.print(RMSCurrent0); 156 157 Serial.print("A "); 158 Serial.print(RMSCurrent1); 159 Serial.println("A"); 160 161 Blynk.virtualWrite(V0, RMSCurrent0); 162 Blynk.virtualWrite(V1, RMSCurrent1); 163} 164 165void 166 displayPower() //Displays all watts 167{ 168 Serial.print(RMSPower0); 169 170 Serial.print("W "); 171 Serial.print(RMSPower1); 172 Serial.print("W 173 "); 174 Serial.print(TotalRMSPower); 175 Serial.println("W"); 176}
Downloadable files
schematic_uno_energy_monitor_2021-11-21_WrFuMp9doE.png
schematic_uno_energy_monitor_2021-11-21_WrFuMp9doE.png
Comments
Only logged in users can leave comments
Corymacs
0 Followers
•0 Projects
Table of contents
Intro
5
0