#include // Define pins for RX and TX (RX=Pin 10, TX=Pin 11) SoftwareSerial mySerial(10, 11); void setup() // Initialize the hardware serial for debugging Serial.begin(9600); // Initialize the software serial port mySerial.begin(9600); mySerial.println("Hello, SoftwareSerial!"); void loop() if (mySerial.available()) Serial.write(mySerial.read()); // Send data from software port to computer Use code with caution. Common Use Cases 1. Bluetooth Modules (HC-05/HC-06)
// Send data via software serial (non-blocking friendly) if (Serial.available()) char out = Serial.read(); mySerial.write(out); // blocking but short
#include <SoftwareSerial.h>
For IoT devices that send SMS or connect to the internet, SoftwareSerial.h is the standard tool for sending AT commands to GSM modules like the SIM800L . Limitations and Best Practices
#include // Define pins for RX and TX (RX=Pin 10, TX=Pin 11) SoftwareSerial mySerial(10, 11); void setup() // Initialize the hardware serial for debugging Serial.begin(9600); // Initialize the software serial port mySerial.begin(9600); mySerial.println("Hello, SoftwareSerial!"); void loop() if (mySerial.available()) Serial.write(mySerial.read()); // Send data from software port to computer Use code with caution. Common Use Cases 1. Bluetooth Modules (HC-05/HC-06)
// Send data via software serial (non-blocking friendly) if (Serial.available()) char out = Serial.read(); mySerial.write(out); // blocking but short
#include <SoftwareSerial.h>
For IoT devices that send SMS or connect to the internet, SoftwareSerial.h is the standard tool for sending AT commands to GSM modules like the SIM800L . Limitations and Best Practices