What is Arduino Software Serial
Introduction
I feel obligated to post this tutorial after seeing beginners assigning two serial devices to Arduino Uno hardware serial pin which is digital pin 0 (Rx) and digital pin 1 (Tx). Connecting two serial devices results to undefined behavior due to conflicting signals. Arduino Uno, Arduino Nano, and Arduino Mini has only 1 serial port. If you need to connect more serial devices, you have the option to use their big brother; the Arduino Mega which has four serial ports and more pins available. But using the Arduino Mega results to additional cost. The other option is to use the Arduino Software Serial library.
Arduino Software Serial library basically mimics or copy the behavior of the hardware serial. We are going to use the library of PaulStoffregen from https://github.com/PaulStoffregen/SoftwareSerial. With SoftwareSerial, we can assign another set of pins for serial devices.
Please download the library then add it by clicking the Sketch > Include Library > Add ZIP Library and select the downloaded SoftwareSerial library.
Hardware Instruction
- Connect the Arduino Uno pin 2 to USB-Serial converter Tx pin.
- Connect the Arduino Uno pin 3 to USB-Serial converter Rx pin.
- Connect the supply voltage to USB-Serial converter.
- Upload the sketch provided below in the source code section. This sketch should function as follows:
- Data sent from hardware serial port should be receive in software serial port.
- Data sent from software serial port should be receive in hardware serial port.
- Please feel free to modify and experiment with the source code to maximize learning.
Video Demonstration
Source Code
1#include "SoftwareSerial.h"
2
3SoftwareSerial swSerial(2,3);
4
5void setup(){
6 //Initialize HARDWARE serial port
7 Serial.begin(9600);
8 //Initialize SOFTWARE serial port
9 swSerial.begin(9600);
10 Serial.print("Setup DONE.");
11}
12
13void loop(){
14 // If there is data from software serial
15 if (swSerial.available()){
16 Serial.write(swSerial.read()); // Write it to hardware serial
17 }
18
19 // If there is data from hardware serial
20 if (Serial.available()){
21 swSerial.write(Serial.read()); // Write it to software serial
22 }
23}
Call To Action
If you find this tutorial helpful, please consider supporting my Youtube channel techtotinker.com. Please leave your comments and suggestions in the comment box. Thank you and have a good day. Happy tinkering.
Posts in this series
- How to Get Started with ATTiny85 in Arduino IDE
- Tutorial: How to use MFRC522 RFID module using Arduino
- SOS Flasher Using Millis Function with Enable Switch
- Tutorial: How to use DS3231 RTC in Arduino
- Tutorial: How to use 0.96 OLED - a small and cute display
- Tutorial: Getting Started with the NRF24L01 | How to use | Arduino
- Tutorial: How to use SIM800L GSM Module for Controlling Anything | Arduino
- Tutorial: How to use Keypad | Text Entry Mode | Arduino
- Tutorial: How to use 4x4 Keypad | Arduino
- Project Idea: Arduino Voltmeter
- Project Idea: Door Lock Security | Arduino
- Multitasking with Arduino | Relay Timer Controller | using millis
- Tutorial Understanding Blink Without Delay | How to millis
- Arduino Simple LCD Menu
- How to use SIM800L GSM Module using Arduino | Make or Answer Voice Calls
- Tutorial: How to Use Arduino Uno as HID | Part 2: Arduino Mouse Emulation
- Tutorial: How to Use Arduino Uno as HID | Part 1: Arduino Keyboard Emulation
- Tutorial: How to use SIM800L DTMF to Control Anything | Arduino
- Tutorial: Arduino EEPROM
- How to use SIM800L GSM Module | Arduino | Send and Receive SMS
- 16x2 LCD Menu for Arduino
- Tutorial: Arduino GPIO | How to use Arduino Pins
- MIT App Inventor for Arduino
- RC Car using L298N, HC-06, and Arduino Uno
- How to Use LCD Keypad Shield for Arduino
- How to Use Arduino Interrupts
- Project: Automatic Alcohol Dispenser
- TUTORIAL: How to use HC-SR04 Ultrasonic Sensor with Arduino
- Source Code: Astronomia Meme and Funeral Dance | melodies the Arduino way
- How to Get Started with L293D Motor Driver Shield with Arduino
- How to Get Started with L298N Motor Driver module using Arduino
- Part 2: Wav Music Player with Lyrics Using Arduino and SD Card
- Interfacing Infrared to Arduino Uno
- Part 1: Wav Music Player Using Arduino Uno and SD Card
- How to Interface Stepper Motor to Arduino Uno
- How To Play MP3 Files on Arduino from SD Card
- How to Interface SD card to Arduino (without SD card shield)?
- Playing Melodies Using Arduino
- 8 Degrees Of Freedom (DOF) Robot Using Arduino Uno
- How to Interface PS2 Controller to Arduino Uno
- Part 3: DF Player Mini Tinkering with Arduino Nano and LCD
- How to Interface HC-06 to Arduino
- How to make a Remote Control RC car using Arduino and HC-06 bluetooth module
- Part 2: DF Player Mini Tinkering with Arduino Nano
- Part 1: DF Player Mini - a mini cheap mp3 player
No comments yet!