Source: https://mokxi.com/libraries/altsoftserial
Updated: 2026-11-02

Libraries / Communication
Arduino library · Communication

# AltSoftSerial: a steadier second serial port on fixed pins

AltSoftSerial, by Paul Stoffregen, is the alternative people reach for when SoftwareSerial drops characters or upsets other timing in a sketch. Upstream it times bits with a 16-bit timer’s input capture and output compare hardware instead of a counted delay loop, so it can send and receive at the same time and does not hold interrupts off for a whole byte.

Open the example in the editor See the calls

Built in on Mokxi: #include <AltSoftSerial.h> and it builds, with nothing to install. Free, and no account needed.

## What AltSoftSerial does

The price is that the pins are not yours to choose. On an Uno, Nano or Pro Mini, RX is pin 8 and TX is pin 9; on a Mega they are 48 and 46; on a Leonardo or Pro Micro, 13 and 5. The constructor takes no pins, and any you pass are ignored. On the real board it also takes Timer1, so pin 10 loses PWM and the Servo library cannot share the timer.

You get one port per board. For a GPS or Bluetooth module at 9600 or 38400 baud beside other interrupt-driven code, it is usually the more dependable choice on an Uno.

Library Manager name | AltSoftSerial

Author | Paul Stoffregen

Include | #include <AltSoftSerial.h>

Boards | Arduino Uno, Arduino Nano, Arduino Mega 2560, Arduino Leonardo, SparkFun Pro Micro, Arduino Micro, Arduino Pro Mini 3.3 V

In the simulator | Simulated: it runs against the part the way it does on the bench.

Parts it drives | GPS module, NEO-6M, Bluetooth serial module, HC-05

## Install it

It builds on Arduino Uno, Arduino Nano, Arduino Mega 2560, Arduino Leonardo, SparkFun Pro Micro, Arduino Micro, Arduino Pro Mini 3.3 V.

In Mokxi it is built in: #include <AltSoftSerial.h> and the sketch compiles, with no download, no zip and no Library Manager.

On a real board, install "AltSoftSerial" by Paul Stoffregen from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add AltSoftSerial to lib_deps in PlatformIO. Mokxi follows the calls of release 1.4, so a sketch written here builds there too.

What to know in the simulator: The bits are timed as SoftwareSerial’s are, not by the 16-bit timer’s input capture, so the pins and calls are upstream’s and Timer1 is not taken.

Arduino Uno · Arduino Nano · Arduino Mega 2560 · Arduino Leonardo · SparkFun Pro Micro · Arduino Micro · Arduino Pro Mini 3.3 V

## The calls you will use

In the order a sketch meets them.

### AltSoftSerial altSerial;

The one port, on the board’s fixed pins: RX 8 and TX 9 on an Uno or Nano.

### altSerial.begin(9600)

Starts it at a baud rate matching the module.

### altSerial.available()

How many received bytes are waiting.

### altSerial.read()

The next received byte, or -1 if none is waiting.

### altSerial.println("hello")

Sends text and a line ending, as on any serial port.

### altSerial.peek()

Looks at the next byte without taking it out of the buffer.

### altSerial.end()

Stops the port and frees its pins.

## Example: A GPS module read on the second serial port

On the Arduino Uno R3. It runs in the browser exactly as printed.

sketch.ino · Arduino Uno R3

### Wiring

- GPS module, NEO-6M TX to Arduino Uno R3 8
- GPS module, NEO-6M RX to Arduino Uno R3 9
- Arduino Uno R3 5V to GPS module, NEO-6M VCC
- Arduino Uno R3 GND to GPS module, NEO-6M GND

Open it in the editor, wired and ready to run

## Common errors and how to fix them

### Nothing is received with the module on pins 2 and 3

AltSoftSerial ignores the pins you name. Move the module’s TX to pin 8 and its RX to pin 9 on an Uno or Nano, or to 48 and 46 on a Mega.

### analogWrite() on pin 10 or a servo stopped working on a real Uno

Upstream AltSoftSerial uses Timer1, which is also the timer for PWM on pins 9 and 10 and for the Servo library. Move PWM to pins 3, 5, 6 or 11, or use SoftwareSerial if you need Timer1 for something else.

### 'AltSoftSerial' does not name a type on an ESP32

The library is written for AVR and Teensy timers. ESP32 boards have spare hardware UARTs: use HardwareSerial on Serial1 or Serial2 with the pins you choose instead.

## Keep going

### Learn

- Arduino NEO-6M GPS: Wiring, TinyGPS++ and Code
- UART Serial Explained: Baud, Frames and the Wire

### Parts

- GPS module, NEO-6M
- Bluetooth serial module, HC-05

### More communication libraries

- OneWire
- TinyGPS
- TinyGPSPlus
- MFRC522
- SoftwareSerial
- i2cdetect
- Keyboard
- Mouse

Every built-in library · Open the editor

## Try AltSoftSerial without installing anything

Open the example, change the sketch, and keep your version in a free account.

Start building free

Open the editor
