Nodemcu, Pzem004t v3 and 8ch relay board

Hi i would like to connect Pzem004t module and 8ch relay board to nodemcu. I am using USB connector for nodemcu which gives me 5v on vv pin but can't control both Pzem004t module and 8ch relay board. For psu i am using 12v which goes to jd-vcc and gnd relay board without jumper on vcc-jdvcc. Also for logic part of relay board I have to use 5v on vcc and gnd to left free. Do you know how to solve this problem?

What is that Pzem004t?
Try and make a wiring, and post it. Draw a logic block diagram and post it.

Pzem004t for AC measurement

No help in that.
Did You read the second line?

also give a link to the relay board
what is it's interface, e.g. 8 digit inputs, I2C, RS485, etc

Probably if I knew what you had:

Addressing Your Issue:

Your problem is not unexpected, and your wiring may be the root cause. Since hardware is involved, it’s crucial to provide an accurate, annotated schematic of your circuit as it is currently wired. Please note that Fritzing diagrams are not considered proper schematics; they are wiring diagrams and are often not helpful for troubleshooting.

What to Include:

  1. Annotated Schematic: Show all connections, including power, ground, and power sources. This helps us understand how your circuit is set up and identify any potential issues.
  2. Technical Information Links: Provide links to technical documentation for each hardware device used in your setup. Avoid links to sales sites like Amazon, as they usually lack the necessary technical details. We need complete specifications to help you effectively.
  3. Additional Information Needed: If the above details are incorrect, more information is required. Tell us what hardware and software you are using, the format of any data (like map data), and how your system determines its position. For example, if your project involves a robot, describe how it navigates and what computers are involved.
  4. Bill of Materials:
  5. A schematic provides a visual representation of the electrical connections and components in a circuit, showing how they interact and function together, while a Bill of Materials (BOM) is simply a list of components with part numbers and quantities needed for assembly. Unlike a BOM, a schematic illustrates the design’s logic and allows for troubleshooting and understanding circuit behavior. A BOM is useful for sourcing parts but doesn’t convey how they connect or operate in the circuit, which is critical information for understanding and working with electronics.

Why This Matters:

We have no way of knowing the specifics of your setup unless you provide that information. Clear and detailed descriptions enable us to offer the most accurate help possible. Without these details, it’s difficult to diagnose and solve the issues you're experiencing.

We need the following to accruately answer your question:

  • Annotated Schematic: Clearly show all connections, including power, ground, and power sources. This will help us understand your circuit setup and identify potential issues.

  • Technical Information Links: Provide links to technical documentation for each hardware component in your setup. Avoid links to sales sites like Amazon, as they often lack the detailed specifications we need to assist you effectively.

Why Do We Want This:

We can’t accurately assist without knowing the specifics of your setup. Clear, detailed descriptions will allow us to offer the best help possible. Without this information, diagnosing and solving your issues will be much harder.

Give yourself an belated Christmas present and pick up these resources, along with the Arduino Cookbook:



I need more information, as I still have no clear idea of what you’re working with. For example, you mentioned an 8-relay module; there are many different types, so which one are you using? Additionally, your description of a circuit board with "fuzzy parts" is too vague.

Please start by providing:

  1. Links to the technical documentation or datasheets for these devices.
  2. A detailed, annotated schematic showing how everything is connected.

The boxes with lines in your diagrams don’t provide enough detail to troubleshoot effectively.

@gilshultz probably you do not know how to solve problem... For someone who is much experienced than you, these photos are more than enough to know how to connect all three boards with one 12v power supply.. Thanks anyway

I’m not going to say you’re wrong; it’s clear you have much more expertise in this area and a better understanding of the materials than I do. Your statement, "these photos are more than enough to know how to connect all three boards with one 12V power supply," provided more clarity than your original question.

No problem, I’ll let you, the expert, solve the issue. Just remember, mine worked on the first try.

Did not want to sound rude or unpolite just to emphasize that someone who knows these boards has enough materials to know to tell me how to connect all three modules with one 12v psu... Problem is that I have need for two modules that work on 5v and there is only one pin (VV) with 5v

You need a 5V supply of at least 2 Amps. What is the current rating of your 12V supply?

Your picture shows a 5V relay board, do not connect 12V to it.

On picture is just placed all equipment I have and I asked how to connect them using 12v / 2 A power supply

testing the PZEM004Tv30 on a ESP32 running File>Examples>PZEM004Tv30>PZEMHardSerial

// ESP32 PZEM004Tv30 voltage/current sensor test
// File>Examples>PZEM004Tv30>PZEMHardSerial

// ESP32 pin 17 Tx to PZEM004Tv30 Rx
// ESP32 pin 16 Rx to PZEM004Tv30 Tx
// ESP32 3.3V to PZEM004Tv30 5V (3.3V works OK)
// ESP32 GND to PZEM004Tv30 GND

/*
Copyright (c) 2021 Jakub Mandula

Example of using one PZEM module with Hardware Serial interface.
================================================================

If desired, a HardwareSerial handle can be passed to the constructor
which will then be used for the communication with the module.

Note that ESP32 HardwareSerial must also be provided with the RX and TX pins.

*/
#include <Arduino.h>
#include <PZEM004Tv30.h>


#if defined(ESP32)
/*************************
 *  ESP32 initialization
 * ---------------------
 * 
 * The ESP32 HW Serial interface can be routed to any GPIO pin 
 * Here we initialize the PZEM on Serial2 with RX/TX pins 16 and 17
 */
