Conflicting declaration 'arduino::HardwareSerial Serial'


I’m just starting to use a UNO Wifi Rev 2 board. I want to interface it with a PZEM004T V3.0 module via Serial1. However the compiler just throws up conflict errors. I’m using the PZEMHardSerial example file which works well on my MEGA:

#include <PZEM004Tv30.h>

/* Hardware Serial3 is only available on certain boards.
 * For example the Arduino MEGA 2560
PZEM004Tv30 pzem(&Serial1);  //Changed to Serial1 as per UNO WIFI Rev 2.0 board

void setup() {

void loop() {
    float voltage = pzem.voltage();
        Serial.print("Voltage: "); Serial.print(voltage); Serial.println("V");
    } else {
        Serial.println("Error reading voltage");

    float current = pzem.current();
        Serial.print("Current: "); Serial.print(current); Serial.println("A");
    } else {
        Serial.println("Error reading current");

    float power = pzem.power();
        Serial.print("Power: "); Serial.print(power); Serial.println("W");
    } else {
        Serial.println("Error reading power");

    float energy =;
        Serial.print("Energy: "); Serial.print(energy,3); Serial.println("kWh");
    } else {
        Serial.println("Error reading energy");

    float frequency = pzem.frequency();
        Serial.print("Frequency: "); Serial.print(frequency, 1); Serial.println("Hz");
    } else {
        Serial.println("Error reading frequency");

    float pf =;
        Serial.print("PF: "); Serial.println(pf);
    } else {
        Serial.println("Error reading power factor");


But I can’t get it to compile getting the following errors:

Arduino: 1.8.13 (Windows 10), Board: "Arduino Uno WiFi Rev2, ATMEGA328"

O:\Documents\Arduino\libraries\PZEM004Tv30\PZEM004Tv30.cpp:54:23: error: conflicting declaration 'arduino::HardwareSerial Serial'

 extern HardwareSerial Serial;


In file included from C:\Users\Mike\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.7\cores\arduino/Arduino.h:140:0,

                 from O:\Documents\Arduino\libraries\PZEM004Tv30\PZEM004Tv30.h:41,

                 from O:\Documents\Arduino\libraries\PZEM004Tv30\PZEM004Tv30.cpp:23:

C:\Users\Mike\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.7\cores\arduino/UART.h:182:20: note: previous declaration as 'UartClass Serial'

   extern UartClass Serial;


exit status 1

Error compiling for board Arduino Uno WiFi Rev2.I have also tried using the SoftwareSerial with the PZEM module and get similar errors.

Any help would be much appreciated.


This library is meant for classic arduino.

Try replacing it with extern UartClass Serial;
That’s possibly why you get conflicting declaration

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