About
In the modern world, everything needs some form of electric energy. whether it's our home, industry, cars, or train everything we see needs electricity. Nowadays we can not imagine our life without electric power. Effective electric power generation and consumption need proper monitoring. If you are interested in optimizing energy consumption or want to make your home or industry smarter, the first and most important thing is to measure the actual energy consumption. Energy Monitor System is an energy monitor and control device comprised of a collection of hardware and software components developed through the RISC-V Design Challenge, the goal is to measure, control and show power usage information and a variety of other parameters accurately and continuously for both residential and commercial use.
Energy Monitor System
The project consists of two main parts.
1) Measurement: Measure, analyze, and draw the plot of all the electricity related parameters.
2) Protection and Control: Fault detection with Protection and to offer enhanced safety for homes, buildings, and appliances.
Measurement
The Measurement part consists of the following
Current (Aac): For energy and power consumption calculation we have to accurately measure both, the instantaneous AC current (I), and Root mean square current (Irms). For the current measurement, there are many techniques and sensors available but the best is to use the current transformer (CT). Usually, AC current is too high and dangerous and can not be applied directly to measuring instruments. CT reduces the current proportionally which can be connected to measuring instruments and also provides a high level of isolation and safety. We can use any type of CT in this project but with small size, High accuracy, and good consistency I choose the ZMCT118F. Specifications from the data sheet are given below.
ZMCT11F is a 1000:1 current transformer and can measure up to 30A of AC current with a high isolation voltage of about 4500 volts. ZMCT11F reduces the current by a factor of 1000 that can be passed through a bleeder resistor and can be measured by microcontroller ADC as voltage.
From the circuit diagram, we can see that a bleeder resistor of 100 ohms is used. R17 and R19 offset the signal by VCC/2, to get a positive signal for ADC measurement. C18 bypasses the AC signal from Resistor. Bleeder resistor R22 is responsible for the current measurement range and resolution we can adjust it according to our use. if CT_VS is the CT voltage, and R22 is the bleeder resistor the actual real current can be calculated as follow.
I = ( (CT_VS - VCC/2) /R22 ) * 1000 where 0 << CT_VS << VCC
Max Current measurement for a bleeder resistor 100ohm is:
if VCC=3.3V CT_VS maximum value can be 3.3VPeak so ((3.3-1.65)/100 )*1000 = 16.5A(Peak) = 16.5/1.44 = 11.45rms. There is a nice tool also for all these calculations Tool for calculating burden resistor size, CT turns, and max Irms (thanks to them). so in short by reading CT_VS voltage with high-resolution ADC and making some strong algorithms, we can find the actual root mean square and instantaneous current easily.
Voltage(Vac): The voltage measure is almost similar to the previous one. here too we need both the root mean square voltage and instantaneous. Once again any techniques and methods can be used to measure the AC voltage ranging from simple resistor dividers to high precision voltage modules. household AC voltage is high and dangerous first we had to do some arrangement or signal conditioning to adjust it to the ADC measurement range. This time I chose ZMPT101B it's a current type Voltage Transformer. Small size, high accuracy, and good consistency, for voltage and power measurement Datasheet technical specs, are given below.
By choosing proper resistors and making proper circuits, we can measure up to 1000V by ZMPT101B with 4000V isolation.
Again R14 and R18 are for offset and C17 to bypass AC. if VT_VS is the measured small AC secondary voltage, then the actual output AC voltage can be found as:
V = R12((VT_VS - VCC/2)/R23)
if VCC=3.3V so our full-scale voltage maximum range can be found as:
Vp= 130,000 (3.3 -1.65)/576;
Vp=372V
Vrms = 372/1.44 = 258V
again we can change and adjust resistors to customize the measuring range and resolution. Care should be taken to choose R12, the input should be kept in the range of 2ma. also, the resistor should have high wattage, like from the above circuit supposed we have 300VAC input:
so 300/130,000 = 0.002037*0.002037 * 130,000 = 0.7watt we need resistor around 1 watt power dissipation. VT_VS is read by microcontroller ADC and doing all those critical calculations we can measure needed AC Voltages.
Power: by using the current and voltage measurement we can calculate AC power and its type.
Apparent Power (S) is the product of the r.m.s voltage and the r.m.s current.
Active Power(P) is the real power consumed in AC circuits we can calculate this by taking the average of instantaneous power(Product of instantaneous voltage and current, from the previous step).
Apparent Power (Q) can be calculated from apparent power and active power by using a power triangle.
Power Factor(pf) can be calculated from the ratio of active power to apparent power.
Kilowatt-hour(kWh) is the unit of total consumed electric power we can calculate this by summing active power for some specific fixed time. it will also give us an idea about electricity consumption cost.
Protection and Control
Protection and control circuit is included in this project to ensure smooth electric power to home and building and expensive appliances.
SLA-05VDC-SL-C 15A relay is used for controlling the output power from the device. relay is controlled by the microcontroller and isolated by opto-coupler and has added diode protection for back EMF. At the start relay switch is turned OFF and no power flow from the device, after reading the current voltage and other parameters when the microcontroller ensures everything is in a safe range then it allows the output power by turning ON the relay. Following protections are included:
Initial Delay: when the device receives power microcontroller will take some time and waits to ON the power to the output. in this way, the initial fluctuation in electricity is avoided which helps the safety of appliances.
Under Voltage: Microcontroller will cut off the output power when VAC is less than define Under voltage for safety and protection purposes.
Over Voltage: Similarly, Microcontroller will cut off the output power when VAC is more than defined Over Voltage.
High Load: if the output load is more than the defined level microcontroller will give a continuous beep sound to give a warning for the user to reduce the load. also, it will display an error msg on the screen for a defined time after that system will restart.
All the protection and control parameters can be adjusted from the code em.h define section.
Other parts
Display: 1.3inch OLED i2c display is used in this project to display various parameters. I ported the famous OLED libraries https://github.com/olikraus/u8g2 (special thanks and credits) for WCH32V307.
From the picture, we can see the display with all the required parameters. all parameters are self-explanatory "Normal" at the bottom means the device working is in normal condition because voltage and current readings are within the range. if Voltage or current goes beyond the defined range it will cut off with no output power.
Power Supply: HLK-5M05 wide range (100-240VAC to 5VDC )is used in this project
because of its simplicity and small size.
Buzzer: to get a warning and fault detection beeps a small buzzer is also included in this project. A simple ON OFF signal from the microcontroller is enough to trigger the buzzer.
Plotter: One of the interesting features of the Energy Monitor System is that it can plot or display the graph of AC current and voltage on the computer by using a serial plotter just connect it through USB with your computer and run any serial plotter you will able to see current voltage and power plots. Setting can be changed from code Marcos.
Coin cell battery: for Kwh monitoring we need to continuously measure kW reading and keep it in the backup register otherwise it will vanish if the power goes off. thus we need Vbat to be active so the coin cell holder is added to the schematic.
Microcontroller
The brain of this project is the 32-bit RISC-V core CH32V307 microcontroller running with a clock speed of 72MHz. CH32V307 comes with interesting features and peripherals like 256kb Flash 64k SRAM with more than 10 timers around 16 12-bit ADC, 2 DAC, and 8 USART, Ethernet, CAN, I2C, and SPI. ADC1 ch2 and ADC2 ch3 with DMA are used for voltage and current measurement respectively while I2C1 in master mood is used for OLED display. TIM3 provides an accurate time tick for storing kWh reading in backup register BKP_DR1. Systick timer was precisely used in the calculation and sampling of AC current and voltage for specific time periods.
Future Scope
- Convert it to a three-phase system.
- Add Modbus RTU protocol with RS-485 for industrial standard.
- Extend it to the IoT version with online monitoring and control.
- Use ethernet and add Modbus TCP.
Code Explanation
This function is developed to find the root mean square of the AC signal. Systick is set to measure and sample AC signal about 20000 times in each time period. digital code is converted to an analogue value, squared and its mean is calculated by dividing it by a total number of samples.
These functions calculate and return the RMS value of current, voltage, and power.
These two functions return current instantaneous value of current and voltage
Plotter print the graphs for instantaneous current and voltage and power
This method sample and averages instantaneous power for each time period by about 20000 times and returns the average power.
these are functions for I2C OLED library porting.
The definitions are used for calibrations and offset settings
Credits and special thanks to
- Oled library: https://github.com/olikraus/u8g2
- Moving average: https://github.com/mhtb32/EfficientMovingAverage/blob/master/moving_average.c
Helpful resources:
https://openenergymonitor.org/
WARNING: This project deals with High voltage. so please take proper safety precautions to avoid any damage. and if you are not sure about what you are doing then please avoid this project.
Comments