The rising energy costs and global warming has forced us to keep an eye on our energy consumption. An energy management system can help monitor, control and reduce the energy consumption significantly. Above all, being able to monitor it from a phone makes it much more convenient. Statistics reveal that the energy monitoring and managing systems can reduce energy costs from 8% up to 20%, which is a big deal.

Hardware Used

Software Used

Libraries Used

Application Description

ESP32 DevKitC Board

The ESP32 DevKitC Board is one of the development board created by Espressif to evaluate the ESP-WROOM-32 module. It is based on the ESP32-microcontroller that boasts integrated WiFi and Bluetooth, along with an array of built-in antenna switches, and ultra-low power consumption.

Pin Mapping

Device Summary

  • Microcontroller: Tensilica 32-bit Single-/Dual-core CPU Xtensa LX6
  • Operating Voltage: 3.3 V
  • Input Voltage: 7-12 V
  • Digital I/O Pins (DIO): 28
  • Analog Input Pins (ADC): 8
  • Analog Outputs Pins (DAC): 2
  • UARTs: 3
  • SPIs: 2
  • I2Cs: 3
  • Flash Memory: 4 MB
  • SRAM: 520 KB
  • Clock Speed: 240 Mhz
  • Wi-Fi: IEEE 802.11 b/g/n/e/i:
  • Integrated TR switch, balun, LNA, power amplifier and matching network
  • WEP or WPA/WPA2 authentication, or open networks

How does it work?

The ESP32 DevKitC Board works similar to an Arduino Uno but has more features and superior capabilities. ESP32 has both WiFi and Bluetooth built into it whereas an Arduino Uno doesn’t. It also has a larger memory and faster clock speed. You can still use the Arduino IDE to program it by installing the ESP32 board in the IDE’s Boards Manager.

First, open the preferences window from the Arduino IDE and go to File Preferences. After that, enter into the “Additional Board Manager URLs” field as shown in the figure below. Then, click the “OK” button.

Once that is done, open boards manager by going to Tools > Board > Boards Manager and serch for ESP32, then press the install button for the ESP32 by Espressif Systems.

ZMPT101B AC Voltage Sensor Module

The ZMPT101B is a voltage transformer ideal for measuring AC voltage. It has high accuracy and good consistency in voltage and power measurement. The module is simple to use and comes with a multi-turn trim potentiometer for adjusting and calibrating the ADC output.


  • Input Voltage: 0-250 V AC
  • On-board micro-precision voltage transformer
  • Analog output corresponding quantity can be adjusted
  • Output Signal: Analog 0-5 V
  • Operating temperature: 40 °C~+70 °C

SCT-013-030 Non-invasive AC Current Sensor

The Non-invasive AC Current Sensor is a current transformer can be clamped around the supply line of an electrical load to measure the current. It does this by acting as an inductor and responding to the magnetic field around a current-carrying conductor. By reading the amount of current being produced by the coil, the current passing through the conductor can be calculated. They are particularly useful for measuring whole building electricity consumption or generation.


  • Input Current: 0-30 A AC
  • Output Signal: DC 0-1 V
  • Non-linearity: 2-3 %
  • Build-in sampling resistance (RL): 62 Ω
  • Turn Ratio: 1800:1
  • Resistance Grade: Grade B
  • Work Temperature: -25 °C~+70 °C
  • Dielectric Strength (between shell and output): 1000 V AC / 1 min 5 mA

Hardware Setup

Voltage Sensor Module Connections

  • OUT connected to ESP32 DevKitC Board pin G35
  • Vcc and Gnd connected to 5V and Ground respectively

Non-invasive AC Current Sensor Connections

The connections for this sensor is a bit more complicated than the voltage sensor as it requires external components. However, please read these warnings carefully before proceeding, for it could be dangerous if not followed.

  • A burden resistor is required. If an unburdened current transformer is attached to a current-carrying conductor, the current transformer will generate an unsafe voltage at its leads which could break down the insulation and destroy the device.
  • Always connect the current transformer leads before clipping it round a current-carrying conductor, and always unclip the current transformer from the current-carrying conductor before disconnecting its leads.
  • Never open-circuit the current transformer whilst it is on a current-carrying conductor. It is always safe to short-circuit it.
  • Never attempt to fit the current transformer to a bare conductor unless you are absolutely certain it is designed for that.

