Non-Invasive Smart Electricity Meter

A non invasive current sensor is connected to the spark core (with a few components), and clamped around a cable in the Mains distribution unit. No wiring is required, however Do not try this at home, as the Mains Distribution Unit should not be tampered with unless one is Licensed to do so.
 
Non-Invasive Smart Electricity Meter
The back end is Web Application hosted on a LAMP (Linux Apache MySql PHP) setup. Initially it was hosted on a raspberry pi on a LAN, but then I decided to host it on a hosted server. Both instances worked well, its just a matter of preference.
The spark core simply takes periodic readings and sends them to the server, where all of the calculations and filtering is done.

The project uses the EmonLib Library for Electricity
Untitled file
// This #include statement was automatically added by the Spark IDE.

#include "HttpClient/HttpClient.h"
#include "application.h"
#include "EmonLib.h"
#include <string.h>

HttpClient http;
http_request_t request;
http_response_t response;
http_header_t headers[] = {

      { "Content-type", "application/x-www-form-urlencoded" },
    { NULL, NULL } // NOTE: Always terminate headers will NULL
};

EnergyMonitor emon1;                   // Create an instance
TCPClient client;
const int voltage = 220;
double average = 0.0; // interval at which to do something (millisecond)
double sum = 0.0; // interval at which to do something (milliseconds)
int count = 0; // interval at which to do something (milliseconds)

static unsigned long secondInterval = 1000;
static unsigned long minuteInterval = 57000;
static unsigned long prevMinute = 0;
static unsigned long prevSecond = 0;
unsigned long now;

void setup()
{
  Serial.begin(9600);
  emon1.current(0, 103.1);
}



void loop()

{
   unsigned long currentMillis = millis();
    if ((unsigned long)(currentMillis - prevSecond) < secondInterval){
    return;
        }
    else{

        double Irms = emon1.calcIrms(1480);  // Calculate Irms only
        //double watts = (Irms*voltage) - 16;  // Calculate Irms only
        double watts = (Irms*1000) ;  // Calculate Irms only
        sum = sum + watts;
        count = count + 1;
        if ((unsigned long)(currentMillis - prevMinute) < minuteInterval){
        return;
        }
        else{
            average = sum/count;
            sendWatts(average);
            average = 0.0;
            sum = 0.0;
            count = 0;
            prevMinute = currentMillis;
        }
        prevSecond = currentMillis;
        }
}

void sendWatts(double wattreading){
    String val = "watts=" + doubleToString(wattreading,2);
    request.hostname = "yourhost.com";
    request.port = 80;
    request.path = "/php/insertConsumption.php";
    request.body = val ;
    http.post(request, response, headers);
}


String doubleToString(double input,int decimalPlaces){
    if(decimalPlaces!=0){
    String string = String((int)(input*pow(10,decimalPlaces)));
    if(abs(input)<1){
    if(input>0)
    string = "0"+string;
    else if(input<0)
    string = string.substring(0,1)+"0"+string.substring(1);
    }

    return string.substring(0,string.length()-decimalPlaces)+"."+string.substring(string.length()-decimalPlaces);

    }
    else {
    return String((int)input);
    }

}

For more detail: Non-Invasive Smart Electricity Meter


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top