Uploaded by 刘祐铭

Revision Lecture 1

advertisement
IoT & Smart Building
Technology
Class Test 1 – Revision Lecture
Lecture 1
Key Learning Points
Smart Nation
To have a smart nation, we need an array of
sensors, which are interconnected via
computer networks
Building up
“Smartness”
Necessary “preconditions” for
change
Areas in which
change is most
beneficial
Actionable units of
change
 Things don’t happen overnight, especially largescale, nationwide stuff.
 Sometimes, a lot of infrastructure have to be in place
before nationwide IT initiatives can happen or be
effective.
Key Enablers
 “Things” that made these possible are called
“enablers”
 Enablers of enablers:
 High rate of computing device ownership
 Highly computer literate population
 High penetration of internet access (via fiber, 3G/4G, WiFi
hotspots)
 The areas that in which “smart nation-building” will
have the most impact on its citizens are the Key
Domains.
Key Domains
 Identifying key domains can help to segregate and
distribute resources needed to achieve targets in these
areas.
 Some examples of Key Domains include





Transport
Home and Environment
Business Productivity
Health and enabled Aging
Public Sector Services
Transport
Home & environment
Business productivity
Health and enabled ageing
ENABLERS
Facilitating smart solutions
Nurturing a culture of experimentation and sustaining innovation
Investment in Research & Development
Living laboratory
Industry and Start-up ecosystem
Cybersecurity and Data Privacy
Building computational capabilities
Public sector services
 Initiatives are actual action on the ground to push
forward specific part of the nationwide agenda of
smart nation.
Initiatives
 Each initiatives will target specific groups within each
key domain.
 Initiatives are the “actionable item” of the overall
“smart nation-building” and makes large, complex
program manageable by executing them in “bitesize”
• Assistive Tech &
Robotics
• HealthHub Portal
• National Steps
Challenge
• Tele-Health
• Contactless
Payment Solution
• FinTech “SandBox”
• Public Service at
Fingertips
• Informed of our
Environment
• Smart Homes
Health
Living
Services
Mobility
• Contactless Fare
Payment
• Data Analytics &
Transport
• Mobility-ondemand
• Self-driving Vehicle
Tech & Research
 Devices connected to the Internet exchanging data
and performing tasks with minimal human
intervention
IoT – Internet
of Things
1. Data generated
How IoT Works
2. Data captured
3. Data analyzed
1.
2.
3.
4.
Current data
Archived data
Trends and pattern matching
Turned into information
4. Done automatically - almost
 Link anybody or anything to anything else, anywhere in the world
at any time
Potential Example
- Connected car
What can IoT
do?
- Analyse engine
parameters and
anticipate failures
- Owner is able to carry
out pre-emptive
maintenance
- Impacts society as the
car will not break down
on the road, causing jams
 Smart Fridge linked to major supermarkets can…
More Potential
IoT
Applications




Pre-empt when the milk runs out, based on your habits
Let you order your milk online before you run out
Tell you which stores are having a discount
Warn you that the milk is going to expire
 You can scan the milk packaging directly via the fridge when
you first put the milk into the fridge
 Or if you order online, the milk’s expiry is automatically
updated to the fridge’s computer upon delivery…
 Activity: What kind of technology does a smart fridge
need to have in order to achieve this?
 Fridge is linked to internet via wired or wireless connection
 Software will need your ID and authorisation for online delivery;
parental control
 Vendors need to offer online delivery to home
Some possible
answers
 Integrated online payment system from fridge to bank to vendor
 Weight/Pressure sensors in milk, bottled/packaged drink
compartment to detect “full/empty level” as well as collect data
for trend analysis
 CPU with AI to analyse and track consumption patterns
 “X-code” scanner for milk packaging; Businesses need to include
expire date in “X-code” as industry practice
Issues in Availability
Where we are
right now
Issues in Security
Where we are
right now
Issues in Data Privacy
Where we are
right now
-
Strava keeps track of >3 trillion
GPS data points and aggregates
them on their site
-
This included military personnel in
secret army bases, if they use the
“default privacy settings”
-
The data is publicly available for
everyone to see
Lecture 2
 Identify various electronics components and symbols
Learning
Objectives
 Draw basic electronic circuit diagram
 Layout basic electronics circuit on a breadboard
 Control electronic circuit operation with an Arduino
 Electricity will always flow from higher to lower
potential (voltage)
 The voltage/potential drop across a component is can
be found by applying the basic formula,
V= IR
Electronics
101.1
where V = Voltage, I = current (ampere or A),
and R = resistance (ohms or Ω)
 This is also known as Ohm’s Law
 The GND or common is usually of lower potential as
compared to the power source (i.e. battery, USB port)
 In a series circuit, voltage is distributed, current is
shared
• Resistors have no polarity
• Resistors comes in a few
standard values, like
dollar denominations
Resistors
• Resistors are thus colour
coded so we can tell their
resistance value
• LEDs gives out light when
enough electricity passes thru it
in the right direction
LED – Light
Emitting Diode
 Different coloured LEDs are
made from different
semiconductor compound and
require slightly different voltages
(e.g. red uses Gallium(III) phosphide,
while blue uses Zinc selenide)
• Typical voltage for LEDs
 Red, orange, yellow: 1.9 to 2.1 V
 Green and blue: 3.0 to 3.4 V
 Violet, pink, purple, white: 2.9 to
4.2 V
 Top and bottom rows are horizontally connected, and are
often called the power rails as they are used to carry power
to all the components on the board
Breadboard
Layout
 The middle columns are vertically connected, and are where
your sensors and other components go
Parts of note
• USB Port
• GPIO (General Purpose Input Output) Pins
• Digital pins (top) can take digital input only (on/off)
• Selected digital pins can produce analog output (those indicated "~")
• Analog input pins (bottom) can take in and decode varying voltages
The Arduino
 A circuit diagram shows how electronics components
are connected in a simplified pictorial form
 There are standard symbols used in a circuit diagram
Circuit
Symbols and
Diagrams
 A circuit diagram can always be translated onto a
breadboard, but the actual wiring maybe more
complicated than the diagram
 Circuit diagrams are also called schematics
My First Circuit
Diagram
 A button switch is a common electronic component used to
control electricity flow manually and may be used to
activate or deactivate certain function by simply pressing
the button to “close” the circuit.
The button
switch
Pin 2
5V
The button
switch
 Connecting the
pushbutton for
the Arduino to
read is a little
different from
before.
 Build the
following circuit
– We will
explain each
part in greater
detail later.
10 kΩ
GND
29
The button
switch
30
The resistor pulls the reading down to ground when it
is disconnected
The button
switch
If a pin is not pulled, it gives undefined, noisy results –
This is known as floating
The resistor prevents shorts, and allows the 5V to safely
"override" it
31
Lecture 3
Learning
Objectives
 Describe the various parts of an Arduino System
 Describe the program structure of an Arduino Sketch
 Read and Modify sample Arduino Sketch
• The “brain” of the Arduino board is a
small, low power computer processor,
called a microcontroller
The Arduino –
Microcontroller
• The one on the Mega board is a
ATmega2560 microcontroller, running
at 16MHz.
• Pins on the Arduino board are
physically connected to “pins” on the
microcontroller
 The pins are used for collecting
information from the real world (input)
and controlling “devices” (output)
The Arduino
Family
• A sketch is the name that Arduino uses for a program/code.
Arduino
Sketch
• It's also the unit of code that is uploaded to the Arduino’s EEPROM
(memory) which is then run on the microcontroller
• EEPROM – Electrically Erasable Programmable Read Only
Memory
 Meaning once uploaded, even if you turn off the power, the code will
remain in the memory (ROM), akin to a harddisk.
 Compared to RAM (Random Access Memory) on PCs, Laptops,
Consoles that will lose its content without power.
An Arduino Sketch will always have the 2 default functions below:
 Setup () – used to initialise pins and connected device
state
Sketch
Structure
 This function will be run exactly once and only once
 It will always run when the Arduino board is first powered on
 As long as the Arduino board is not powered down, it will not run
again
 It will always run before loop()
 Loop() – runs the main bulk of the program logic,
inputs/outputs
 Always runs after setup() has completed
 Will keep running forever unless code stops the process or Arduino is
powered down
 Arduino programming is largely involved with working
with the GPIO pins
 Pins can be used for input or output
common
arduino
operations
 Output: Arduino sends information into the real world
 Input: Arduino takes information in from the real world
 Pins can exchange analog or digital information
 Digital: Information only representing two stages
(on/off, true/false)
 Written as HIGH or LOW
 Analog: Information represents a range of values (e.g.
0 – 255; 0 – 1023)
38
 Within the setup() function, we need to declare
which pins are to be used as inputs and outputs. If we
omit this step, the pins may not behave correctly!
common
arduino
commands
 pinMode(pinNum, mode);
 E.g. pinMode(13, OUTPUT);
 Sets Pin 13 as an output pin
 E.g. pinMode(2, INPUT);
 Sets Pin 2 as an input pin
39
 To switch a pin on or off, use the digitalWrite() function
common
arduino
commands
digitalWrite(pinNum, value);
 On the Arduino, Pin 13 is connected to an on-board LED. To switch
it on, we could say:
digitalWrite(13, HIGH);
40
 Write code to make your in-built LED blink
