In most case, our device are stand-alone application, which means we don’t involve any additional computer for operation. However, we can still make Arduino interact with our computer in such nice way. We use serial communication to achieve this.

Most possible reason for communication is debugging purpose. We analyze Arduino state for various input and condition given, by reading output shown by Arduino. The serial communication can also be used for communication of two devices.

Arduino have built-in support for serial communication on pin 0 and 1, but what if we need more serial ports? Here come SoftwareSerial Library to rescue. This library has been developed to allow serial communication to take place on the other digital pins of our Arduino board, using software to replicate the functionality of the hardwired RX and TX lines. This can be extremely helpful when the need arises to communicate with two serial enabled devices, or to talk with just one device while leaving the main serial port open for debugging purpose.

Objective

  • Use pin 10 and 11 as virtual RX and TX serial lines.
  • Echo data received from main RX serial line to virtual TX line.
  • Echo data received from virtual RX line to main TX serial line.

Prerequisite

Requirement

Following is all materials I use for this tutorial.

  • Arduino Uno R3

You can change the Arduino board to higher specification if you like.

You also need an USB A to B cable for upload our program to our Arduino and also for serial communication.

Circuit

Here is the circuit image, created using Fritzing.

SerialComm

We don’t need any extra component to do this project.

SerialComm_Diagram

Code

Let’s see what code we use for this project and discuss it later.

Here we have two serial line: Arduino serial and virtual serial by SoftwareSerial. Both have difference baud rate, the main lines have baud rate 57600 while the virtual lines have baud rate 4800.

The initialization of both lines are similar. We use begin() function to set the baud rate of both lines.

In loop(), we will echo every input we got. To do that, we should check the availability first. This is done by executing available(). To read data, Arduino use read() function. To send data to other end, Arduino provide print() and println() function. These functions are slight different where println() send extra new line character at the end of transmission.

Result

You need two serial lines connected to your PC. The result should be similar to Simple Serial Communication project. It is strongly recommended to use PuTTY and connect to both port recognized by your computer.

Why it Works

We have demonstrate serial communication in this project. The word serial means “one after the other”. Serial data transfer is a transmission method where data is transferred one bit at a time, one right after the other.

Information is passed back & forth between the computer and Arduino, by essentially, setting a pin high or low.

There are two condition of logic in circuit, HIGH and LOW. Some microcontrollers might define HIGH and LOW difference, but in Arduino Uno we have HIGH logic as 5V and LOW logic as 0V. If you know boolean value, yes this is boolean value with HIGH is true and LOW is false.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">