Module 5
Module 5
Module 5
Arduino:
It has 14 digital input/output pins (of which 6 can be used as PWM outputs),
6 analog inputs, a 16 MHz quartz crystal, a USB connection, a power jack, an
ICSP header and a reset button.
"Uno" means one in Italian and was chosen to mark the release of Arduino Software
(IDE) 1.0. The Uno board and version 1.0 of Arduino Software (IDE) were the
reference versions of Arduino, now evolved to newer releases.
Module – 5 IoT Physical Devices and End Point-
Aurdino Uno
Module – 5 IoT Physical Devices and End Point-
Aurdino Uno
1. Reset Button – This will restart any code that is loaded to the 9. Power LED Indicator – This LED lights up anytime the board is
Arduino board plugged in a power source
2. AREF – Stands for “Analog Reference” and is used to set 10. Voltage Regulator – This controls the amount of voltage going
an into the Arduino board
external reference voltage
3. Ground Pin – There are a few ground pins on the Arduino and 11. DC Power Barrel Jack – This is used for powering your
they all work the same Arduino with a power supply
4.Digital Input/Output – Pins 0-13 can be used for digital input or 12. 3.3V Pin – This pin supplies 3.3 volts of power to your projects
output
13. 5V Pin – This pin supplies 5 volts of power to your projects
5. PWM – The pins marked with the (~) symbol can simulate
analog output 14. Ground Pins – There are a few ground pins on the Arduino
and they all work the same
6. USB Connection – Used for powering up your Arduino and
uploading sketches 15. Analog Pins – These pins can read the signal from an analog
sensor and convert it to digital
7. TX/RX – Transmit and receive data indication LEDs
void setup()
{
// runs once
}
void loop()
{
// repeats
}
10
Comments, Comments, Comments
Comments
Like this…
And this….
*/
comments
Three commands to
know…
pinMode(pin, INPUT/OUTPUT); ex:
pinMode(13, OUTPUT);
digitalWrite(pin, HIGH/LOW);
delay(time_ms);
ex: delay(2500); //
delay of 2.5sec.
// NOTE: -> commands are CASE-sensitive
Arduino Code Basics
Arduino programs run on two basic sections:
void setup() {
}
void loop() {
}
SETUP
16 16
SETUP
void setup() {
port #
pinMode(9, OUTPUT);
Input or Output
}
LOOP
digitalWrite(9, HIGH);
delay(1000);
digitalWrite(9, LOW);
delay(1000);
Turn the LED on
or off
} Wait for 1 second
or 1000 milliseconds
13
DECLARING A
VARIABLE
int val = 5;
assignment
Typ “becomes”
e value
variable
14
name
USING
VARIABLES
int delayTime = 2000;
int greenLED = 9;
void setup() {
Declare delayTime
pinMode(greenLED,
OUTPUT)V;ariable
void loop() {
digitalWrite(greenLED, HIGH);
delay(delayTime); Use
digitalWrite(greenLED, delayTime
LOVWa)ri;able delay(delayTime);
}
15
Using Variables
int delayTime = 2000;
int greenLED = 9;
void setup() {
pinMode(greenLED,
OUTPUT);
}
void loop() {
digitalWrite(greenLED,
HIGH);
delay(delayTime);
digitalWrite(greenLED,
subtract 100 from
} delayTime to gradually
LOW); increase LED’s
delayTime = delayTime - blinking speed
16 100; delay(delayTime);
Conditions
a>b a >= b
a<b a <= b
a == b a != b
23
IF Condition
if(true)
{
“perform some action”
}
IF Example
int counter = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
20 }
Input & Output
void setup()
{ Serial.begin(9600
21
Writing to the Console
void setup() {
Serial.begin(9600);
Serial.println(“Hello World!”);
void loop() {}
22
IF - ELSE Condition
If we want all of the conditions to be true we need to use ‘AND’ logic (AND gate)
• Example
32 32
BOOLEAN OPERATORS - OR
If we want either of the conditions to be true we need to use ‘OR’ logic (OR gate)
• Example
33 27
BOOLEAN
VARIABLES
boolean done = true;
boolean done = false;
void setup()
{ Serial.begin(9600);}
void loop() {
if(!done) {
Serial.println(“HELLOWORLD”);
done = true; }
} 28
Important functions
• Serial.println(value);
– Prints the value to the Serial Monitor on your computer
• pinMode(pin, mode);
– Configures a digital pin to read (input) or write (output) a digital value
• digitalRead(pin);
– Reads a digital value (HIGH or LOW) on a pin set for input
• digitalWrite(pin, value);
– Writes the digital value (HIGH or LOW) to a pin set for output
OUTLINE
• Essential Programming Concepts
– Delay
– Infinite Loop
• General Input/Output
– Polling or Busy/Wait I/O
– Interrupt Processing
• Timers and Internal Inteerrupts
• High-Level Language Extensions
• Code Transformations for Embedded Computing
– Loop Unrolling
– Loop Merging
– Loop Peeling
– Loop Tiling
DELAY (1/3)
• Delays are essential in embedded systems, unlike high-
performance systems where we want the program to
execute as fast as possible
• Delays are used to synchronize events, or read inputs
with a specific sampling freqency (more on Bus/Wait I/O)
DELAY (3/3)
• Okay, so how do we build a delay function?
• Our reference is the system clock frequency
• We use a register or a timer to measure ticks
• Each tick is 1/frequency
• Example: Assuming a 16-bit processor, an increment
and a jump instruction is 1-cycle each and a 10 MHz
system clock, build a 1-sec delay:
• T = 1/10 MHz = 100 ns
• 1 s/100 ns = 10,000,000
RaspberryPi:
Raspberry Pi is the name of a series of single-board computers made by the Raspberry Pi
Foundation, a UK charity that aims to educate people in computing and create
easier access to computing education.
The Raspberry Pi launched in 2012, and there have been several iterations and variations
released since then. The original Pi had a single-core 700MHz CPU and just 256MB RAM,
and the latest model has a quad-core 1.4GHz CPU with 1GB RAM. The main price point
for Raspberry Pi has always been $35 and all models have been $35 or less, including the
Pi Zero, which costs just $5.
41
Module – 5 IoT Physical Devices and End
Dr. Syed Mustafa, HKBKCE.
42
Module – 5 IoT Physical Devices and End
43
Module – 5 IoT Physical Devices and End
Dr. Syed Mustafa, HKBKCE.
Module – 5 IoT Physical Devices and End
Hardware Layout:
raspi-config
• The Raspberry Pi configuration tool in Raspbian, allowing you to easily enable features such as the camera, and
to change your specific settings such as keyboard layout
config.txt
•The Raspberry Pi configuration file
Wireless networking
• Configuring your Pi to connect to
a wireless network using the
Raspberry Pi 3's or Pi Zero W's
inbuilt wireless
connectivity, or a USB wireless
dongle
Wireless access point
• Configuring your Pi as a wireless access point using the Raspberry Pi 3 and Pi Zero W's inbuilt wireless
connectivity, or a USB wireless dongle
Module – 5 IoT Physical Devices and End Point-
Aurdino Uno
Using a proxy
•Setting up your Pi to access the internet via a proxy server
HDMI Config
• Guide to setting up your HDMI device, including custom settings
Audio config
•Switch your audio output between HDMI and the 3.5mm jack
Camera config
• Installing and setting up the Raspberry Pi camera board
External storage config
• Mounting and setting up external storage on a Raspberry Pi
Module – 5 IoT Physical Devices and End Point-
Aurdino Uno
Localisation
•Setting up your Pi to work in your local language/time zone
UART configuration
• How to set up the on-board UARTS.
You have a few options when it comes to interacting with the Raspberry Pi. The
first and most common is to use it like you would a full desktop computer (just
smaller). This involves connecting a keyboard, mouse, and monitor. With this
setup, you are likely best served by installing Raspbian with Desktop, which gives
you a full graphical user interface(GUI) to work with. This is the best option if you
want an experience similar to working with other operating systems (OS), such as
Windows, macOS, or other popular Linux flavors, like Ubuntu.
Module – 5 IoT Physical Devices and End
Programming RaspberryPi with Python:
SOFTWARE REQUIRED
• Raspbian Stretch OS
• SD card Formatter
• Win32DiskImager (or) Etcher
Module – 5 IoT Physical Devices and End
DS18B20 Temperature Sensor DS18B20 Temperature
Pinout Sensor
Module – 5 IoT Physical Devices and End
RaspberryPi OS: (Not RaspberryPi OS: RaspberryPi OS: RaspberryPi OS:
linux) (Linux based) (Media center based) (Audio based)
Data flows from devices at the street layer to the city network layer and connect to
the data center layer, where the data is aggregated, normalized, and virtualized.
The data center layer provides information to the services layer, which consists of
the applications that provide services to the city.
In smart cities, multiple services may use IoT solutions for many different purposes.
These services may use different IoT solutions, with different protocols and different
application languages
Module – 5 Smart City IoT Architecture:
Module – 5 Smart City IoT Architecture:
Street Layer:
The street layer is composed of devices and sensors that collect data and take action
based on instructions from the overall solution, as well as the networking
components needed to aggregate and collect data.
A sensor is a data source that generates data required to understand the physical
world. Sensor devices are able to detect and measure events in the physical world.
ICT connectivity solutions rely on sensors to collect the data from the world around
them so that it can be analyzed and used to operationalize use cases for cities.
Module – 5 Smart City IoT Architecture:
Dr. Syed Mustafa, HKBKCE.
Street Layer:
64
control has become an issue.
Module – 5 Smart City IoT Architecture:
City Layer:
At the city layer, which is above the street layer, network routers and switches
must be deployed to match the size of city data that needs to be transported.
This layer aggregates all data collected by sensors and the end-node network into
a
single transport network.
The city layer may appear to be a simple transport layer between the edge devices
and the data center or the Internet.
65
Module – 5 Smart City IoT Architecture:
City Layer:
However, one key consideration of the city layer is that it needs to transport
multiple types of protocols, for multiple types of IoT applications. Some applications
are delay- and jitter sensitive, and some other applications require a deterministic
approach to frame delivery.
City Layer:
In this model, at least two paths exist from any aggregation switch to the data
center layer. A common protocol used to ensure this resiliency is Resilient Ethernet
Protocol (REP).
Module – 5 Smart City IoT Architecture:
Ultimately, data collected from the sensors is sent to a data center, where it can be
processed and correlated.
Based on this processing of data, meaningful information and trends can be derived,
and information can be provided back.
For example, an application in a data center can provide a global view of the city
traffic and help authorities decide on the need for more or less common transport
vehicles. At the same time, an automated response can be generated
Module – 5 Smart City IoT Architecture:
The cloud model is the chief means of delivering storage, virtualization, adaptability,
and the analytics know-how that city governments require for the technological
mashup and synergy of information embodied in a smart city.
Traditional city networks simply cannot keep up with the real-time data needs of
smart cities; they are encumbered by their physical limitations.
The cloud enables data analytics to be taken to server farms with large and
extensible processing capabilities.
Module – 5 Smart City IoT Architecture:
Dr. Syed Mustafa, HKBKCE.
71
Data Center Layer:
Module – 5 Smart City IoT Architecture:
Service Layer:
Ultimately, the true value of ICT connectivity comes from the services that the
measured data can provide to different users operating within a city.
Smart city applications can provide value to and visibility for a variety of user types,
including city operators, citizens, and law enforcement.
The collected data should be visualized according to the specific needs of each
consumer of that data and the particular user experience requirements and
individual use cases.
Module – 5 Smart City Security Architecture
Smart City Security Architecture:
A serious concern of most smart cities and their citizens is data security.
Vast quantities of sensitive information are being shared at all times in a layered, real-
time architecture, and cities have a duty to protect their citizens’ data from
unauthorized access, collection, and tampering.
In general, citizens feel better about data security when the city itself, and not a
private entity, owns public or city-relevant data.
It is up to the city and the officials who run it to determine how to utilize this data.
Module – 5 Smart City Security Architecture
Smart City Security Architecture:
A security architecture for smart cities must utilize security protocols to fortify each
layer of the architecture and protect city data.
Security protocols should authenticate the various components and protect data
transport throughout.
Module – 5 Smart City Security Architecture
Smart City Security Architecture:
Dr. Syed Mustafa, HKBKCE.
Module – 5 Smart City Security Architecture
Smart City Security Architecture:
Starting from the street level, sensors should have their own security protocols.
This additional processing may slow the deployment but ensures the security of the
exchanges.
Another consideration may be the type of data that the sensor is able to collect and
process. For example, a roadside car counter may include a Bluetooth sensor that
uniquely identifies each driver or pedestrian
Module – 5 Smart City Security Architecture
Smart City Security Architecture:
Dr. Syed Mustafa, HKBKCE.