Introduction: Domotic Energy Meter

Integrate power metering to a domotic system is very useful not only for statistic and economic reason but either to promptly recognize and manage overload and prevent automatic shutdown from the smart meter.

There a lot of project in the net using Arduino or Rasperry PI.

What I'm looking for is:

  • Power sensor that could be easily integrate with new function
  • Fully programmable over LAN without a physical access over USB port or SD card
  • Capable to be as much autonomous has possible. If the domestic server is temporary down I need to read actual power consumption or maybe integrate locally controlled power relays

Arduino based project are very cheap and reliable but if you need to modify you firmware it's difficult to do this without a physical access to the board to reload the firmware.

Raspberry PI is very versatile and is fully programmable over the LAN but in my opinion the number of logic port is very poor (I assume this is my opinion please RaspberryPI enthusiast don't feel offended :) )

So why don't use BOTH of them?

This project take the best from Arduino and RaspberryPI in order to have the expandability and easy to manage logic port of an Arduino and the versatility in term of integration and remote programming of a RaspberryPI

Step 1: List of Material

Before to start I recommend to have at least the following parts:

  • Arduino UNO (or any other version of Arduino you prefer)
  • RaspberryPI (choose the one you prefer from version 1 to 3, my suggestion is to use the first version is cheaper and has sufficient resource for this kind of task)
  • A SD card to store RaspberryPI OS
  • 2 * 10Kohms and 5% tolerance resistor (brown-black-orange-gold code)
  • 10uF ALUMINUM ELECTROLYTIC CAPACITOR
  • SCT-013-000 AC Current Sensor
  • USB Cable
  • 0.96" 128x64 White Graphic OLED Display Module - SPI,I2C

Setup is very minimal and simple is up to you decide if connect resistances and capacitor using direct connection or to build a simple pcb (I'm an electronic hobbyist and I've choose for the second option :))

OPTIONAL: A dog to maintain the proper inspiration :)

Step 2: Connect All

All the job works around your Arduino so first of all wire the connection toward oled display following the instruction reported.

Be very careful regarding VCC you OLED works with 3.3V and NOT the native 5V o you Arduino so use the proper pin.

Connect capacitor and resistances to the current sensor and attach the white wire of the sensor to the analog pin 1 of you Arduino.

Now you can flash the Arduino and perform the first tests

Step 3: Flash the Arduino

I'll skip any detailed step related to how to add library to Arduino because you can find plenty of instructables.

I'll provide two libraries: HCuOLED is the controller of the OLED display while EmonLib provide to you the primitives to convert the information read from the analog input of the Arduino to an understandable measure in term of Ampere and Watt (either for this point please refer to the very good job that you can find here).

Now you can compile and flash the provided .ino files (feel free to modify and maybe improve).

Step 4: First Test

If everything is working now you can connect your sensor to a load and read the actual power consumption in KW (but you can modify the code in order to read also Ampere).

If you aren't able to read any measure you need to be careful to the following possible issues:

  • remember that the sensor has a versus (marked with an arrow)
  • The sensor come with tho wire (red and white) be sure that the wire connected to the Arduino is the withe one
  • probably you capacitor is broken

If you read something but is very far from a good value please refer to the proper library description here. There is a very simple primitive that let you able to adjust the read value in order to improve precision.

Following this example you can find the call to the .current method in where you can adjust the multiplier in order to obtain the proper result (follow the complete calibration procedure here).

#include "EmonLib.h"                 
EnergyMonitor emon1;
void setup()
{  
  Serial.begin(9600);
  emon1.current(1, 111.1);             // Current: input pin, CALIBRATION.
}
void loop()
{
  double Irms = emon1.calcIrms(1480);  // Calculate Irms only
  
  Serial.print(Irms*230.0);	       // Apparent power (230 is the Voltage)
  Serial.print(" ");
  Serial.println(Irms);		       // Irms
}

Step 5: Raspberry PI Connection

Avoiding any further info on how to setup a Raspberry PI I'll concentrate only to the basic step useful to interconnect to the Arduino, retrieve and parse the data and do whenever you want with it.

First of all you need to use the USB cable to direct attach (and power) the Arduino.

At this point the Arduino board is sending you via USB Serial channel the data. The only think you need to do is parse and use it.

In my installation I've connected the sensor to a Domoticz server so in the provided example you'll find the call that send the read data to it. Anyway you can choose if avoid to use a RaspberryPI connecting you Arduino board directly to your network using an Ethernet or Bluetooth shield.

I've adopted this configuration because I've installed in the Raspberry PI also the Arduino IDE in order to remotely update and flash the Arduino.

Step 6: Enjoy You Smart Meter

Now you're able to use you real time consumption data in order to keep track of your daily consumption, enable alarm if you pass limit or if you read power usage when you are away.