IoT Based Energy Consumption Cost Calculator Using ESP8266

In this project, an open-source and modular IoT based energy consumption cost calculator is designed and implemented. A Wi-Fi-based IoT network has been designed which has the capability of monitoring daily energy consumption in our homes through our smartphones. In the IoT network, the voltage values will be constant and the current will be varying according to the current sensor SCT-013 (upto 30A) connected to the ESP8266 NodeMCU board. Real-time power, current and total kilowatt can be calculated by using measured current, voltage values and phase angle.

These measured and calculated values have been sent to the ESP8266 NodeMCU board by software serial method. The ESP8266 provides the cloud server-based user interface where we can see these calculations and actual values. It uses a Wi-Fi access point connection. The user interface is displayed via the mobile application with TCP/IP protocols. This system shows the actual energy consumption as well as total costs per month. Experimental studies prove that this system could be used in general-purpose applications such as IoT energy monitoring systems for smart home automation systems.

Must Read Smart Energy Monitoring System Using ESP32

Principle Behind Energy Consumption Cost Calculator

In this project, the SCT-013 current (CT) sensor is used for single-phase current measurement. We can calculate the total power, current and apparent power values using the measured current, RMS predefined voltage values and phase angle in the Arduino IDE software.

The measured and calculated values have been sent to the ESP8266 board by using Arduino IDE software. The ESP8266, cloud server and smartphone device communicate with each other with TCP/IP protocol via a Wi-Fi access point in the designed IoT network.


Energy Consumption Cost Calculator

Circuit Diagram

Energy Consumption Cost Calculator Circuit Diagram
Energy Consumption Cost Calculator Circuit Diagram

Components Required

  • ESP8266 NodeMCU
  • SCT-013 Current Sensor (Upto 30A)
  • 5 Volt Hi-Link AC-DC Converter
  • 10KΩ Resistor (x2)
  • 100Ω Resistor
  • Veroboard
  • Wires

Circuit Connection Energy Consumption Cost Calculator

Now let me discuss the circuit diagram of the IoT-based energy consumption cost calculator system using the ESP8266 board. The circuit has been designed using EasyEDA software.

The connections are so simple. The ground pin of the sensor is connected to the ground pin of the ESP8266. The output Analog pin of the voltage sensor is connected to the A0 pin of the ESP8266. After that two 10KΩ resistors and a single 100Ω resistor are connected along with a 10uF/25V electrolyte capacitor.

Apart from that, we need to measure the real-time AC current that is connected to the AC phase wire. Similarly, the current sensor clip doesn’t have any connections, just clip a phase or neutral wire and lock it. Don’t clip both phase and neutral wires otherwise the reading will go wrong.

Cloud Server Creation for Energy Consumption Cost Calculator

For this project, we use the Ubidots application that runs over Android and IOS devices as well as a web browser to control any IoT devices using smartphones and computer dashboards. It allows you to create your graphical user interface for IoT applications.

  • First download and install the Ubidots application from Google Play Store. Also, IOS users can download it from the IOS App Store. Once the process is done, start the app and sign-up using your email id and password.
  • Now click on Devices→Devices→click on the Add New Device button→select Blank Device→type device name→finally click on Create button which is symbolized with a green tick. So you successfully create your own device.
  • Go inside your device and now here add variables. Select Add Variables→select Raw→name the variable as “Current”. After successfully creating a variable, click on the Ubidots logo from the upper left-hand side which will open the home page
  • Here click on Add New Widget→select Gauge→click on Add Variables→now go inside nodemcu→select Current. Now here we need to name the variable as Current and define the range as 0 to 30.
  • Now we need to enter the token in the code and for that click on Profile→Api Credentials→click on the blank space of the default token section→when the token is visible copy this.
  • For adding rupees in amount, we just need a synthetic variable. For that go to Devices→Devices again→enter into the “nodemcu”→Add Variables→select Synthetic. We can add different types of modified calculations for our needs. For now first select “nodemcu”→then Current.
Ubidots Synthetic Variable

These two sections i.e., “voltage = 235” and “amount in rupees = 6” will change according to different locations.

The formula for rate of current in rupees ((235*(current (nodemcu))*6)/60000).

  • Do the same process as adding current variable into the dashboard.
Ubidots Dashboard

NodeMCU Code

For compiling the code we also need the ESP8266 board manager. Just click on File→Preferences→Paste the link in Additional Board Manager URLs→OK. Link: Next, click on Tools→Boards→Boards Manager→Search ESP32→Install→OK.

Also, we need additional library files i.e., Ubidots-MQTT-ESP, PubSubClient.h to compile the code.

#include "UbidotsESPMQTT.h"const int ACPin = A0;         //Define input pin for current sensor#define ACTectionRange 30;    //Set Non-invasive AC Current Sensor tection range (5A,10A,20A,30A)#define VREF 3.28   //Define reference voltage#define TOKEN "BBFF-phdC1OrWt3OfXbXa7S7dqAfjtognNm" //Ubidots default token#define WIFINAME "Wifi Name" //Your SSID#define WIFIPASS "Wifi Password" //Your WiFi PasswordUbidots client(TOKEN);void callback(char* topic, byte* payload, unsigned int length) {  Serial.print("Message arrived [");  Serial.print(topic);  Serial.print("] ");  for (int i = 0; i < length; i++)   {    Serial.print((char)payload[i]);  }  Serial.println();}float Rate_of_Current_Value_per_min = 0;float Current_Value = 0;float Power = 0;float amount_consumed = 0;float readACCurrentValue(){  float ACCurrtntValue = 0;  float peakVoltage = 0;  float voltageVirtualValue = 0;  //Vrms  for (int i = 0; i < 5; i++)  {    peakVoltage += analogRead(ACPin);   //Read peak voltage    delay(1);  }  peakVoltage = peakVoltage / 5;  voltageVirtualValue = peakVoltage * 0.707;    //Change the peak voltage to the virtual value of voltage    voltageVirtualValue = (voltageVirtualValue / 1024 * VREF ) / 2;   //The circuit is amplified by 2 times, so it is divided by 2  ACCurrtntValue = voltageVirtualValue * ACTectionRange;  return ACCurrtntValue;}void setup(){  client.ubidotsSetBroker("");  client.setDebug(true); // Pass a true or false bool value to activate debug messages  Serial.begin(115200);  client.wifiConnection(WIFINAME, WIFIPASS);  client.begin(callback);}void loop(){  for (int k = 0; k < 60 ; k++)  {    float ACCurrentValue = readACCurrentValue(); //read AC current value    Serial.print(ACCurrentValue);    Serial.println(" A");    Current_Value += ACCurrentValue;    delay(1000);  }  Rate_of_Current_Value_per_min = Current_Value / 60;  Serial.print("Rate of Current in a min"); Serial.print(Rate_of_Current_Value_per_min); Serial.println(" Am");  if (!client.connected())  {    client.reconnect();  }  client.add("current", Rate_of_Current_Value_per_min);  client.ubidotsPublish("nodemcu");  client.loop();  Rate_of_Current_Value_per_min = 0;  Current_Value = 0;}

Post a Comment

Previous Post Next Post