Arduino Home Energy Monitor using CT Clamp Current Sensor & ZMPT101B AC Voltage Sensor
Table of Contents
Arduino Home Energy Monitor:
Arduino Home Energy Monitor using CT Clamp Current Sensor & ZMPT101B AC Voltage Sensor- In this article, you will learn how to make Arduino Home Energy Monitor using CT Clamp Current Sensor, ZMPT101B AC voltage Sensor, and an SSD1306 I2C supported Oled display module. Instead of using the Arduino Nano you can also use Arduino Uno.
After calculating voltage, current, and power, you can easily calculate the units. You can calculate how much electricity you have used in a day or even in an entire month. When you have the values of voltage, current, and power, you can calculate anything by using the desired formula.
Anyway, in my case, I already have the main energy meter, which keeps track of the units. So, from here, I can calculate how much electricity I have used. You can see, this energy meter is installed outside the house. And when I am at home, I have no idea when and how much load is there, and most importantly, what the voltage is. Nowadays, the temperature here ranges from 44 degrees Celsius to 49 degrees Celsius. Due to this, the voltage often drops significantly. A few days ago, the voltage dropped below 100 volts, which caused the AC compressor to malfunction. Because I had no idea about the voltage.
So, what I want to say is that I am going to use this Arduino Home Energy Monitor for monitoring the voltage, current, and power. So, if in case there is a high load or low voltage, I can turn off sensitive loads.
During the practical demonstration, I am going to use an ampere meter for measuring the actual current and then I will compare it with the current value measured with my designed Arduino Home energy meter. And the same thing I am going to do for the AC Voltage. I will measure the voltage using this multimeter and then I will compare it with the voltage; measured with my designed Arduino Home Energy Monitor. This testing is important for several reasons because most of the time the measured values are different from the actual values. In such situations, we need to calibrate our sensors, which I will explain later in this video. So, without any further delay, let’s get started!!!
Amazon Links:
Arduino Nano USB-C Type (Recommended)
*Disclosure: These are affiliate links. As an Amazon Associate I earn from qualifying purchases.
About the Current Sensor and Voltage Sensor:
You can see the CT Clamp Current Sensor and the ZMPT101B AC Voltage Sensor. If you want to know about their technical specifications and how to use these sensors individually, then you can read my getting started articles on the CT Clamp Current Sensor and ZMPT101B AC Voltage Sensor.
Gravity: Analog AC Current Sensor (20A)
When you want to measure the AC current, are you still having trouble cutting the wires, wiring, or soldering. Gravity: Analog AC Current Sensor comes to the rescue, eliminating the need to cut wires or reconnect circuits. Simply clamp the AC transformer probe on the AC line, and then plug the 3.5mm headphone jack into the signal conversion module to read the current AC current value. The analog output is designed to be compatible with 3V3/5V micro-controller. It can be conveniently used for AC current measurement to monitor AC motors, lighting equipment, air compressors, etc.
Pin Description:
LABEL | NAME | Function Description |
1 | – | GND |
2 | + | Power Input (3.3V-5.5V) |
3 | A | Signal Output (0.2-2.8VDC) |
4 | Φ3.5mm 3P plug | AC Transformer Input Signal |
FEATURES
- Non-contact measurement, high safety
- Multiple ranges for various measurement scenarios
- Compatible with 3V3/5V micro-controller
APPLICATIONS
- AC motor automatic monitoring
- Lighting and electrical equipment measurement
SPECIFICATION
AC Current Signal Conversion Module
- Input Voltage (VCC): 3.3V-5.5V
- Interface: Gravity Analog (PH2.0-3P,analog voltage output 0.2-2.8V DC)
- AC Voltage Input Range: 0-1V (AC RMS)
- Relative Error: ±4%
- Dimension: 32×27 mm /1.26×1.06 in
- Weight: 5g
Open Type AC Transformer Probe
- AC Current Range: 0-20A
- Signal Output (standard Φ3.5mm 3P plug): 0-1V AC voltage, linear corresponding range 0-20A
- Accuracy: ±1%
- Non-linearity: ≤±0.2%
- Frequency Range: 50Hz~1kHz
- Cable Length: 1m
- Working Temperature: -25 ℃~+70 ℃
- Opening Size: 13×13 mm / 0.51×0.51 in
- Weight: 50g
ZMPT101B 230 volts AC Mains Voltage Sensor:
This module is based on a high precision ZMPT101B voltage Transformer. This module makes it easy to monitor AC mains voltage up to 250 volts. This module comes with Multi-turn trim pot which can be used for adjusting the Analog output.Using ZMPT101B AC Voltage Sensor you can easily measure main voltage using Arduino or even Raspberry Pi (external ADC required).
Features of ZMPT101B AC voltage sensor Module
- Voltage upto 250 volts can be measured
- Light weight with on-board micro-precision voltage transformer
- High precision on-board op-amp circuit
- Operating temperature: 40ºC ~ + 70ºC
- Supply voltage 5 volts to 30 volts
Advantages of ZMPT101B AC voltage sensor
- Analog output corresponding quantity can be adjusted.
- Pcb board size: 49.5 (mm) x19.4 (mm)
- Good consistency, for voltage and power measurement
- Very efficient and accuracy
Arduino Home Energy Monitor, Circuit Diagram:
As usual, I am using my designed Arduino Nano and LoRa based development board, but you can also do the same exact connections on a breadboard. Forget about the relays, LoRa, and 5v Buzzer. Just concentrate on the connections; I am about to explain.
Connect the VCC and GND pins of the ZMPT AC voltage sensor to the Arduino 5V and GND. In my case I have connected the VCC wire to the Arduino Vin pin which is connected to the regulated 5v and 3A power supply. Connect the Out pin of the ZMPT voltage sensor to the Arduino Analog pin A0.
Connect the VCC and GND wires of the AC Current Sensor to the Arduino 5V and GND. But, in my case I have connected it to the external 5V and 3A power supply. Connect the output signal wire A to the Arduino Analog pin A1.
Connect the VCC and GND pins of the SSD1306 Oled display module to the Arduino 3.3V and GND pins. Connect the SCL and SDA pins to the Arduino Analog pins A5 and A4 respectively. A5 is the SCL and A4 is the SDA.
Or you can follow this circuit diagram if you want to use 7805 Voltage regulator.
You can read my article, on how to make yourself an Arduino development board. In that article, I have explained in detail why not to use 7805 voltage regulator.
Download the Required Libraries:
You will also need to download the ZMPT101B library. Go to the Sketch menu > then to Include Library > and click on the Manage Libraries. Search for the ZMPT101B library and install it.
Arduino Home Energy Monitor Programming:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
#include <SPI.h> // include libraries #include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #include <ZMPT101B.h> #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 64 // OLED display height, in pixels // Declaration for an SSD1306 display connected to I2C (SDA, SCL pins) #define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin) Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); #define SENSITIVITY 500.0f // ZMPT101B sensor output connected to analog pin A0 // and the voltage source frequency is 50 Hz. ZMPT101B voltageSensor(A0, 50.0); float correctionfactor=6.5; float Current_Value = 0; const int ACPin = A1; //set arduino signal read pin #define ACTectionRange 20; //set Non-invasive AC Current Sensor tection range (5A,10A,20A) #define VREF 5 char watt[5]; unsigned long last_time =0; unsigned long current_time =0; float Wh =0 ; void setup() { Serial.begin(115200); // pinMode(voltageSensor,INPUT); pinMode(ACPin,INPUT); voltageSensor.setSensitivity(SENSITIVITY); display.begin(SSD1306_SWITCHCAPVCC, 0x3C); delay(2000); display.clearDisplay(); display.setTextColor(WHITE); } void loop() { float ACcurrent=0; float current_value = readACCurrentValue(); ACcurrent=current_value; //Serial.print(current_value); // Serial.println(" A"); // current += current_value; delay(1000); Serial.print(ACcurrent); Serial.println("Current: "); float acvoltage = voltageSensor.getRmsVoltage(); Serial.println(acvoltage); float P = acvoltage * ACcurrent; last_time = current_time; current_time = millis(); Wh = Wh+ P *(( current_time -last_time) /3600000.0) ; dtostrf(Wh, 4, 2, watt); Serial.write(watt); display.clearDisplay(); display.setCursor(10,0); display.setTextSize(2); display.setTextColor(WHITE); display.print("V:"+String(acvoltage)); display.setCursor(10,20); display.setTextSize(2); display.print("I:"+String(ACcurrent)); display.setCursor(10,45); display.setTextSize(2); display.print("P:"+String(P)); display.display(); delay(3000); } 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 peakVoltage = peakVoltage + correctionfactor; delay(1); } peakVoltage = peakVoltage / 5; voltageVirtualValue = peakVoltage * 0.707; //change the peak voltage to the Virtual Value of voltage /*The circuit is amplified by 2 times, so it is divided by 2.*/ voltageVirtualValue = (voltageVirtualValue / 1024 * VREF ) / 2; ACCurrtntValue = voltageVirtualValue * ACTectionRange; return ACCurrtntValue; } |
The purpose of this code, is to measure the AC Voltage, Current, Power, and to print all these measured values on the Oled display module. I am not going to explain this code line by line, because I have already explained it in my previous getting started tutorials on the AC current Sensor and ZMPT AC Voltage sensor. I have just combined the two codes and that’s it. Now, let’s go ahead and start our practical demonstration.
Arduino Home Energy Monitor, Demonstration:
All the values are zero, because I have not yet connected the voltage and current sensors.
I connected the ZMPT101B voltage sensor to the AC voltage and the current sensor is not yet connected. So, that’s why the current value is zero, and also the power value is zero. You can see the actual AC voltage on the multimeter which fluctuates between 179 and 181 volts. And you can see the measured AC voltage which is a bit OFF. So, let’s go ahead and calibrate the AC voltage sensor.
You can use this potentiometer to fine tune the value. While calibrating the sensor make sure you don’t touch ac voltage wires or the contacts on the bottom side of the PCB. As it can be really dangerous.
The voltage sensor has been calibrated, and you can clearly see the measured voltage value is pretty close to the actual voltage. Now, let’s start with the Current Sensor.
Next, I am going to measure the current of a Bulb and let’s see if I am going to get the exact current value.
The measured current value fluctuates around 0.1 amps while the actual current value on the ampere meter fluctuates between 0.31 and 0.32A. The difference is high, so we need to calibrate the current sensor.
Unlike the ZMPT101B the CT Clamp Current sensor doesn’t have a potentiometer. So, we can’t do calibration on the sensor side. So, we will have to do it through the programming.
I have defined this correctionfactor variable to fine tune the measured current value. Keep changing this value until you are happy with the final measured value. In my case the value 9 worked, and I re-upload the program.
Now, the measured current value is pretty close to the actual measured value. Both the sensors are calibrated and now my Arduino Home Energy meter is ready for the final testing, so let’s go ahead and do it.
This Bulb draws around 0.32A, the voltage is around 174 volts, and the power is around 55 watts.
Next, I checked the Voltage, Current, and Power of the AC Room Cooler.
So, that’s all for now.
Watch Video Tutorial: