Learn about Serial communication between two Arduino Boards. It can be also for serial communication between multiple Arduinos. Transmit data between two Arduino using RX/TX lines. Learn to work. The main advantages of serial communication over parallel communication are longer distance communication, less number of wires for communication, reduction in hardware complexity etc. When coming to Arduino, the communication between Arduino UNO (or any other board) and computer is serial communication.
Serial communications can be used in many ways, but in this situation we will use it to turn off and on an LED.
Just add an LED to pin 13 and ground. Then connect your USB cable.
Create an integer to store the incoming serial byte. I decided to name it 'inByte'
In the void setup, set pin 13 as an output and use 'Serial.begin(< baud rate >);' to initiate the serial communication. We used 9600bits per second, so we added - Serial.begin(9600);
in the void loop we first need to know when a byte is available to be read. So, we use 'Serial.available()' This function returns the number of bytes that are available to be read. So, if we use 'if(Serial.available() > 0)', we know there is at least one byte that we can read.
inside that if statement, we need to read the byte and store it for later use. we will use 'Serial.read()', which will read the byte. then we will save it to inByte. In total, this line read: inByte = Serial.read();
While still being inside the main if statement (<'if(Serial.available() > 0)>) we add if statements. To read or write a letter to a variable, we will put the letter in single quotation marks. We wanted our LED to turn on if we sent an 'a' to the Arduino. Thus, our if statement read: 'if(inByte 'a')' inside the if statement we added set the pin to HIGH.
Also, we used 'Serial.println()' so that the arduino will notify us, right within the Serial monitor, that it has read an 'a' and has turned on the LED.
This if statement looked like this:
if(inByte 'a') { // byte is 'a'
digitalWrite(13, HIGH);
Serial.println('LED - On');
}
We also wanted the LED to turn off if any other letter was read. so we added an else statement which turned the LED off.
This all may seem confusing, but it is easier to understand if you look at the final code on the next page.
Just add an LED to pin 13 and ground. Then connect your USB cable.
Create an integer to store the incoming serial byte. I decided to name it 'inByte'
In the void setup, set pin 13 as an output and use 'Serial.begin(< baud rate >);' to initiate the serial communication. We used 9600bits per second, so we added - Serial.begin(9600);
in the void loop we first need to know when a byte is available to be read. So, we use 'Serial.available()' This function returns the number of bytes that are available to be read. So, if we use 'if(Serial.available() > 0)', we know there is at least one byte that we can read.
inside that if statement, we need to read the byte and store it for later use. we will use 'Serial.read()', which will read the byte. then we will save it to inByte. In total, this line read: inByte = Serial.read();
While still being inside the main if statement (<'if(Serial.available() > 0)>) we add if statements. To read or write a letter to a variable, we will put the letter in single quotation marks. We wanted our LED to turn on if we sent an 'a' to the Arduino. Thus, our if statement read: 'if(inByte 'a')' inside the if statement we added set the pin to HIGH.
Also, we used 'Serial.println()' so that the arduino will notify us, right within the Serial monitor, that it has read an 'a' and has turned on the LED.
This if statement looked like this:
if(inByte 'a') { // byte is 'a'
digitalWrite(13, HIGH);
Serial.println('LED - On');
}
We also wanted the LED to turn off if any other letter was read. so we added an else statement which turned the LED off.
This all may seem confusing, but it is easier to understand if you look at the final code on the next page.
Software Serial Example
Arduino and Genuino boards have built in support for serial communication on pins 0 and 1, but what if you need more serial ports? The SoftwareSerial Library has been developed to allow serial communication to take place on the other digital pins of your boards, 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.
In the example below, digital pins 10 and 11 on your Arduino or Genuino boards are used as virtual RX and TX serial lines. Windows tablet driver error. The virtual RX pin is set up to listen for anything coming in on via the main serial line, and to then echo that data out the virtual TX line. Conversely, anything received on the virtual RX is sent out over the hardware TX.
Full Specifications What's new in version 2.10.1.699Version 2.10.1.699 fixes Bugzilla Output does not work.GeneralPublisherPublisher web siteRelease DateMay 17, 2013Date AddedMay 22, 2013Version2.10.1.699CategoryCategorySubcategoryOperating SystemsOperating SystemsWindows XP/Vista/7Additional Requirements.NET Framework 3.5Download InformationFile Size6.17MBFile NameBugShooting2.10.1.699.exePopularityTotal Downloads728Downloads Last Week1PricingLicense ModelFree to tryLimitations30-day trialPrice$25.06. Bug shooting software.
Hardware Required
Arduino To Arduino Bluetooth Serial Communication
- Arduino or Genuino Board
Arduino To Arduino Serial Communication
Circuit
There is no circuit for this example. Make sure that your Arduino or Genuino board is attached to your computer via USB to enable serial communication through the serial monitor window of the Arduino Software (IDE).
image developed using Fritzing. For more circuit examples, see the Fritzing project page
Schematics
image developed using Fritzing. For more circuit examples, see the Fritzing project page
Code
See also
- TwoPortReceive – Two serial ports that receive data switching from one to the other one when a special character is received.
- MultiSerialMega - Use two of the serial ports available on the Arduino and Genuino Mega.
- Serial Call Response - Send multiple vairables using a call-and-response (handshaking) method.
- Serial Call Response ASCII - Send multiple variables using a call-and-response (handshaking) method, and ASCII-encode the values before sending.
Last revision 2018/05/17 by SM