Project tutorial

Sigfox kWh Meter © GPL3+

What if our old electric energy power meter with rotary disk could be connected to the Internet?

  • 5,525 views
  • 7 comments
  • 14 respects

Components and supplies

Apps and online services

About this project

1) In a nutshell

This tutorial will help you create a device that will connect your old inductive power meter to the Internet. And what kind of meter exactly is it? It is the kind of oldest, but still used power meter. It has the rotary disk, which has reflective paint all the way round it with a little black stripe. Each time you see that black part passing by, it means one rotation has been completed. In this project 120 turns are equal to consumption of 1 kWh.

2) Microcontroller, IoT network and other stuff used

So, we will need Arduino MKRFOX1200, which has the Sigfox (and that is the network) connectivity. Sigfox is LPWAN network, that allows to connect anything to the Internet. The network works in ISM band 868 MHz and allows us to send 140 messages (12 bytes of payload each) daily uplink. But that is not all just about network. Sigfox gives us an opportunity to customize the way we want to work with messages. In fact all messages are stored on Sigfox cloud, from where we can retrieve them by defining their destination - callbacks, etc.

ThingSpeak:

ThingSpeak is an IoT platform for the user-friendly display of data. In this project it is the Sigfox callback destination that displays received consumption using charts as soon as the transfer occurred.

One more time - which electric energy power consumption meter will we use?

This one:

3) Practical stuff

  • 1. Connect all listed parts as shown in the wiring diagram. I will not explain the theory behind connection, if anything is unclear, feel free to ask. Do not forget to give it some juice :) (usb power bank, or your laptop usb output, etc.).
  • 2. Write a code. You will find the Code attached on the bottom of this page. Again, if anything in code is unclear to you, feel free to ask.
  • 3. Create ThingSpeak Channels with Analysis. Register on https://thingspeak.com/ and create channel no. 1 by giving it name, description and Field 1 - Consumption. Create channel no. 2 based on channel no. 1, but with different name. Then select Matlab Analysis option on channel no. 2 and write the following code:
readChannelID = TYPE_CHANNEL1_ID_HERE;
readAPIKey = 'TYPE_CHANNEL1_READ_API_KEY_HERE'; 
writeChannelID = TYPE_CHANNEL2_ID_HERE;
writeAPIKey = 'TYPE_CHANNEL2_API_KEY_HERE';
data = thingSpeakRead(readChannelID, 'ReadKey', readAPIKey,'OutputFormat','table'); 
analyzedData = data;
analyzedData.('Consumption') = (data.('Consumption') + YOUR_CURRENT_CONSUMPTION_STATUS_IN_WH)/1000 ;
thingSpeakWrite(writeChannelID, analyzedData, 'WriteKey', writeAPIKey);
  • 4. Create Sigfox Callback. I hope you already registered yours MKRFOX1200 in backend so I am gonna skip tutorial on how to do this. After you logged in on https://backend.sigfox.com/ go to the callbacks section and create one as following:
  • TYPE: DATA UPLINK
  • CHANNEL: URL
  • CUSTOM PAYLOAD CONFIG: status::uint:32:little-endian
  • URL PATTERN: https://api.thingspeak.com/update?api_key=EXPLAINED1&field1={customData#status}
  • USE HTTP METHOD: GET

*EXPLAINED1 - replace this with Channel 1 ThingSpeak WriteApiKey

4) Device installation & logic behind

So you already have accomplished most difficult parts of this project. Now attach the CNY70 sensor to the glass of your power meter with double sided tape - take care to place it on the centre of rotary disk (fig. Installation). Next, press the device button two times and do the calibration - if the sensor reads reflective part of disk, the diode should light up. If the sensor reads black stripe, the diode should go off. After successful calibration, press the device button one more time. Now the device starts reading the power consumption and sends this value every 30 minutes to Internet using Sigfox. The precision of reading is set to 25 Wh (in our case every 3 disk turns).

5) Final Output

After all these steps you will be able to see your actual electric energy consumption in a beautiful ThingSpeak chart as below.

Code

Sigfox kWh electric energy power meterArduino
This is .ino code for making your power meter intelligent.
#include <SigFox.h>

int DIODE = 13;
int BTN = 12;
int BTN_state = 0;
int BTN_prev = 0;
int BTN_NR_OF_PRESS = 0;
int CALC = 0;
unsigned long i = 0;
uint32_t CONSUMPTION = 0;
boolean SHINE = false;
boolean KARDAN = false;


void setup() {

  pinMode(DIODE, OUTPUT);
  pinMode(BTN, INPUT);
  Serial.begin(9600);
  if (!SigFox.begin()) {
    Serial.println("Sigfox module unavailable.");
  }

}

void loop() {


  int senzor = analogRead(A3);


  BTN_state = digitalRead(BTN);

  if (BTN_state != BTN_prev) {
    if (BTN_state == HIGH) {
      BTN_NR_OF_PRESS++;
    }
  }

  BTN_prev = BTN_state;

  if (BTN_NR_OF_PRESS % 3 == 0) {

    if (senzor > 300 && senzor < 950) {
      digitalWrite(DIODE, HIGH);
    }
    else {
      digitalWrite(DIODE, LOW);
    }
  }




  if (senzor < 1020 && SHINE == false)
  {
    SHINE = true;

  }
  if (senzor > 1020 && SHINE == true && BTN_NR_OF_PRESS == 4)
  {
    CALC++;
    SHINE = false;


  }
  if (CALC % 3 == 0 && CALC != 0 && KARDAN == false)
  {
    KARDAN = true;
    CONSUMPTION += 25;
  }
  if (CALC % 3 != 0) {
    KARDAN = false;
  }

  if (BTN_NR_OF_PRESS % 4 == 0) {
    digitalWrite(DIODE, LOW);


    if (SHINE == false)

    {



      for (millis(); (millis() - i) > 1800000;) {
        i = millis();
        SigFox.debug();
        SigFox.beginPacket();
        SigFox.write(CONSUMPTION);
        SigFox.endPacket();
      }

    }
  }


}

Schematics

Sigfox kWh electric energy power meter
Schematic for connection of MKRFOX1200 with CNY70 and other stuff.
Schema ujbtua96w8

Comments

Similar projects you might like

Lightpipe 7-Segment Display

Project tutorial by Brian Lough

  • 2,312 views
  • 3 comments
  • 6 respects

ElBanquos 1D Pong

Project showcase by ElBanquo

  • 149 views
  • 2 comments
  • 2 respects

Arduino Spider Robot (Quadruped)

Project tutorial by MEGA DAS

  • 1,970 views
  • 1 comment
  • 14 respects

PENXZYL: Arduino 3-Axis Brush Plotter

Project showcase by Guiye Perez Bongiovanni

  • 4,429 views
  • 4 comments
  • 20 respects

Google Chrome Dinosaur Game on 16x2 LCD Shield

Project showcase by brzi

  • 364 views
  • 1 comment
  • 7 respects

Arduino Pressure Measuring and Logging

Project tutorial by Fillbee

  • 122 views
  • 0 comments
  • 1 respect
Add projectSign up / Login