void loop() if (gps.available()) char c = gps.read(); ble.write(c); // forward GPS data to Bluetooth Serial.write(c); // optional debug
All digital pins support software serial, but using pins from different port groups can improve performance.
| Scenario | Action | |----------|--------| | Standard Arduino IDE | No action needed; just #include <SoftwareSerial.h> | | Update library | Boards Manager → Update Arduino AVR Boards | | Manual install | Download ZIP from GitHub → unzip → place in sketchbook/libraries/SoftwareSerial | | PlatformIO | Add arduino-libraries/SoftwareSerial to lib_deps | softwareserial.h arduino library download
| Library/Approach | Best for | |----------------|-----------| | HardwareSerial | Primary serial, high baud rates. | | NeoSWSerial | Reliable reception on two pins at up to 57600 baud. | | AltSoftSerial | High-performance, but uses fixed timer pins (8 & 9 on Uno). | | SerialPort (Mega) | Multiple hardware ports (Serial1, Serial2, Serial3). | | I2C/SPI to UART bridge (e.g., SC16IS750) | Add many hardware UARTs externally. | Problem: Read NMEA sentences from a GPS module (4800 baud) and transmit them over Bluetooth (9600 baud) to a smartphone.
| Port | Pins | |------|------| | PCINT0 | 8 | | PCINT1 | 9 | | PCINT2 | 10, 11, 12, 13 | | PCINT3 | A0–A5 (14–19) | void loop() if (gps
SoftwareSerial gps(4, 5); SoftwareSerial ble(6, 7); void setup() gps.begin(9600); ble.begin(115200); // may be unreliable at this baud rate
void loop() mySerial.println("Hello");
void setup() Serial.begin(9600); // Debug console gps.begin(4800); ble.begin(9600);
ss.print("GPS: "); ss.println(gpsData); if (ss.available()) char c = ss.read(); // process | | AltSoftSerial | High-performance, but uses fixed