Calculating for Suitable Burden Resistor Value

Now, we must calculate for the value of the burden resistor to use. Since we’re using the SCT-013-030 which has a limit of 30A, our maximum peak current would be:

With the primary peak-current, divide it by the number of turns in the current transformer to give the peak-current in the secondary coil. The number of coils and its other properties can be found in its datasheet.

To maximize measurement resolution, the voltage across the burden resistor at peak-current should be equal to one-half of the analog reference voltage. In this case, we’re using 5V so the voltage across the burden resistor is 2.5V.

Since 106.6667Ω is not a common resistor value, we pick the nearest smaller value which is 100Ω so the maximum load current will not create a voltage higher than 5V.

Blynk App Setup

Download the Blynk app for your smartphone on your phone’s Google Play Store or iTunes App Store.

After downloading the app, click the app and it will direct you to the Log In page. You may either Log In with your Facebook Account, or Create New Account, or Log In if you’ve used the Blynk app before. Once that’s done, create a new project by clicking “New Project.”

Name the project and make sure to pick ESP32 Dev Board for the device and WiFi for the connection type since those are what we’re going to use.

Click the “+” icon on the top right to add components or widgets. For the best visual display in this project, we’ll use the Gauge widget.

Set up four of them. Two for the AC voltage and current and another two for the power and kilowatt-hour. You can click on them to change their label, color, and set the virtual pin. More importantly, make sure the AC voltage gauge pin is set to V0, the AC current gauge pin is set to V1, power gauge pin is set to V2, and kilowatt-hour gauge pin is set to V3. This will make sense later in the code.


Code Breakdown


First, we define the Blynk print serial for debugging purposes. Next, the libraries we need for the program have to be included. EmonLib handles the retrieval of data from both sensors as well as the calculation for the RMS and power values. BlynkSimpleEsp32 is needed to integrate our program to the Blynk Mobile app.

The EnergyMonitor object emon is then created and calibration values are defined. These values have to be obtained via trial and error depending on the setup so it can be different for everyone. The Blynk timer object is also created to handle the sending of data to the Blynk mobile app.

This is where you input the auth token of your Blynk mobile app, your WiFi SSID, and its password. You can obtain the auth token from your app by going to the project settings (nut icon). You can choose to copy it from there or have them email it to you.

These values have to be initialized to be used later on in the calculations. The kWh starts at 0 and will slowly build up as time goes on.

Timer Event Function

This section of the code is where the retrieval of values from the sensors are happening and where they are being calculated. In emon.calcVI(20, 2000), the real power, apparent power, power factor, Vrms, and Irms are being calculated. In our case, we only need the Vrms, Irms, and apparent power so we get those using emon.Vrms, emon.Irms, and emon.apparentPower respectively then print them in the Serial monitor for debugging purposes. We then use Blynk.virtualWrite to send the data to Blynk based on the virutal pins set.

For the kilowatt-hour, we slowly add it up as times goes. The formula is power*timePassed/3600*1000*1000. 3600 is there to convert milliseconds to seconds, 1000 is to convert seconds to hours, and another 1000 is to convert watts to kilowatts.

void setup()

Inside the setup() function, we set the serial baud rate to 9600 bps which is the default for serial communication. Then we set the voltage and current sensor pins along with their calibration values. Blynk has to be initialized here as well as the timer. Finally, we set it to 5000L for an update time of 5 seconds. The reason for this is because we cannot send data too fast onto the Blynk server otherwise they will force-cut our connection.

void loop()

Inside the loop() function, we only need to run Blynk and the timer – nothing else.

Accuracy of Values

These values are obtained from a 3W light bulb.


AC is dangerous to work with. If not careful, it could injure or even kill people. One has to be extra careful when dealing with AC applications. Experienced or not, it is advisable to have someone observing your safety at all times. This individual should certainly know the circuits and location of the switches controlling the equipment, and should be given instructions to pull the switch immediately if anything unforeseen happens.

Blynk is an easy-to-use IoT platform that helps with any form of wireless communication. The app is customizable and it supports a lot of devices such as, but not limited to, Arduinos, Wemos D1, Raspberry Pi, ESP8266, and ESP32.


Tags : AC Voltage SensorblynkcurrentDevKitC Boardenergyenergy monitoringESP32Non-invasive AC current sensorpowervoltagewifiwirelessZMPT101B

Leave a Response