Difference between revisions of "Component: Energy Monitor (PZEM-004T) (Electrical)"
Line 42: | Line 42: | ||
This example program uses a PZEM-004T energy monitor to monitor mains voltage, current, frequency, power factor, energy, and over-threshold power alarm. | This example program uses a PZEM-004T energy monitor to monitor mains voltage, current, frequency, power factor, energy, and over-threshold power alarm. | ||
+ | |||
The alarm threshold is set within properties. | The alarm threshold is set within properties. | ||
+ | |||
Initialiasion returns 0 if PZEM-004T is detected or 255 if it is not. | Initialiasion returns 0 if PZEM-004T is detected or 255 if it is not. | ||
Values are sent to the ESP32 TTGO display which uses a ST7789v1 GLCD. | Values are sent to the ESP32 TTGO display which uses a ST7789v1 GLCD. | ||
Line 52: | Line 54: | ||
This example uses the Arduino Uno and outputs UART via the Timer UART component on pin D2 at a baud rate of 19200. | This example uses the Arduino Uno and outputs UART via the Timer UART component on pin D2 at a baud rate of 19200. | ||
+ | |||
All the functions are the same as above but no display is used. | All the functions are the same as above but no display is used. | ||
+ | |||
D3 and D4 have pullups so no external resistors are required. | D3 and D4 have pullups so no external resistors are required. | ||
+ | |||
Each switch is pulled to GND to trigger. | Each switch is pulled to GND to trigger. | ||
+ | |||
You will require A TTL UART to USB converter to view the data as the one built-in to the Uno is used for the MODBUS of the power monitor | You will require A TTL UART to USB converter to view the data as the one built-in to the Uno is used for the MODBUS of the power monitor | ||
+ | |||
{{Fcfile|Arduino_Uno_Mains_PM_v1.0.fcfx |Arduino Uno Mains PM v1.0}} | {{Fcfile|Arduino_Uno_Mains_PM_v1.0.fcfx |Arduino Uno Mains PM v1.0}} | ||
Revision as of 13:58, 23 July 2023
Author | Matrix Ltd. |
Version | 1.0 |
Category | Electrical |
Contents
Energy Monitor (PZEM-004T) component
The PZEM-004T module is used for measuring AC voltage, current, active power, frequency, power factor & overcurrent. Resetable active energ and the overpower level can be set and monitored.
Component Source Code
Please click here to download the component source project: FC_Comp_Source_Energy_Monitor_PZEM-004T.fcfx
Please click here to view the component source code (Beta): FC_Comp_Source_Energy_Monitor_PZEM-004T.fcfx
Detailed description
No detailed description exists yet for this component
Examples
Notes: if there is a communication issue after initialisation, then just 9's will be returned!
For the display properties, make sure Use SPI is set to No
The TX of the PZEM-004T energy monitor goes to RX of the microcontroller
The RX of the PZEM-004T energy monitor goes to TX of the microcontroller. If using an Uno, the PZEM-004T must be disconnected from the RX prior to programming. After reconnecting press the Reset button on the Uno.
If using a morocontroller that have 3V tolerant pins only, e.g ESP32, then connect the supply going to the PZEM-004T to 3v and not 5V.
WARNING: MAINS CAN KILL. ONLY TRY THIS IF YOU ARE EXPERIENCED WITH MAINS ELECTRICITY. WIRE AT YOUR OWN RISK!
This example program uses a PZEM-004T energy monitor to monitor mains voltage, current, frequency, power factor, energy, and over-threshold power alarm.
The alarm threshold is set within properties.
Initialiasion returns 0 if PZEM-004T is detected or 255 if it is not. Values are sent to the ESP32 TTGO display which uses a ST7789v1 GLCD.
This example uses the Arduino Uno and outputs UART via the Timer UART component on pin D2 at a baud rate of 19200.
All the functions are the same as above but no display is used.
D3 and D4 have pullups so no external resistors are required.
Each switch is pulled to GND to trigger.
You will require A TTL UART to USB converter to view the data as the one built-in to the Uno is used for the MODBUS of the power monitor
Macro reference
Initialise
![]() |
Initialise |
Starts up the UART to allow communications. Also, checks if PZEM-004T is detected. Returns 0 if detected or 255 if not detected. | |
![]() |
Return |
ReadAlarmStatus
![]() |
ReadAlarmStatus |
65535 = Overpower alarm triggered. 0 = Overpower alarm not triggered. | |
![]() |
Return |
ReadCurrent
![]() |
ReadCurrent |
Read what the current draw is. Resolution: 0.001A Measurement accuracy: 0.5% | |
![]() |
Return |
ReadEnergy
![]() |
ReadEnergy |
Read active energy value. Resolution: 1Wh Measurement accuracy: 0.5% | |
![]() |
Return |
ReadFrequency
![]() |
ReadFrequency |
Reads the frequency of the mains | |
![]() |
Return |
ReadPower
![]() |
ReadPower |
Read active power. Starting measure power: 0.4W Resolution: 0.1W | |
![]() |
Return |
ReadPowerAlarmThreshold
![]() |
ReadPowerAlarmThreshold |
Reads the power alarm threshold in watts | |
![]() |
Return |
ReadPowerFactor
![]() |
ReadPowerFactor |
Read power factor Resolution: 0.01 Measurement accuracy: 1% | |
![]() |
Return |
ReadVoltage
![]() |
ReadVoltage |
Read voltage. Measuring range:80~260V Resolution: 0.1V Measurement accuracy: 0.5% | |
![]() |
Return |
ResetEnergy
![]() |
ResetEnergy |
Reset the energy value | |
![]() |
Return |
SetPowerThresholdLevel
![]() |
SetPowerThresholdLevel |
Sets the power alarm threshold in watts | |
![]() |
PowerThresholdValue |
Reg addreess high of alarm threshold | |
![]() |
Return |