IoT Smart Energy Meter Using ESP32 and Blynk 2.0

In this project, we designed an open-source and modular IoT Smart Energy Meter using ESP32 and Blynk IoT 2.0. A Wi-Fi-based IoT network has been created to monitor daily energy consumption in our homes through smartphones and web dashboards. The system uses the ACS712 current sensor connected to the ESP32 development board to measure current and the ZMPT101B voltage sensor to measure voltage values. Real power, apparent power, and power factors can be calculated using these measured values and the phase angle.

The ESP32 development board, equipped with the ACS712 sensor, sends these measured and calculated values to the Blynk IoT platform. It provides a cloud server-based user interface where we can view these calculations and actual values. The interface is accessible via a web browser and mobile application using TCP/IP protocols. The system’s efficacy for general-purpose applications, such as IoT energy monitoring systems for smart home automation, has been demonstrated through experimental studies.

The electricity demand is crucial in our daily lives for technological development. Grid loading is managed for both residential and commercial consumers, requiring operators to distribute the load accordingly. Smart homes are designed to optimize energy consumption and support smart grids. The Internet of Things (IoT) plays a significant role in this context, encompassing industries like automotive, logistics, healthcare, smart grids, metro cities, and smart homes.

In this project, we focus on the Internet of Consumer Things (CIoT) systems. By monitoring and controlling home appliances like water heaters, air conditioners, and dishwashers, we can efficiently manage energy consumption. Traditional measuring methods, often labour-intensive and complex, are replaced by user-friendly CIoT systems with Wi-Fi-enabled devices. With widespread access to Wi-Fi networks, computers, and smartphones, this approach simplifies energy monitoring and management. The project also integrates Blynk 2.0 for enhanced mobile application control and uses a Telegram bot to generate and deliver energy consumption bills to users.

Must Read Smart Energy Monitoring System Using ESP32

Overview of IoT Smart Energy Meter

In this project, the SCT-013 current (CT) sensor has been replaced by the ACS712 current sensor for single-phase current measurement. Additionally, a 9V AC step-down transformer is used to measure the RMS value of the voltage. Both sensors are connected to the ESP32 board. Using the measured current, RMS voltage values, and phase angle, we can calculate the power factor, real power, and apparent power values within the Arduino IDE software.

The measured and calculated values are processed and transmitted by the ESP32 development board, using the Arduino IDE software. The ESP32, cloud server, and smartphone device communicate with each other via TCP/IP protocol over a Wi-Fi access point, creating an efficient CIoT network.

Smart IoT Energy Meter Using ESP32

Circuit Diagram

IoT-Smart-Energy-Meter-Using-ESP32-Circuit Diagram

Hardware Components

  • ESP32 Development Board
  • ACS712 Current Sensor
  • ZMPT101B Voltage Sensor
  • 16×2 I2C LCD Display Module
  • 40 Watt Bulb as Load
  • 5 Volt AC DC Converter
  • Connection Wires
  • Multimeter to Measure Voltage & Current (Additional)
  • AC Mains Power Supply

Software Components

  • Arduino IDE (Uploading Code)
  • Blynk 2.0 Platform (Configure Realtime Data Visualization)
  • Telegram (Generate Monthly Energy Consumption & Bill)

Understanding Components

ESP32 Development Board

It is a low-cost, minimal-power system on a microcontroller with integrated Wi-Fi and Bluetooth facility. ESP32 was created and developed by Espressif Systems, a Shanghai-based Chinese company, and it is manufactured by TSMC using its 40nm chip technology. In this project, we can use ESP8266 NodeMCU but there is only one analog pin that comes with it. And ESP32 have so many Analog pins. So according to our needs (Voltage and Current), we choose ESP32 despite ESP8266 NodeMCU.

ACS712 Current Sensor

The ACS712 current sensor is a popular device used for measuring current in a variety of applications, including energy monitoring and control systems. Here are some key points about the ACS712 current sensor:

  • Current Measurement: The ACS712 can measure both AC and DC. It comes in different variants to measure different ranges of current, such as 5A, 20A, and 30A.
  • Output Voltage: The sensor provides an Analog voltage output that is proportional to the current passing through the sensing element. This output can be read by an analog-to-digital converter (ADC) on a microcontroller like the ESP32.
  • Sensitivity: Depending on the version, the sensor has different sensitivities. For example, the ACS712-05B has a sensitivity of 185 mV/A, the ACS712-20A has a sensitivity of 100 mV/A, and the ACS712-30A has a sensitivity of 66 mV/A.
  • Accuracy and Response Time: The sensor is known for its good accuracy and fast response time, making it suitable for real-time current monitoring.
  • Isolation: The ACS712 provides electrical isolation between the high-power load and the low-power circuitry, ensuring safety and protecting the microcontroller.

ZMPT101B Voltage Sensor:

The ZMPT101B is a voltage sensor module designed to measure AC voltage in various applications. It’s commonly used in projects involving power monitoring, home automation, and other IoT applications where voltage measurement is needed. Here are some key features and details about the ZMPT101B voltage sensor:

  • High Accuracy: The ZMPT101B offers high accuracy in measuring AC voltage, making it suitable for precise applications.
  • Isolation: It provides electrical isolation between the high voltage being measured and the low voltage circuitry of the microcontroller, enhancing safety.
  • Wide Measurement Range: It can measure various AC voltages depending on the circuit design and calibration.
  • Analog Output: The sensor outputs an Analog voltage proportional to the input AC voltage, which can be read by an Analog-to-Digital converter (ADC) in a microcontroller.