activity:
blinking LED
 To help you, use the delay function, which makes your
program pause for x milliseconds
delay(x);
41
 To read to see if a pin is receiving power, we use digitalRead(). The
value is returned, so store it in a variable for further processing.
common
arduino
commands
 int reading = digitalRead(pinNum);
 In our previous example, you can check the state of the
pushbutton by reading pin 2.
 int reading = digitalRead(2);
42
if (pinFiveInput < 500)
{
// do Thing A
}
Conditional
Statement
Example
else if (pinFiveInput >= 1000)
{
// do Thing B
}
else
{
// do Thing C
}
 So far, we have been working in the digital domain – Where values
are only HIGH or LOW.
 If we want a range of values (e.g. To dim an LED), we have to use
analog control.
analog output
 Analog output is only available on pins marked "~" (ie. Pins 3, 5, 6,
9, 10, 11)
 To produce analog output, write:
analogWrite(pinNum, amount)
 Where amount is a value ranging from 0 to 255.
44
 Certain controls also provide analog input
 Use the A0 to A7 pins to read these analog values
analog input
 Use the analogRead() function:
 int reading = analogRead(pinNum);
45
 The potentiometer has three pins
 The two outer pins are connected to two ends of a resistive wire
 The middle pin, called the wiper, makes contact with the resistive wire,
and can be rotated
 Thus, we form a variable resistor between the wiper and either of the
output pins
potentiometer
 We can also form a potential divider
by connecting the circuit in the manner
shown
 The wiper will give a varying voltage
when it is rotated
GND
A0
5V
46
Lecture 4
 Also known as a photo resistor or LDR (light
dependent resistor)
 Resistance will vary with amount of light falling
on the light-sensitive element
 Common application:
Light Sensor
 Mobile phone screen brightness control
 Turn on the headlight on a car when it is dark
Light Sensing module
Light Sensor
Setup –
Potential
Divider
Serial
Communication
 Arduino communicates with many sensors modules via serial
communication
 Serial communication sends data one at a time thru a single
channel of communication, compared to parallel with sends
multiple
 The Serial Monitor is a separate pop-up window that acts as a
separate terminal that communicates by receiving and sending
Serial Data.
Serial Port
Setup and
Initialisation
void setup(){
Serial.begin(9600);
}
void loop(){
if (Serial.available() > 0){
//… do something
}
}
 The Serial Monitor is a separate pop-up window that acts as a
separate terminal that communicates by receiving and sending
Serial Data.
Serial Port
Reading and
Writing
int data;
void loop(){
if (Serial.available() > 0){
data = Serial.read();
Serial.println(“Data Received:”);
Serial.print(data);
}
}
 Sometimes you code did not work as expected and the Arduino
complier does not complain about it because it is not a syntax
error
Using Serial
Monitor for
debugging
 One of the ways to check and test for logic error is to use the Serial
Monitor
 Initialise serial communication even if your program does not need
it, but using Serial.begin()
 The, at strategic places in your code, insert a serial.print(“xxx”)
statement to show the progress of your code and/or values of
certain variables at that point in the execution
 The Serial Monitor is a separate pop-up window that acts as a
separate terminal that communicates by receiving and sending
Serial Data.
int LoopCounter;
Serial Monitor
for Debugging
Example
//…other code
Serial.println(“Beginning of loop”);
Serial.print(“LoopCounter value = ”);
Serial.println(LoopCounter);
//…other code
Serial.println(“Reading temperature sensor”);
LoopCounter++;
//…other code
 Sometimes, the output is not the final result we want, but it allows
us to know that we are going things right or the process is
functioning as intended.
Output as
Feedback
 This kind of output is what we call Feedback, and is very helpful
for troubleshooting during development. It is also useful in both
the physical and digital world
 Example of output as feedback
 Movement of the timer knob on a heating oven
 Lift floor display
 Hourglass icon/cursor in Windows
 Sensors are electronic devices that measure physical phenomena,
like intensity of light (light sensor/meter), weight and pressure
(physical and air), sound (microphone/sound meter), temperature
(thermometer), orientation (gyroscope), motion (accelerometer),
etc.
Sensors Input
and Output
 Therefore, Sensors are Input devices
 Actuators are electro-mechanical that generate motion, like servo
motor, dc motor, etc. Therefore, Actuators are Output devices
 Light (LED), and Sound (speakers) are other common output
medium
 If we do not need to output something physically, we just output
to a computer display or just save the data to the harddisk
IR Distance Sensor
PIR Sensor module
Presence and
Distance
Sensors
Ultrasonic
Presence sensor
LIDAR
IR Presence sensor
 Sensitive to the IR (Infra Red) wavelength (heat) radiated by the
human body at ~10um, roughly 37C
 Has two sensing elements. When one sense a difference in heat
compared to the other as a warm body passes thru, it will register a
“hit”.
PIR (Body
Heat) Sensor
Body Heat Sensor module
 Emits a chirp of sound and measures
how long it takes to "bounce" off a
surface
Ultrasonic
Sensor
 We can use v = d ÷ t to calculate the distance, since we know:
 v (speed) is the speed of sound
 t (time) is what we have measured
 d is the total distance travelled by the chirp of sound
 Note that we have to divide d by two because the sound makes a
round trip forward and back
void setup() {
pinMode(2, OUTPUT); // Trigger
pinMode(3, INPUT); // Echo
}
Ultrasonic
Sensor Code
void loop() {
// Give the TRIG pin a pulse to activate the sensor
digitalWrite(2, LOW);
delayMicroseconds(2);
digitalWrite(2, HIGH);
delayMicroseconds(10);
digitalWrite(2, LOW);
// Measure the length of time in which the ECHO pin is HIGH
long duration = pulseIn(3, HIGH);
float distance = (duration*0.034) / 2.0;
Serial.print("Distance: ");
Serial.println(distance);
delay(500);
}
Position and
Orientation
Sensors
Potentiometers
Tilt Sensor
Digital compass
or gyroscope
Accelerometer
Flame Sensor
Temperature
Sensor
 A thermistor is a device that changes its resistance with
temperature. These sensors are easy to interface, but they
respond slowly to changes.
 Flame sensors are tuned to detect open flames such as lighters
and candles
 These sensors use semiconductor technology to detect changes in
temperature
TMP36
 This is calibrated to 10mV per °C with a 500mV offset, ie.
 Temperature (°C) = (Voltage Detected – 0.5) × 100
 Voltage detected = (Analog Reading × 5) ÷ 1024
void setup() {
pinMode(A0, INPUT);
}
Temperature
Sensor Code
void loop() {
int reading = analogRead(A0);
float voltage = (reading * 0.5) / 1024.0;
float temperature = (voltage – 0.5) * 100;
}
 Humiture is a combination of temperature and
humidity and is a better gauge of relative
human comfort compared with either value
alone.
Humiture
Sensor
 At low humidity, even if the temperature is
higher, the human body is less likely to perspire
and thus remains more comfortable
 Conversely, at high humidity, one can feel
“sticky” on the skin even when temperature is
moderate
Humiture Sensor module
 Can sense toxic gas from burning and smoke due to chemically reactive
elements of the sensor
 More sensitive at higher temperature, as high as 200-300C
 Can adjust built-in potentiometer (variable resistor) to define sensitivity
threshold
Gas Sensor
Gas Sensor module
 A bend (flex) sensor is a thin strip of plastic that changes its resistance
as it is bent. A force-sensitive resistor (FSR or force sensor) changes its
resistance depending on the magnitude of force applied to its surface.
FSRs are designed for small amounts of force like the pressure from a
finger, and they are available in different shapes including long strips
and circular pads.
Touch and
Force Sensors
 Loadcells are sensors that measure high pressure or weight from
kilograms to tons. A flex sensor cannot be used for heavy weight
because it will break under these conditions
Flex sensor on the left,
load cells on the right
 An integrated sensor that measures the air pressure and
temperature, and uses these two metrics to provide an estimated
altitude value
 Requires the Adafruit sensor library (provided in the kit’s download)
Digital
Barometer
Digital Barometer module
Sound Sensor
 A microphone is the simplest and most common device used to
detect and measure sound. Sudden changes in volume are the
easiest sound elements to read, but processing the sound wave
with software (or special hardware) makes it possible to detect
specific frequencies or rhythms. A microphone usually requires
extra components to amplify the signal before it can be read by a
microcontroller
 Piezo electric film sensors, commonly used in speakers and
microphones, can also be used to detect sound.
There are two kinds of sensor limitations
 Firstly – Noise
 Noise refers to small, random errors that are inherent to sensors
 We can account for noise by averaging values
 Second – Context-Dependent
Sensor
Limitations
 A sensor can only detect what it is designed to detect, and can't give
us additional information about the context of the environment
 For example, the body heat sensor actually just reacts to the specific
range of heat (at roughly 37C), and does not really know if an actual
person has passed by. If we can create an artificial heat source at
around the same temperature, the body heat sensor will still trigger
as if a person has passed by.
 Furthermore, even if it is indeed a “living” body that passed by, it
cannot tell whether it is a human being or an animal.
 All sensors have limitations and constraints, and knowing what
they are will help the designer to make practicable adjustment
that will improve its use
Related documents
Download