Energy Usage Notifier
ESP8266 can be used as IoT device with it's large processing capability and wifi connectivity. We used NodeMCU Boards here as it's already have voltage divider, helping us measuring analog input easily. This Energy Meter depend on current reading sensor (SCT-013) to determine the AC current flowing on a cable. To get energy measurement we are going to need two sensor, one for voltage and the other for current reading. Reminder that working with main electricity can be harmful so know the safe practice procedure before you build this. Do this project at your own risk.
Supplies
1x NodeMCU ESP8266
1x 1000 Ohm Potentiometer
2x 1K Resistor
1x SCT-013 000
1x Breadboard
8x Wiring Cable
How It Works
Some of you might already know about current transformer in highschool. It used magnetic inductance effect to transfer energy from one coil to the other, where the number of turns will decide the amplification of the voltage input at transformer output. Remember when you experiment with the transformer, when you try to supply DC current into the transformer no voltage induced on it's output that's because you need changing magnetic field to transfer the energy. By Supplying DC current there will be no change in the magnetic field thus no voltage induced on the output side of the transformer. The thing is to create voltage difference on a wire require changing magnetic field which doesn't happen on DC current as it only flow in one direction. That is why the SCT sensor will only works on AC circuit.
Select Burden Resistor
In this part we will try to calculate the burden resistor. In my case, I want to measure current up to 6A and since my main circuit is 230V, it can measure up to 1380 Watts. Thing is the higher the max current you set the less resolution you get out of it. NodeMCU has 10bit ADC at 3.3V mean it can detect 1024 level from 0V to 3.3V and you can detect 3.2 mV change. When we measure 6A on mains we got induce current of 0.003A (SCT-013 has 2000 turns) and we want to convert this current into voltage, that's the reason why we need to calculate the burden resistor as it will decide the maximum voltage of the sensor. We use Rburden = Vmax/Imax to calculate the burden resistor, pluging in the numbers will result of 412 ohm resistor.
Build the Schematic on Breadboard
I mostly follow this Schematic from openenergymonitor as a guide. Without that NodeMCU can't read the SCT sensor, with the help off this schematic this NodeMCU now are capable of reading the sensor. That schematic help to offset voltage from the sensor as the voltage will sometimes be outside of the NodeMCU voltage range.
Time to Program
Programming Internet connected sensor is a bit different from your standard arduino program. What you need to keep in mind is, internet is asynchronous io type and can be categorized as event driven programming. Any program in these area can be disconnected at moment notice or having high latency which result in timing inconsistency. Blynk mostly help in this area by literally polling some server every milisecond or less which result in some code to run out of time than intended. This might be make or break situation depending on your project, but in our case we only want to send notification to users which is not time strict event.
Blynk Timer here help us to call certain function we want to call periodically. In this project we use blynk timer to send notification, current power usage to Blynk, and even sensor reading. Sensor reading for electricty require us to sample 50 Hz (Main Circuit) signal, that will make us do sampling atleast two times the main frequency. Fortunately this works okay-ish (not to accurate but it's enough), but with some trial and error i found that 250 Hz sampling works great (with some occasional disconnect). You can change this variable called "UpdateRate" to change the sampling period.
Now to calculate the power we're going to need current reading and some constant voltage variable. You will need to change this variable as well, to match your main voltage. Don't forget to change ssid and password variable before running the code. Code can be downloaded at the button below.
Downloads
Create Blynk View
This is probably the easiest part when building this project. Widget you need is SuperChart, Value Display, and Text Input. Put all the widget mention on to the main page by dragging it to the center of your screen. Now Configure each widgets with the respective VirtualPin (SuperChart -> V0, Value Display -> V10, Text Input -> V2, Button -> V3). After that you can run the blynk app by pressing play button on the right side corner.
Plug-in the Power to NodeMCU
But before that you want to have your appliance turn off before you run the NodeMCU. Latch the sensor into one of the cable that run from mains then you can turn on the MCU. After you got Device Connected Notification then you can run the appliance you want to measure. That is it, now you are able to see historical graph and set your define notification threshold.
Some Thought
This device only able to measure apparent power which is not bad if you use this to measure resisitve load. It can be improved by adding voltage sensor but you will need to upgrade to higher spec esp32 for the added Analog Pin. After some thought about blynk timer will drifting over time, it's probably doesn't matter since this MCU clocked higher than any Arduino board I have used. Well that's it thank you for reading till the end.