Md. Khairul Alam
Published © CC BY-NC

Smart Energy Monitoring & Control System (Edison Inside)

Power management has been one of the most hot topics in the past decade because of the decrease in the energy reserves. Power shutdown is...

Full instructions provided4,704
Smart Energy Monitoring & Control System (Edison Inside)

Things used in this project

Hardware components

Arduino Compatible Edison Breakout
×1
Hall effect current sensor
×1
AC/AC adapter (220/12)
×1
LCD display (4*20)
×1
Resistor
×1
Capacitor
×1

Software apps and online services

IOT Analytics

Story

Read more

Schematics

F16OP5KIFISEGRV.fzz

Code

Code

Plain text
for (n=0; n<number_of_sample; n++){
  // inst_voltage and inst_current calculation from raw ADC goes here
  inst_power = inst_voltage * inst_current;
  sum_inst_power += inst_power;
}
real_power = sum_inst_power / number_of_samples;

Code

Plain text
for (n=0; n<number_of_sample; n++){
   // inst_voltage calculation from raw ADC input goes here.
    squared_voltage = inst_voltage * inst_voltage;
    sum_squared_voltage += squared_voltage; 
 }
 mean_square_voltage = sum_squared_voltage / number_of_samples;
 root_mean_square_voltage = sqrt(mean_square_voltage);

Code

Plain text
for (n=0; n<number_of_sample; n++) {
    // inst_current calculation from raw ADC input goes here.
    squared_current = inst_current * inst_current;
    sum_squared_current += squared_current;
 }
mean_square_current = sum_squared_current / number_of_samples;
root_mean_square_current = sqrt(mean_square_current);

Code

Plain text
apparent_power = root_mean_square_voltage * root_mean_square_current;

Code

Plain text
power_factor = real_power / apparent_power; 

Code

Plain text
iotkit-admin

Code

Plain text
iotkit-admin test

Code

Plain text
2014-11-10T21:50:54.062Z - info: Trying to connect to host ...
2014-11-10T21:50:54.570Z - info: Connected to dashboard.us.enableiot.com 
2014-11-10T21:50:54.571Z - info: Environment: prod 
2014-11-10T21:50:54.571Z - info: Build: 0.10.

Code

Plain text
iotkit-admin activate ACTIVATION_CODE

Code

Plain text
iotkit-admin register component_name component_id

Code

Plain text
iotkit-admin catalog

Code

Plain text
iotkit-admin register current current.v1.0

Code

Plain text
systemctl stop iotkit-agent
systemctl start iotkit-agent

Code

Plain text
peak-voltage-output = R1/(R1 + R2) x peak-voltage-input = 10k /(10k + 100k) x 12.7V = 1.15V

Code

Plain text
#include <IoTkit.h>    // include IoTkit.h to use the Intel IoT Kit
#include <Ethernet.h>  // must be included to use IoTkit
#include <aJSON.h>
#include <LiquidCrystal.h>

// create an object of the IoTkit class
IoTkit iotkit; 

const int vSensorPin = A0;
const int cSensorPin = A1;

const int numberOfSamples = 3000;

int sampleV, sampleC;
float voltageV, voltageC;
float instVoltage, instCurrent;

float sumI, sumV, sumP;

float realPower, apparentPower,reactivePower;
float powerFactor, voltageRMS, currentRMS;
unsigned long last_kWhTime, kWhTime;
float kiloWattHour = 0.0;

// RS, EN, D4, D5, D6, D7
LiquidCrystal lcd(7, 6, 2, 3, 4, 5);

void setup() {
  // put your setup code here, to run once:
 pinMode(7, OUTPUT); // not needed for arduino 
 pinMode(6, OUTPUT); // but must set as output for Edison LCD library
 pinMode(5, OUTPUT);
 pinMode(4, OUTPUT);
 pinMode(3, OUTPUT);
 pinMode(2, OUTPUT);
 iotkit.begin();
 lcd.begin(20, 4);
 lcd.setCursor(0, 1);
}

void loop() {
  // put your main code here, to run repeatedly:
  calculatePower();
  displayPower();
  sendToCloud();
  delay(2000);
}

void calculatePower(){
    for(int i=0; i<numberOfSamples; i++){
      
      sampleV = analogRead(vSensorPin);
      sampleC = analogRead(cSensorPin);

      voltageC = sampleC*5.0/1023.0;
      voltageV = sampleV*5.0/1023.0;

      instCurrent = (voltageC-2.5)/0.66;
      instVoltage = (voltageV-2.46)*7.8;

      sumV += instVoltage * instVoltage;
      sumI += instCurrent * instCurrent;

      sumP += abs(instVoltage * instCurrent);
      }

      voltageRMS = sqrt(sumV / numberOfSamples);
      currentRMS = sqrt(sumI / numberOfSamples);

      realPower = sumP / numberOfSamples;
      apparentPower = voltageRMS * currentRMS;
      powerFactor = realPower / apparentPower;
      reactivePower = sqrt(apparentPower * apparentPower - realPower * realPower); 

      last_kWhTime = kWhTime;
      kWhTime = millis();

      kiloWattHour += (realPower / 1000) * ((kWhTime - last_kWhTime) / 3600000.0);

      sumV = 0;
      sumI = 0;
      sumP = 0;
 }

void displayPower(){
   lcd.clear();
   lcd.setCursor(0,0); //col,row
   lcd.print("Voltage: ");
   lcd.print((int)voltageRMS);
   lcd.print("V  ");
   lcd.print("Current: ");
   lcd.print(currentRMS);
   lcd.print("A");
   lcd.setCursor(0,1);
   lcd.print("Power: ");
   lcd.print(realPower);
   lcd.print("W  ");
   lcd.print("pf: ");
   lcd.print(powerFactor);
   lcd.setCursor(0,2);
   lcd.print("VAR: ");
   lcd.print(reactivePower);
   lcd.print("VAR  ");
   lcd.print("VA: ");
   lcd.print(apparentPower);
   lcd.print("VA");
   lcd.setCursor(0,3);
   lcd.print("Energy used: ");
   lcd.print(kiloWattHour);
   lcd.print("KWH");
  }

void sendToCloud(){
    iotkit.send("voltage", voltageRMS);
    iotkit.send("current", currentRMS);
    iotkit.send("realpower", realPower);
    iotkit.send("powerfactor", powerFactor);
    iotkit.send("reactivepower", reactivePower);
    iotkit.send("apparentpower", apparentPower);
    iotkit.send("energy", kiloWattHour);
  }

Github

https://github.com/enableiot/iotkit-samples

Github

https://github.com/interactive-matter/aJson

Credits

Md. Khairul Alam

Md. Khairul Alam

64 projects • 569 followers
Developer, Maker & Hardware Hacker. Currently working as a faculty at the University of Asia Pacific, Dhaka, Bangladesh.

Comments