Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

/*

Smart Energy Meter and Monitoring using ElectroSaving App


Khalid Akram (17EL12)
Ansar Bilal (17EL32)
Muhammad Fahad (16/17EL34)
*/
#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
const int sensorIn = A0;
const int buttonPin = 12;
const int transistorPin = 8;

int buttonState = 0;
int mVperAmp = 78;

double Voltage = 0;
double VRMS = 0;
double AmpsRMS = 0;
double kilos = 0;
int peakPower = 0;

void setup()
{

pinMode(buttonPin, INPUT_PULLUP);
pinMode(transistorPin, OUTPUT);

Serial.begin(9600);
lcd.begin(20, 4);
lcd.clear();
lcd.setCursor(6,1);
lcd.print(" WELCOME");
lcd.setCursor(5,2);
lcd.print("Energy Meter");

delay(1000);
lcd.clear();

void loop()
{
int sensorValue = analogRead(A1);
float volt = sensorValue * (241.0 / 1023.0);

Voltage = getVPP();
VRMS = (Voltage/2.0) *0.707; //root 2 is 0.707
AmpsRMS = (VRMS * 1000)/mVperAmp;

int RMSPower = volt * AmpsRMS; //Calculates RMS Power Assuming Voltage 220VAC,
change to 110VAC accordingly
if (RMSPower > peakPower)
{
peakPower = RMSPower;
}
kilos = kilos + (RMSPower * (2.05/60/60/1000)); //Calculate kilowatt hours
used
delay (2000);
buttonState = digitalRead(buttonPin);

if (buttonState == LOW)
{

digitalWrite (transistorPin, HIGH);

else
{

digitalWrite (transistorPin, LOW);

Serial.print("\t AC Voltage = ");


Serial.print(volt);
Serial.println(" Volt");
Serial.print("\t \t AC Current = ");
Serial.print(AmpsRMS);
Serial.println(" Amps");
Serial.print("\t \t \t Power = ");
Serial.print(RMSPower);
Serial.println(" Watt");
Serial.print("\t \t \t \t Energy = ");
Serial.print(kilos);
Serial.println(" Kwh");

lcd.setCursor(0, 0);
lcd.print("V="); lcd.print(volt);
lcd.setCursor(0, 1);
lcd.print("I=");lcd.print(AmpsRMS);
lcd.setCursor(0, 2);
lcd.print("P="); lcd.print(RMSPower);
lcd.setCursor(0, 3);
lcd.print("Kwh=");lcd.print(kilos);

delay(1000);
}

float getVPP()
{
float result;
int readValue; //value read from the sensor
int maxValue = 0; // store max value here
int minValue = 1023; // store min value here

uint32_t start_time = millis();


while((millis()-start_time) < 1000) //sample for 1 Sec
{
readValue = analogRead(sensorIn);
// see if you have a new maxValue
if (readValue > maxValue)
{
/*record the maximum sensor value*/
maxValue = readValue;
}
if (readValue < minValue)
{
/*record the minimum sensor value*/
minValue = readValue;
}
}

// Subtract min from max


result = ((maxValue - minValue) * 5.0)/1023.0;

return result;
}

You might also like