0% found this document useful (0 votes)
5 views66 pages

Lecture 04 05 IoT Systems Logical Design Using Arduino Part 1 2

Uploaded by

longpnbh01131
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
5 views66 pages

Lecture 04 05 IoT Systems Logical Design Using Arduino Part 1 2

Uploaded by

longpnbh01131
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 66

INTERNET OF THINGS

Chapter 4
IoT Systems - Logical Design
using Arduino (Part 1 & 2)
INTERNET OF THINGS A HANDS ON APPROACH
Objectives
▪ Better understanding of Arduino
▪ Mastery of Arduino hardware
▪ Programming for Arduino
▪ Simple sample projects
Topics
▪ What is Arduino?
▪ Hardware
▪ Programming the Arduino
▪ How to get started?
What is a Microcontroller?
A microcontroller (MCU for microcontroller
unit) is a small computer on a single metal-
oxide-semiconductor (MOS) integrated
circuit (IC) chip. A microcontroller contains
one or more CPUs (processor cores) along
with memory and programmable
input/output peripherals.
Arduino Microcontroller
▪ Open-source electronics platform
based on easy-to-use hardware and
software

▪ Are able to read inputs - light on a


sensor, a finger on a button, or a
Twitter message - and turn it into an
output - activating a motor, turning on
an LED, publishing something online
What is it used for?

▪ Physical Computing projects/research

▪ Interactive Installations

▪ Rapid Prototyping
Types of Arduinos
What is the difference between them?
Types of Arduino
Analog and digital pins

▪ The Arduino can input and output analog signals as well as


digital signals

▪ An analog signal is one that can take on any number of


values, unlike a digital signal which has only two values:
HIGH and LOW
Hardware

THE ARDUINO UNO


Hardware

POWER
Hardware

BREADBOARDS
Hardware

JUMPER WIRES
Programming The Arduino

How Arduino is programmed?


Using a software
called Arduino IDE
Programming The Arduino
Arduino Software (IDE)
The Arduino Integrated Development Environment - or Arduino Software
(IDE) - contains a text editor for writing code, a message area, a text
console, a toolbar with buttons for common functions and a series of
menus. It connects to the Arduino hardware to upload programs and
communicate with them.
Programming The Arduino
Arduino Language

▪ Simplified C/C++
▪ Based on the wiring project: http://wiring.org.co
▪ Peripheral libraries: LCD, sensors, 12C, ect
Programming The Arduino
Useful functions
Programming The Arduino

The IDE Interface


Programming The Arduino
Arduino Sketches
Programming The Arduino
Libraries
▪ Step 1. Choose Sketch=>Include Library=>Add .ZIP Library.
▪ Step 2. Browse to the ZIP file you downloaded and select it. For
older versions of Arduino, you’ll need to unzip the library file and
then put the whole folder and its contents into the sketchbook/
libraries folder on Linux, My Documents\Arduino\Libraries on
Windows, or Documents/Arduino/libraries on OS X.
How to get started?
Electricity\Electronics Basic Concept Review
▪ Ohms Law
▪ Voltage
▪ Current
▪ Resistance
▪ Using a Multi-meter
Ohm’s Law
Electrical Properties

Voltage Current Resistance


V I R
• Defined as • The rate of
the amount charge flow
of potential in a circuit.
energy in a • Units: Amperes (A)
circuit.
• Units: Volts (V)
Current Flow Analogy

High Current Low Current


Voltage Analogy

Water
Tower
Water
Tower

V
V

More Energy == Higher Voltage Less Energy == Lower Voltage


Resistance Analogy

Water Water
Tower Tower

Big Pipe == Lower Resistance Small Pipe == Higher Resistance


Continuity – Is it a Circuit?
The word “circuit” is derived from the circle. An
Electrical Circuit must have a continuous LOOP
from Power (Vcc) to Ground (GND).

Continuity is important to make portions of


circuits are connect. Continuity is the simplest and
possibly the most important setting on your multi-
meter. Sometimes we call this “ringing out” a
circuit.
Measuring Electricity – Voltage
Voltage is a measure of potential electrical energy. A voltage is also
called a potential difference – it is measured between two points in a
circuit – across a device.
Measuring Electricity -- Current
Current is the measure of the rate of charge flow. For Electrical Engineers – we
consider this to be the movement of electrons.
In order to measure this – you must break the circuit or insert the meter in-line
(series).
Measuring Electricity -- Resistance
Resistance is the measure of how much opposition to current flow is in a circuit.
Components should be removed entirely from the circuit to measure resistance.
Note the settings on the multi-meter. Make sure that you are set for the
appropriate range.

Resistance
settings
Prototyping Circuits Solderless Breadboard
▪ One of the most useful tools in an engineer or Maker’s toolkit. The
three most important things:
• A breadboard is easier than soldering
• A lot of those little holes are connected, which ones?
• Sometimes breadboards break
What’s a Breadboard?
Solderless Breadboard

▪Each row (horiz.) of 5


holes are connected.

▪Vertical columns –
called power bus are
connected vertically
Using the Breadboard to built a simple circuit

▪Use the breadboard


to wire up a single
LED with a 330 Ohm
Resistor (Orange-
Orange-Brown).
Note: the longer leg on the
LED is the positive leg and
the shorter leg is the
negative
Fritzing View of Breadboard Circuit

