Component: Energy Monitor (PZEM-004T) (Electrical)

From Flowcode Help
Jump to navigationJump to search
Author Matrix Ltd.
Version 1.0
Category Electrical


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!

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 uisng 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 3.3V tolerant pins only, e.g ESP32, then connect the supply going to the PZEM-004T to 3.3v and not 5V

WARNING: MAINS CAN KILL. ONLY TRY THIS IF 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.

FC6 Icon.png ESP32 TTGO Mains PM v1.3



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.

FC6 Icon.png Arduino Uno Mains PM v1.0

Macro reference

Initialise

Fc9-comp-macro.png Initialise
Starts up the UART to allow communications. Also, checks if PZEM-004T is detected. Returns 0 if detected or 255 if not detected.  
Fc9-u8-icon.png - BYTE Return


ReadAlarmStatus

Fc9-comp-macro.png ReadAlarmStatus
65535 = Overpower alarm triggered. 0 = Overpower alarm not triggered. 
Fc9-u16-icon.png - UINT Return


ReadCurrent

Fc9-comp-macro.png ReadCurrent
Read what the current draw is. Resolution: 0.001A Measurement accuracy: 0.5% 
Fc9-f32-icon.png - FLOAT Return


ReadEnergy

Fc9-comp-macro.png ReadEnergy
Read active energy value. Resolution: 1Wh Measurement accuracy: 0.5% 
Fc9-f32-icon.png - FLOAT Return


ReadFrequency

Fc9-comp-macro.png ReadFrequency
Reads the frequency of the mains 
Fc9-f32-icon.png - FLOAT Return


ReadPower

Fc9-comp-macro.png ReadPower
Read active power. Starting measure power: 0.4W Resolution: 0.1W 
Fc9-f32-icon.png - FLOAT Return


ReadPowerAlarmThreshold

Fc9-comp-macro.png ReadPowerAlarmThreshold
Reads the power alarm threshold in watts 
Fc9-u16-icon.png - UINT Return


ReadPowerFactor

Fc9-comp-macro.png ReadPowerFactor
Read power factor Resolution: 0.01 Measurement accuracy: 1% 
Fc9-f32-icon.png - FLOAT Return


ReadVoltage

Fc9-comp-macro.png ReadVoltage
Read voltage. Measuring range:80~260V Resolution: 0.1V Measurement accuracy: 0.5% 
Fc9-f32-icon.png - FLOAT Return


ResetEnergy

Fc9-comp-macro.png ResetEnergy
Reset the energy value 
Fc9-u8-icon.png - BYTE Return


SetPowerThresholdLevel

Fc9-comp-macro.png SetPowerThresholdLevel
Sets the power alarm threshold in watts 
Fc9-u16-icon.png - UINT PowerThresholdValue
Reg addreess high of alarm threshold 
Fc9-u8-icon.png - BYTE Return


Property reference

Fc9-prop-icon.png Properties
Fc9-conn-icon.png UART Properties
Fc9-type-16-icon.png Channel
UART Channel selector Software channels are bit banged using generic I/O pins but are not as reliable as hardware channels. Hardware channels use the selected peripheral on-board the target microcontroller. 
Fc9-type-5-icon.png TX
Pin to be used for Transmit data 
Fc9-type-5-icon.png RX
Pin to be used for Receive data 
Fc9-type-16-icon.png Baud Options
Baud rate option selector 
Fc9-type-14-icon.png Baud Rate
 
Fc9-type-16-icon.png Bus
Specifies the bus mode being used, RS232 allows you to connect a single master node to a single slave node. RS485 allows you to connect a single master node to multiple slave nodes. 
Fc9-conn-icon.png Modbus Properties
Fc9-type-21-icon.png Receive Buffer Size
Maximum number of bytes the receive buffer can hold 
Fc9-type-21-icon.png Slave ID Bytes
Number of bytes used when passing a slave ID, usually 1 but sometimes 2 
Fc9-type-21-icon.png Silent Interval
Configures how much time to wait after each master modbus command before another command can be sent. A silent interval of 60ms minimum is required in order to guarentee successful reception of the next transmission. 0=No Delay 60 = 60mS - Default Range : 0 - 65535 
Fc9-type-21-icon.png UART Receive Timeout
Amount of time to wait before timing out when listening for a slave's response. Range: 0 - 255. 0 = Don't Wait 1 - 254 = X ms 255 = Wait Forever 
Fc9-type-21-icon.png Receive Timeout Count
Number of timeouts in a row to wait for until we decide the slave is not responding or finished responding to a message. Range: 0 - 255 0 = First Timeout Only 1 = First Timeout + 1 2 = First Timeout + 2 
Fc9-conn-icon.png Simulation Properties
Fc9-type-10-icon.png Label
A text label to appear on the Modbus panel object. 
Fc9-type-7-icon.png Scope Traces
Selects if the scope traces are automatically added to the data recorder window or not. Simulation - draws an approximation of the UART data onto the scope trace. ICT - sets up the scope trace for incoming data and adds UART packet decoding at the correct BAUD. 
Fc9-type-7-icon.png Console Data
Selects if the console data is automatically generated or not 
Fc9-type-21-icon.png Console Columns
Number of characters that can be displayed on a single line of the console. 
Fc9-type-16-icon.png Data Source
Simulation data source used to allow the component to connect to various remote devices Nothing - Simulation data is ignored COM port - Routes the communication data to and from a physical or virtual COM port API - Routes the communication data via a data API component on the Panel.