#if !defined(PZEM_RX_PIN) && !defined(PZEM_TX_PIN)
#define PZEM_RX_PIN 16
#define PZEM_TX_PIN 17
#endif

#define PZEM_SERIAL Serial2
#define CONSOLE_SERIAL Serial
PZEM004Tv30 pzem(PZEM_SERIAL, PZEM_RX_PIN, PZEM_TX_PIN);

#elif defined(ESP8266)
/*************************
 *  ESP8266 initialization
 * ---------------------
 * 
 * esp8266 can connect with PZEM only via Serial0
 * For console output we use Serial1, which is gpio2 by default
 */
#define PZEM_SERIAL Serial
#define CONSOLE_SERIAL Serial1
PZEM004Tv30 pzem(PZEM_SERIAL);
#else
/*************************
 *  Arduino initialization
 * ---------------------
 * 
 * Not all Arduino boards come with multiple HW Serial ports.
 * Serial2 is for example available on the Arduino MEGA 2560 but not Arduino Uno!
 * The ESP32 HW Serial interface can be routed to any GPIO pin 
 * Here we initialize the PZEM on Serial2 with default pins
 */
#define PZEM_SERIAL Serial2
#define CONSOLE_SERIAL Serial
PZEM004Tv30 pzem(PZEM_SERIAL);
#endif

void setup() {
    // Debugging Serial port
    CONSOLE_SERIAL.begin(115200);
 delay(2000);
  Serial.println(PZEM_RX_PIN);
  Serial.println(PZEM_TX_PIN);

    // Uncomment in order to reset the internal energy counter
    // pzem.resetEnergy()
}

void loop() {
    // Print the custom address of the PZEM
    CONSOLE_SERIAL.print("Custom Address:");
    CONSOLE_SERIAL.println(pzem.readAddress(), HEX);

    // Read the data from the sensor
    float voltage = pzem.voltage();
    float current = pzem.current();
    float power = pzem.power();
    float energy = pzem.energy();
    float frequency = pzem.frequency();
    float pf = pzem.pf();

    // Check if the data is valid
    if(isnan(voltage)){
        CONSOLE_SERIAL.println("Error reading voltage");
    } else if (isnan(current)) {
        CONSOLE_SERIAL.println("Error reading current");
    } else if (isnan(power)) {
        CONSOLE_SERIAL.println("Error reading power");
    } else if (isnan(energy)) {
        CONSOLE_SERIAL.println("Error reading energy");
    } else if (isnan(frequency)) {
        CONSOLE_SERIAL.println("Error reading frequency");
    } else if (isnan(pf)) {
        CONSOLE_SERIAL.println("Error reading power factor");
    } else {

        // Print the values to the Serial console
        CONSOLE_SERIAL.print("Voltage: ");      CONSOLE_SERIAL.print(voltage);      CONSOLE_SERIAL.println("V");
        CONSOLE_SERIAL.print("Current: ");      CONSOLE_SERIAL.print(current);      CONSOLE_SERIAL.println("A");
        CONSOLE_SERIAL.print("Power: ");        CONSOLE_SERIAL.print(power);        CONSOLE_SERIAL.println("W");
        CONSOLE_SERIAL.print("Energy: ");       CONSOLE_SERIAL.print(energy,3);     CONSOLE_SERIAL.println("kWh");
        CONSOLE_SERIAL.print("Frequency: ");    CONSOLE_SERIAL.print(frequency, 1); CONSOLE_SERIAL.println("Hz");
        CONSOLE_SERIAL.print("PF: ");           CONSOLE_SERIAL.println(pf);

    }


    CONSOLE_SERIAL.println();
    delay(2000);
}

sample serial monitor output using a heater as a load

Custom Address:1
Voltage: 247.30V
Current: 0.00A
Power: 0.00W
Energy: 0.023kWh
Frequency: 50.0Hz
PF: 0.00

Custom Address:1
Voltage: 247.70V
Current: 0.00A
Power: 0.00W
Energy: 0.023kWh
Frequency: 50.0Hz
PF: 0.00

Custom Address:1
Voltage: 247.80V
Current: 0.00A
Power: 0.00W
Energy: 0.023kWh
Frequency: 50.0Hz
PF: 0.00



Custom Address:1
Voltage: 209.60V
Current: 3.91A
Power: 819.10W
Energy: 0.027kWh
Frequency: 50.0Hz
PF: 1.00

Custom Address:1
Voltage: 209.70V
Current: 3.91A
Power: 819.30W
Energy: 0.028kWh
Frequency: 50.0Hz
PF: 1.00

Custom Address:1
Voltage: 183.20V
Current: 6.72A
Power: 1231.20W
Energy: 0.030kWh
Frequency: 50.0Hz
PF: 1.00

Custom Address:1
Voltage: 182.50V
Current: 6.69A
Power: 1221.50W
Energy: 0.031kWh
Frequency: 50.0Hz
PF: 1.00

Custom Address:1
Voltage: 181.90V
Current: 6.67A
Power: 1213.40W
Energy: 0.033kWh
Frequency: 50.0Hz
PF: 1.00

results compared to a multimeter and a clamp meter

  PZEMsensor          meter
voltage current  voltage current
  247     0        245     0
  209    3.92      210    3.83
  181    6.72      181    6.5

the voltage drop as the current increases is due to overloading the isolation transformer

test setup (note the isolation transformer and the enclosure for the PZEM004Tv30 reducing the possibility of electric shock)

closeup of the ESP32/ PZEM004Tv30 wiring

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.