Circuit Connection

ZMPT101B Voltage Sensor:

  • VCC (Power): Connect to ESP32 3.3V pin.
  • GND (Ground): Connect to ESP32 GND pin.
  • OUT (Analog Output): Connect to an ESP32 ADC pin (e.g., GPIO 34).

ACS712 Current Sensor:

  • VCC (Power): Connect to ESP32 3.3V pin.
  • GND (Ground): Connect to ESP32 GND pin.
  • OUT (Analog Output): Connect to another ESP32 ADC pin (e.g., GPIO 35).

I2C LCD Display:

  • VCC (Power): Connect to ESP32 3.3V pin.
  • GND (Ground): Connect to ESP32 GND pin.
  • SDA (Data Line): Connect to ESP32 GPIO 21 (SDA).
  • SCL (Clock Line): Connect to ESP32 GPIO 22 (SCL).

How to Create Blynk 2.0 Dashboard for IoT Smart Energy Meter

To set up Blynk 2.0 for your project, you’ll need to create a web dashboard and a mobile dashboard that can display real-time data for voltage, current, power, energy units, and total cost. Here’s a step-by-step guide:

Create a Blynk 2.0 Account and Project

Sign Up: If you don’t already have an account, sign up on the [Blynk 2.0 platform].

  • Create a New Template:
  • Go to the “Templates” tab.
  • Click “New Template”.
  • Give your template a name (e.g., “IoT Energy Meter”).
  • Set the hardware to ESP32.

Create Datastreams:

  • Navigate to the “Datastreams” section within your template.
  • Create data streams for each parameter you want to monitor:
  • Voltage: Select type Virtual Pin (V0).
  • Current: Select type Virtual Pin (V1).
  • Power: Select type Virtual Pin (V2).
  • Units Consumed: Select type Virtual Pin (V3).
  • Total Cost: Select type Virtual Pin (V4).

Save Template: Save your template and copy the “Template ID” and “Device Name” for later use.

Set Up the Blynk Web Dashboard

Create a New Device:

  • Go to the “Devices” tab.
  • Click “New Device” and select the template you created.
  • Follow the prompts to configure the device.

Web Dashboard Setup:

  • Navigate to the “Web Dashboard” tab of your device.
  • Drag and drop widgets for displaying your data:
  • Gauge and Label widgets for Voltage, Current, Power, Units Consumed, and Total Cost.
  • Link each widget to the corresponding data stream.

Configure Widgets: For each widget, set the label, datastream, and display settings (e.g., units, range).

Set Up the Blynk Mobile Dashboard

  • Download Blynk App: Install the Blynk IoT app from the App Store or Google Play.
  • Log In: Log in with the same account credentials used for the web dashboard.
  • Add a Device: Add the device corresponding to your template.

Mobile Dashboard Setup:

  • Tap on the device to enter the dashboard setup.
  • Add widgets similar to the web dashboard.
  • “Gauge” and “Value Display” for Voltage, Current, Power, Units Consumed, and Total Cost.
  • Assign each widget to the appropriate data stream.

Configure Widgets: Set the label, datastream, and display options (units, decimals, etc.).

This setup allows you to monitor voltage, current, power, energy units, and total cost through both web and mobile dashboards. You can also set up notifications and alerts using Blynk’s features for a comprehensive energy monitoring solution.

How to Create a Telegram Bot and Implement with IoT Smart Energy Meter

Creating and integrating a Telegram bot with an IoT smart energy meter for billing involves several steps, including setting up the bot, coding the ESP32 to communicate with Telegram, and implementing the billing logic. Here’s a step-by-step guide:

Create a Telegram Bot:

Create the Bot:

  • Open the Telegram app and search for “BotFather”.
  • Start a chat with BotFather and use the command /start.
  • Use the command /newbot to create a new bot.
  • Follow the prompts to name your bot and set a username. The username must end with “bot”.
  • After creating the bot, you’ll receive a “Bot Token”. This token is essential for connecting your bot to Telegram’s API.

Get Your Chat ID:

  • You’ll need their chat IDs to send messages to yourself or specific users.
  • You can use the bot to find your chat ID by sending a message to your bot and then using an online service like ‘https://api.telegram.org/botYOUR_BOT_TOKEN/getUpdates‘ to get your user ID.

Set Up the ESP32 to Communicate with Telegram

Install Required Libraries: In the Arduino IDE, install the ‘UniversalTelegramBot’ and ‘WiFiClientSecure’ libraries.

Connect ESP32 to Wi-Fi: Configure the ESP32 to connect to your Wi-Fi network.

Send Messages to Telegram: Use the ‘UniversalTelegramBot’ library to send messages from the ESP32 to Telegram.

Implement Billing System:

Calculate Energy Consumption and Cost:

  • Track the total energy consumed using the power data from your sensors.
  • Calculate the total cost based on a predefined rate per unit of energy.

Send Billing Information to Telegram: Implement a function in your code to send billing details to the user via the Telegram bot.

ESP32 Code for IoT Smart Energy Meter

Deploy and Monitor:

  • Deploy the ESP32: Upload the code to your ESP32.
  • Monitor Telegram: The bot will send billing information to the specified chat ID at regular intervals.

Additional Considerations

  • Security: Ensure that your bot token and Wi-Fi credentials are kept secure. Avoid hardcoding sensitive information directly into your code if possible.
  • Customizations: You can add more features, such as real-time alerts for high consumption, commands to request the current bill or additional data visualization.

Video Output

Leave a Comment