0% found this document useful (0 votes)
6 views

4in1 Arduino Tutorial 2

The document discusses a tutorial on serial communication and sensing with Arduino. It covers serial communication, Arduino UART, reading analog and digital inputs, types of serial communication including synchronous and asynchronous, and an example of reading an analog potentiometer value and controlling an LED brightness.

Uploaded by

mervynmada2001
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

4in1 Arduino Tutorial 2

The document discusses a tutorial on serial communication and sensing with Arduino. It covers serial communication, Arduino UART, reading analog and digital inputs, types of serial communication including synchronous and asynchronous, and an example of reading an analog potentiometer value and controlling an LED brightness.

Uploaded by

mervynmada2001
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

BRUTE FORCE

ELECTRONICS-PROGRAMMING-ROBOTICS

BRUTE FORCE [email protected] +263718384192


Course Overview

▪ Week 1 – Electronics
▪ Week 2 – Programming
▪ Week 3 – Arduino
▪ Week 4 – Robotics

BRUTE FORCE [email protected] +263718384192


Tutorial 2

Serial Monitoring and Sensing

BRUTE FORCE [email protected] +263718384192


Focus
● Serial Communication
● Parallel Communication
● Types of Serial Communication
● Arduino UART
● Reading Analog and Digital Inputs

BRUTE FORCE [email protected] +263718384192


Arduino Serial Communication
● Serial communication is the process of communicating between
electronic devices one bit at a time. It provides an easy and flexible way
for your Arduino board to interact with your computer and other
devices.
● Serial communications are also a handy tool for debugging. You can
send debug messages from Arduino to the computer and display them
on your computer screen.
● We use serial communications every time we click the upload button in
our IDE. This process is actually displayed on the main board via LED's
labelled Tx and Rx.
● If the Arduino is receiving bits the Rx pin will flash. If the Arduino is
transferring bits, the Tx pin will flash. Every Arduino board has at least
one Serial communications chip-on-board, called a UART (Universal
asynchronous receiver/transmitter).

BRUTE FORCE [email protected] +263718384192


...Arduino Serial Communication
● Serial Functions in Arduino:
a) Serial.begin(baud_rate) - to define the baud rate that will be used for serial communication e.g. Serial.begin(9600)
defines 9600 baud rate for communication.
b) Serial.available() -to get the number of bytes available for reading from the serial port. It gives the number of bytes of data
that has arrived and is stored in the serial receive buffer e.g. if(Serial.available())
c) Serial.print(value) - used to print data to a serial port in a form that is human readable (character, strings,
numbers).e.g. Serial.print(“Hi 1234”)
d) Serial.read() - returns a character that was received on the Rx pin of
Arduino e.g char read_byte
read_byte =
Serial.read() Byte of
data read is stored in read_byte.
e) Serial.write(value), Serial.write(string), Serial.write(buff, length) - writes data in binary form to the serial port. Data is
sent in form of bytes or series of bytes.
● value : value to be sent as a single byte.
● string : string to be sent as a series of bytes.
● buff : array of data to be sent as bytes.
● length : number of bytes to be sent.

BRUTE FORCE [email protected] +263718384192


Print data received through serial communication on to the serial monitor of
Arduino

BRUTE FORCE [email protected] +263718384192


Types of Serial Communication
● Serial communication can be further classified as −
1. Synchronous − Devices that are synchronized use the same clock and their timing is in synchronization with each other.
2. Asynchronous − Devices that are asynchronous have their own clocks and are triggered by the output of the previous
state.
● It is easy to find out if a device is synchronous or not. If the same clock is given to all the connected devices, then they are
synchronous. If there is no clock line, it is asynchronous.
● The asynchronous serial protocol has a number of built-in rules. These rules are nothing but mechanisms that help ensure
robust and error-free data transfers. These mechanisms, which we get for eschewing the external clock signal, are −
1. Synchronization bits
2. Data bits
3. Parity bits
4. Baud rate

BRUTE FORCE [email protected] +263718384192


.....Types of Serial Communication

1. Synchronization bits - These are the start and stop bits transferred with each chunk of data. They let the
receiver know that data is coming and when it has finished transmitting.
2. Data bits - This is the actual information we send, can be 5-9 bits long.
3. Parity bits - Parity bits are determined using odd or even logic after adding each 1 from the data chunk. It is a
method of error checking that slows your data transfer and you will need a method to resend incorrect dat
4. Baud rate - the baud rate is the speed at which both devices agree to send and receive data at. Think of this as a
clock signal that you sent and forget. It is measured in bits per second.

BRUTE FORCE [email protected] +263718384192


Parallel Communication
When coming to Arduino, the
• Parallel communication is a method of transferring multiple bits of data
communication between Arduino
simultaneously using more number of data lines.
UNO (or any other board) and
• Parallel connection between the Arduino and peripherals via input/output ports is the
computer is serial
ideal solution for shorter distances up to several meters. However, in other cases
communication.
when it is necessary to establish communication between two devices for longer
distances it is not possible to use parallel connection.
• Parallel interfaces transfer multiple bits at the same time.
The main advantages of serial
communication over parallel
communication are longer
distance communication, less
number of wires for
communication, reduction in
hardware complexity etc.

BRUTE FORCE [email protected] +263718384192


Arduino UART
● UART stands for Universal Asynchronous Receiver/Transmitter.
● is a serial communication protocol used to transmit/receive data serially
at a specific baud rate.
● It is a hardware device (or circuit) used for serial communication between
two devices.
● . It can be used to communicate data between PC or various serial devices
like GSM, GPS, Bluetooth, etc.

BRUTE FORCE [email protected] +263718384192


Reading Analog and Digital Inputs

You will need:


Arduino board
Breadboard
LED
220 ohm resistor
potentiometer

BRUTE FORCE [email protected] +263718384192


//Constants:
const int ledPin = 9; //pin 9 has PWM funtion
const int potPin = A0; //pin A0 to read analog input

//Variables:
int value; //save analog value

void setup(){
pinMode(ledPin, OUTPUT);
pinMode(potPin, INPUT); //Optional

void loop(){
value = analogRead(potPin); //Read and save analog value from potentiometer
value = map(value, 0, 1023, 0, 255); //Map value 0-1023 to 0-255 (PWM)
analogWrite(ledPin, value); //Send PWM value to led
delay(100); //Small delay

BRUTE FORCE [email protected] +263718384192


THANK YOU ARDUINO GEEKS!

IGNITING CREATIVITY - LEARN BY DOING

You might also like