▪What happens
when you break
the circuit?
▪What if you
wanted to add
more than one
LED?
Adding control – let’s use the Arduino and start programming!
Concepts: INPUT vs. OUTPUT
Referenced from the perspective of the microcontroller (electrical board).

Inputs is a signal / information Output is any signal exiting the


going into the board. board.

Almost all systems that use physical computing will have some form of output

What are some examples of Outputs?


Concepts: INPUT vs. OUTPUT
Referenced from the perspective of the microcontroller (electrical board).

Inputs is a signal / information Output is any signal exiting the


going into the board. board.

Examples: Buttons Switches, Light Examples: LEDs, DC motor, servo


Sensors, Flex Sensors, Humidity motor, a piezo buzzer, relay, an RGB
Sensors, Temperature Sensors… LED
Concepts: Analog vs. Digital
▪Microcontrollers are digital devices – ON or
OFF. Also called – discrete.

▪analog signals are anything that can be a full


range of values. What are some examples?
More on this later…
5V 5V

0V 0V
Open up Arduino

▪Hints:
▪For PC Users → For Mac Users →
1.Let the installer copy and move the 1. Move the Arduino
files to the appropriate locations, or executable to the dock
2.Create a folder under C:\Program Files for ease of access.
(x86) called Arduino. Move the entire 2. Resist the temptation to
Arduino program folder here. run these from your
desktop.
Integrated Development Environment (IDE)
Two required functions /
methods / routines:

void setup()
{
// runs once
}

void loop()
{
error & status messages // repeats
}
Settings: Tools → Serial Port

▪Your computer communicates


to the Arduino microcontroller
via a serial port → through a
USB-Serial adapter.

▪Check to make sure that the


drivers are properly installed.
Settings: Tools → Board

▪Next, double-check that the proper board is selected under the


Tools→Board menu.
Arduino & Arduino Compatible Boards
digitalWrite()

BIG 6 CONCEPTS
analogWrite()

digitalRead()

if() statements / Boolean

analogRead()

Serial communication
Let’s get to coding…
▪Project #1 – Blink
•“Hello World” of Physical Computing

▪ Psuedo-code – how should this work?

Turn LED Turn LED Rinse &


Wait Wait
ON OFF Repeat
Comments, Comments, Comments
▪ Comments are for you – the programmer and your
friends…or anyone else human that might read your code.

▪ // this is for single line comments


▪ // it’s good to put a description at the
top and before anything ‘tricky’
▪ /* this is for multi-line comments
▪ Like this…
▪ And this….
▪ */
comments
Three commands to know…
▪ pinMode(pin, INPUT/OUTPUT);
▪ ex: pinMode(13, OUTPUT);

▪ digitalWrite(pin, HIGH/LOW);
▪ ex: digitalWrite(13, HIGH);

▪ delay(time_ms);
▪ ex: delay(2500); // delay of 2.5 sec.

▪ // NOTE: -> commands are CASE-sensitive


Project #1: Wiring Diagram

Move the green


wire from the
power bus to pin 13
(or any other Digital
I/O pin on the
Arduino board.

Image created in Fritzing


A few simple challenges
Let’s make LED#13 blink!
▪ Challenge 1a – blink with a 200 ms second interval.

▪ Challenge 1b – blink to mimic a heartbeat

▪ Challenge 1c – find the fastest blink that the human eye can
still detect…
▪ 1 ms delay? 2 ms delay? 3 ms delay???

Try adding other LEDs
Programming Concepts: Variables
Variable Scope

▪Global
▪---
▪Function-level
Programming Concepts: Variable Types
▪ Variable Types:

8 bits 16 bits 32 bits

byte int long


char unsigned int unsigned long
float
Fading in and Fading Out (Analog or Digital?)
▪ A few pins on the Arduino allow for us to modify the output
to mimic an analog signal.

▪ This is done by a technique called:


▪ Pulse Width Modulation (PWM)
Concepts: Analog vs. Digital

▪To create an analog signal, the microcontroller


uses a technique called PWM. By varying the duty
cycle, we can mimic an “average” analog voltage.

▪Pulse Width Modulation (PWM)


Project #2 – Fading
Introducing a new command…

▪analogWrite(pin, val);

▪pin – refers to the OUTPUT pin


(limited to pins 3, 5, 6, 9, 10, 11.) –
denoted by a ~ symbol

▪val – 8 bit value (0 – 255).


▪ 0 => 0V | 255 => 5V
Move one of your LED pins over to Pin 9
▪ In Arduino, open up:
▪ File → Examples → 01.Basics → Fade
Fade - Code Review
Fade - Code Review
Project# 2 -- Fading
▪ Challenge 2a – Change the rate of the fading in and out.
There are at least two different ways to do this – can you
figure them out?

▪ Challenge 2b – Use 2 (or more) LEDs – so that one fades in as


the other one fades out.
R G B

Color Mixing
Tri-color LED

▪ In the SIK, this is a standard –


Common Cathode LED

▪ This means the negative side


of the LED is all tied to Ground.
Summary
• Understanding the Arduino Platform
• Demystifying Hardware Componen
• Know how to program using Arduino
• Applying simple sample project developmentts

You might also like