Forum
Power Monitoring using Arduino Uno
In this simple project we are going to build a simple real time power monitoring circuit to measure a 3-phase household usage. the design is very simple consists of the below
1- Arduino Uno
2- DHT22 (Temperature and Humidity Monitoring)
3- None-Invasive Current sensors SCT-013-060 (60 Amp)
4- LCD 128x46
5- Resistors and Capacitors
6- Jumper wires
the Arduino will be loaded with the energy monitoring package that can be found the libraries (EmonLib.h) this package will calculate and provide the current and voltage per phase and the DHT22 will provide information about the temperature and humidity for the sounding environment where you place the sensor
we create simple visualization on the LCD with lines and boxes to show real time readings for the voltage, current and kW consumption per phase and total of all the phases
the project can be enhanced more by sending data to an external data warehouse to be collected, analyzed and visualized
as for the code, please check the below
#include <Arduino.h> #include <U8g2lib.h> #include "EmonLib.h" #include "DHT.h" #define DHTPIN 2 #define DHTTYPE DHT22 #ifdef U8X8_HAVE_HW_SPI #include <SPI.h> #endif #ifdef U8X8_HAVE_HW_I2C #include <Wire.h> #endif # /* * SPI Serial Peripheral Interface * https://www.arduino.cc/en/Reference/SPI * * PINS 128x64 DOT MATRIX / GRAPHIC DISPLAY * ST7920 LCD controller * * BLK Backlight - * BLA Backlight + * VOUT * RST RST * NC Not Connected * PSB Interface Secelection LOW = Serial / HIGH = Parallel * DB7 Data Bit 7 * DB6 Data Bit 6 * DB5 Data Bit 5 * DB4 Data Bit 4 * DB3 Data Bit 3 * DB2 Data Bit 2 * DB1 Data Bit 1 * DB0 Data Bit 0 * E Enable trigger (serial clock SCK) * R/W Read / Write (Master Out Slave In MOSI) * RS Register Select (chip select CS) * V0 LCD Constrast * VCC Voltage Common Connector * GND Ground * * * PIN CONNECTIONS: * * BLK GND * BLA 3.3V * PSB GND * E (SCK) 13 * RW (MOSI) 11 * RS (CS) 10 * * VCC 5V * GND GND * */ U8G2_ST7920_128X64_1_SW_SPI u8g2(U8G2_R2, /* clock=*/ 13, /* data=*/ 11, /* CS=*/ 10, /* reset=*/ 8); EnergyMonitor emon1; // Create an instance-1 EnergyMonitor emon2; // Create an instance-2 EnergyMonitor emon3; // Create an instance-3 DHT dht(DHTPIN, DHTTYPE); int valVrms1 = 0; float valIrms1 = 0; float valIrms2 = 0; float valIrms3 = 0; int valKW1 = 0; int valKW2 = 0; int valKW3 = 0; int valKWtotal = 0; int h = 0; int t = 0; void setup(void) { u8g2.begin(); Serial.begin(9600); emon1.current(1, 27); // Ph-1Current: input pin, calibration. emon2.current(3, 48); // Ph-2Current: input pin, calibration. emon3.current(4, 45); // Ph-3Current: input pin, calibration. emon1.voltage(2, 140, 1.7); // Voltage: input pin, calibration, phase_shift dht.begin(); } void screen (void){ u8g2.setFont(u8g2_font_5x8_tf); // Set the Voltage frame and value u8g2.drawFrame(1,1,39,10); u8g2.setCursor(3, 9); u8g2.print("Vol"); u8g2.setCursor(18, 9); u8g2.print(":"); u8g2.setCursor(24, 9); u8g2.print(valVrms1); // Set the Temp frame and value u8g2.drawFrame(44,1,39,10); u8g2.setCursor(45, 9); u8g2.print("Tem"); u8g2.setCursor(61, 9); u8g2.print(":"); u8g2.setCursor(66, 9); u8g2.print(t); u8g2.setCursor(76, 9); u8g2.print("c"); // Set the humidity frame and value u8g2.drawFrame(87,1,39,10); u8g2.setCursor(89, 9); u8g2.print("Hum"); u8g2.setCursor(105, 9); u8g2.print(":"); u8g2.setCursor(110, 9); u8g2.print(h); u8g2.setCursor(120, 10); u8g2.print("%"); // Set the Phase-1 frame u8g2.drawFrame(1,13,39,10); u8g2.setCursor(3, 21); u8g2.print("Phase-1"); // Set the Phase-1 AMP u8g2.drawFrame(44,13,39,10); u8g2.setCursor(45, 21); u8g2.print(valIrms1); u8g2.setCursor(70, 21); u8g2.print("A"); // Set the Phase-1 KWA u8g2.drawFrame(87,13,39,10); u8g2.setCursor(89, 21); u8g2.print(valKW1); u8g2.setCursor(115, 21); u8g2.print("W"); // Set the Phase-2 frame u8g2.drawFrame(1,25,39,10); u8g2.setCursor(3, 33); u8g2.print("Phase-2"); // Set the Phase-2 AMP u8g2.drawFrame(44,25,39,10); u8g2.setCursor(45, 33); u8g2.print(valIrms2); u8g2.setCursor(70, 33); u8g2.print("A"); // Set the Phase-2 KWA u8g2.drawFrame(87,25,39,10); u8g2.setCursor(89, 33); u8g2.print(valKW2); u8g2.setCursor(115, 33); u8g2.print("W"); // Set the Phase-3 frame u8g2.drawFrame(1,37,39,10); u8g2.setCursor(3, 45); u8g2.print("Phase-3"); // Set the Phase-3 AMP u8g2.drawFrame(44,37,39,10); u8g2.setCursor(45, 45); u8g2.print(valIrms3); u8g2.setCursor(70, 45); u8g2.print("A"); // Set the Phase-3 KWA u8g2.drawFrame(87,37,39,10); u8g2.setCursor(89, 45); u8g2.print(valKW3); u8g2.setCursor(115, 45); u8g2.print("W"); // Print Total KW for the 3 phases u8g2.setFont(u8g2_font_courR12_tf); u8g2.setCursor (2, 60); u8g2.print("T-W"); u8g2.setCursor (50,60); u8g2.print(valKWtotal); } void loop(void) { emon1.calcVI(20,2000); valVrms1 = emon1.Vrms; valIrms1 = emon1.calcIrms(1480); valIrms2 = emon2.calcIrms(1480); valIrms3 = emon3.calcIrms(1480); valKW1 = valIrms1*valVrms1; valKW2 = valIrms2*valVrms1; valKW3 = valIrms3*valVrms1; valKWtotal = valKW1+valKW2+valKW3; h = dht.readHumidity(); t = dht.readTemperature(); u8g2.firstPage(); do { screen(); } while ( u8g2.nextPage() ); //Serial.print(valVrms1); //Serial.print(" , "); //Serial.print(valIrms1*220); //Serial.print('\n'); //float h = dht.readHumidity(); //float t = dht.readTemperature(); //Serial.print("Humidity: "); //Serial.print(h); //Serial.print(" %\t"); //Serial.print("Temperature: "); //Serial.print(t); //Serial.print(" *C "); //Serial.print('\n'); }
please feel free to comment, share this and add additional lines to enhance this project in a way that all can benefit from it
if you are looking to the materials that used to build this project, you can find it below