CPE400 Lab4
CPE400 Lab4
CPE400 Lab4
4
Serial Communication with the Microcontroller
Course Code: CPE400 Program: BSCPE
Course Title: Embedded Systems Date Performed:
Section: Date Submitted:
Members: Instructor:
1. Objective(s):
This activity aims to introduce the concept of Serial communication between a computer and a microcontroller
2. Intended Learning Outcomes (ILOs):
After performing the laboratory activity, the students should be able to:
2.1 Implement circuits with analog and digital input components and the microcontroller
2.2 Write a program that can read inputs for analog and digital inputs.
3. Discussion:
Microcontrollers are programmed through serial communication with the computer using the Arduino built-in serial library.
The Arduino Serial Library is used to communicate from the Arduino board back to the computer over the USB port.
Serial data transfer sequence is through one-bit data transfer at a time, in which the information is passed back & forth
between the computer and Arduino board by, essentially, setting the pin into a high or low status. Just like using the LED
lights as an indicator for the output. The connection of the Arduino board as shown in image below, emphasizes the data
transfer physical procedure from the software going to the Arduino board.
Besides, being used for programming, microcontrollers use serial communication to communicate with other devices such as
a Bluetooth module, WIFI module, and other microcontrollers. Serial communication can be established through the USB Port
of an Arduino UNO module or similar boards but communication can also be established through the pins 0, and 1. Although
using USB ports is more convenient especially for uploading programs.
The image below shows an Arduino UNO Board and the available pins for serial communication. Pins 0 (Rx) and 1 (Tx)
always operate by pair.
The Arduino UNO Board Analog and Digital Input pins
The Arduino UNO Board’s microcontroller the Atmega328 IC only has one Serial Rx and Tx pin for serial communication, as
such it is not advisable to use pins 0 and 1 as they are being used by the program to communicate with other devices and
even the
The serial library needs to be initialized with a baud rate also known as the data rate, which is the rate at which the
information/data/bits are being transferred over a given period of time (commonly seconds for example 9600 baud is
equivalent to 960 bytes per second). The Serial library is normally initialized once in the setup function with the
method .begin(). A larger Arduino board such as the Arduino Mega can handle more than one Serial instance.
In this activity, we will be exploring how to use the built-in Serial library of Arduino and apply it in the principle of serial
communication in microcontrollers in general.
4. Materials and Equipment:
Arduino UNO Board with USB Cable 3 LEDs (Green, Orange or Yellow, Red)
Desktop Computer with Arduino IDE 1 RGB LED
Solderless Breadboard Solid Wires/Jumping Wires
3 220 Ω Resistors
5. Procedure:
Using the Serial library
1. Open the Arduino IDE, and copy the code as shown below:
2. Upload the code to your Arduino Board. Click the Serial Monitor (shown by the red line). Observe the output.
3. Add a delay of 500 milliseconds after the Serial print as shown below. Observe the output again.
8. Conclusion:
9. Assessment Rubric:
Intended Learning Unsatisfactory Satisfactory Exemplary
Score
Outcomes 1 2 3
Combine serial Unable to Able to combine Able to combine
communication and combine serial serial serial communication
digital devices in communication communication and digital devices in
creating a program and digital and digital devices creating a program
devices in in creating a without errors
creating a program but with
program errors
Use serial Unable to use Able to use serial Able to use serial
communication in serial communication in communication in
displaying output. communication displaying output. displaying output.
in displaying but with errors without errors
output.
__________________
Printed Name and Signature of Faculty Member