Working with Serial Data

Step 1
Communicating via Serial

Serial Communication is a method for transmitting and receiving data

In this project we will use Serial Communication to send control data between a remote transmitter and a robotic receiver.

Step 2
Serial data is sent and received one byte at a time

We use the commands read and write for receiving and transmitting bytes.

Step 3
Our Arduino communicates with the computer through the Serial Port
Step 4
Open the Serial Monitor by clicking the Magnifying Glass Icon
Temp1493944730 Temp1493944684
Step 5
We can use the Serial Monitor to view Serial data on the Arduino

The box at the top let's us send data to the Arduino's receiver pin.


The box at the bottom let's us view the Arduino's transmitted data.

Step 6
You may remember using the Tx and Rx pins from previous lessons

These pins are linked to the Arduino's Serial port.

Step 7
Let's send data to the computer

To do this we first need to set the baud rate- the rate at which data is transferred in bytes per second.

The default baud rate is 9600 as you can see in the monitor:

Step 8
Use Serial.begin() to set the Serial Port's baud rate to 9600 bytes/sec
Step 9
Now we can use the write command to transmit data

Hit Upload and you'll see this data in the Serial Monitor's Tx field.

Step 10
Serial Buffers

Writing Serial data places the data into a buffer which transmits the information one byte at a time through the port:

This data is then stored by the receiving entity in a second buffer.

Step 11
Sending data from the computer to the Arduino

This field in the Serial Monitor allows us to send data to the Arduino's receiver pin (The Rx pin).


The data will be stored in the Serial buffer.

Step 12

Each time is called, the first character in the buffer pops out and gets returned:

Step 13
Create a character type variable named "inByte"

In the loop() function, have it continuously read from the Serial buffer.


Then write inByte back to the Serial Monitor so we can check it

Check Your Work
Step 14
Upload your code and check the Serial Monitor

You should see a constant stream of null-characters!


We need to tell our program to only read from the buffer if there is data available.

Step 15
Use Serial.available to make the program only read data if there is data available in the Serial buffer
Temp1493949405 Temp1493949610
Check Your Work
Step 16
Whatever you type in the Rx field should now appear in the Tx field

Send a few messages and notice how they get written right next to each other:

Step 17
Right now our system looks like this

We type something and send it to the Rx pin of our Arduino's Serial Port buffer.

Then we can read each character using


Lastly we write the character to the Tx pin of the Arduino's Serial Port buffer, which we can see in the monitor.

Step 18
The newline character '\n'

This is a special, invisible, character \n which creates a newline when read.

For example

Step 19
Set the Serial Monitor to add a newline character after each message you send
Check Your Work
Step 20
Each message now create a newline at the end

This will be really useful in the upcoming lessons where we will want to split multi-character data into separate "chunks"

Step 21
In the next lesson we will be setting up our transmitter so that it automatically connects with our receiver
Working with Serial Data Info


MVCode Clubs

Created By

Newprofile jamie


Build your own remote controller (advanced)

Access Level


For Teachers and Schools

Teach coding to your students with MVCode Teach

MVCode offers an integrated product designed to teach coding to students.

Learn more about MVCode Teach