Arduino build error

error: 'Serial1' was not declared in this scope

An Arduino Uno or Nano has one hardware serial port, called Serial, shared with the USB cable. Serial1, Serial2 and Serial3 exist on bigger boards only.

  • Build error
  • 2 common causes
  • Seen 1,904 times in failed builds on Mokxi in the 30 days to November 16, 2026.
The message

What the Arduino IDE prints

Output window
sketch.ino: In function 'void setup()':
sketch.ino:2:3: error: 'Serial1' was not declared in this scope
    2 |   Serial1.begin(9600);
exit status 1

The board you picked has no such port, so the name is unknown. Use a software serial port, or a board that has more.

Mokxi's compiler, clang, words it as use of undeclared identifier 'Serial1', and suggests Serial.

Causes

The 2 usual causes with the fix

1Serial1 on an Uno or Nano

The SoftwareSerial library makes a second port on any two pins. It is slower and cannot send and receive at once at high speed, which is fine for a GPS or a Bluetooth module.

Broken
void setup() {
  Serial.begin(9600);
  Serial1.begin(9600);
  Serial.println("ok");
}

void loop() {
}
Fixed
#include <SoftwareSerial.h>

SoftwareSerial port(10, 11);

void setup() {
  Serial.begin(9600);
  port.begin(9600);
  Serial.println("ok");
}

void loop() {
}

Mokxi’s build tab says: This board has no Serial1: its one hardware serial port is Serial.

Try this fix in Mokxi

2Serial3 on a board that has fewer ports

The Arduino Mega 2560 has Serial, Serial1, Serial2 and Serial3. If the project needs several hardware ports, choose the Mega.

Broken
void setup() {
  Serial.begin(9600);
  Serial3.begin(9600);
  Serial.println("ok");
}

void loop() {
}
Fixed
void setup() {
  Serial.begin(9600);
  Serial3.begin(9600);
  Serial.println("ok");
}

void loop() {
}

Mokxi’s build tab says: This board has no Serial3: its one hardware serial port is Serial.

Try this fix in Mokxi

FAQ

Questions and answers

Which boards have Serial1?

The Mega 2560, the Leonardo and Micro, the ESP32, the Pico and many others. The Uno and Nano do not.

Can I use pins 0 and 1 for a second port?

Those pins are the same port as Serial, so a module there fights with the USB cable. Use SoftwareSerial on other pins.

Does SoftwareSerial have limits?

It listens on one port at a time and drops bytes above about 57600 baud on an Uno. Use a lower speed.