You are on page 1of 21

ENGG 200

Introduction to Engineering

Serial Monitor, Analog Signals

LIU ENGG200- Introduction to Engineering 1


What is Serial
▪ The word serial means "one after the other." Serial data
transfer is when we transfer data one bit at a time, one right
after the other.

LIU ENGG200- Introduction to Engineering 2


Arduino Serial Interfaces
• Used for communication between the Arduino board and a
computer or other devices.

• Arduino platforms have at least one serial port (also known


as a UART or Universal Asynchronous Receiver/Transmitter)

• Serial Communicates through digital pins 0 (RX) & 1 (TX)


and via USB to Computer for Sketches

LIU ENGG200- Introduction to Engineering 3


Serial Write – Key Concepts
• Serial.begin(): Sets the data rate in bits per second (baud) for
serial data transmission
• Syntax: Serial.begin(baud)
• Example: Serial.begin(9600) sets serial baud rate to 9600 bits
per second

• Serial.print(): Prints data to the serial port as human-readable


ASCII text without carriage return / Newline Feed character
• Syntax: Serial.print(val) or Serial.print(val, format)
• Parameters:
• val: the value to print - any data type
• format: specifies the number base or number of decimal places
• Example: Serial.print(”Hello world.“) gives "Hello world.“
• Example: Serial.print(1.23456, 2) gives “1.23”

LIU ENGG200- Introduction to Engineering 4


Serial Write – Key Concepts

• Serial.println(): Prints data to the serial port as human-readable ASCII


text followed by a carriage return and a newline character
• Syntax: Serial.println(val) or Serial.print(val, format)
• Parameters:
• val: the value to print - any data type
• format: specifies the number base or number of decimal places
• Example: Serial.println(”Hello world.“) gives "Hello world.“
• Example: Serial.println(1.23456, 2) gives “1.23”

• Serial.write(): Writes binary data to the serial port. This data is sent as a
byte or series of bytes
• Syntax: Serial.write(val)
• Example: Serial.wrtie(”Hello world“) writes "Hello world“

LIU ENGG200- Introduction to Engineering 5


Bring up Serial Monitor
• Select “Tools” -> “Serial Monitor” or click Serial Monitor Icon

Note: Sketch must be loaded first; else, Serial Monitor will close on Sketch upload

OR
ANALOG SIGNALS
▪ Analog signal is any continuous signal Vs. time!
▪ digital signal uses discrete (discontinuous) values

LIU ENGG200- Introduction to Engineering 7


Analog vs digital signals

5V

0V

5V

0V
Analog Sensors

LM35 LDR Potentiometer

LIU ENGG200- Introduction to Engineering 9


ANALOG READ – BOARD HARDWARE
• 10 bit resolution .
• (GPIO) pins .
• 100 µs (0.0001 s) to read an analog input .
▪ reading rate = 10,000 /s

LIU ENGG200- Introduction to Engineering 10


Analog Read – Key Concepts
• analogRead(): Reads the value from the specified analog
pin.

• Syntax: analogRead(pin)

• Example: analogRead(A0) reads analog value of pin A0

LIU ENGG200- Introduction to Engineering 11


Analog to digital conversion
Need to convert
analog signals to
digital for processing.

Digital signal
depends on the
resolution of the
analog-to-digital
converter (ADC).
A 10-bit system will
have 1,024 points of
resolution.
210 = 1,024 Why the number 2?
Because there are two options in a binary system (0 & 1).
Analog to digital conversion

▪ Arduino translates an analog input voltage into a number that


ranges from 0 - 1,023.
▪ Digital voltages are translated into a number that ranges from
0 – 255.

0 255
potentiometer
Circuit #2: Potentiometer
How to read analog input from the
physical world using a potentiometer
(“pot” for short) and control the blink rate
of an LED. We’ll also learn how to use the
serial monitor to watch how the voltage
changes.

When it’s connected with 5V across its +5V


two outer pins, the middle pin outputs a
voltage between 0 and 5V, depending on
the position of the knob. In this way, it can Analo
be used as a “voltage divider”. GN g
D Input
Circuit schematic

The left side of the schematic


is the same as the previous
circuit.

We’re adding a
potentiometer to
control the blink rate of
the LED.

We’re running 5V across the outer


pins of the pot. The middle pin of
the potentiometer will be
connected to analog input pin 0.

Note: All analog pins on the Arduino are INPUT pins.


Digital pins can be INPUT or OUTPUT pins.
Design it!
Design it!
Potentiometer/Voltage Divider

▪ A voltage divider (Figure 3-7) can change an output voltage


with a combination of resistors
▪ A potentiometer is another example of a voltage divider
when used for controlling the movement of a motor
▪ A second use of voltage dividers is as a logic level converter
to reduce the voltage of a transmitted signal. For example, a
logic level converter is required by a receiving Bluetooth
module operating at 3.3V when connected to an Arduino
transmitting a 5V signal
▪ We can also use it to control the contrast of an LCD, the
brightness of a LED as we will see later on

LIU ENGG200- Introduction to Engineering 19


Voltage Divider

Vin

LIU ENGG200- Introduction to Engineering 20


Voltage Divider

Vin

LIU ENGG200- Introduction to Engineering 21

You might also like