You are on page 1of 42

Internet of

Things: Sensing and


Actuator Devices
Lecturer: Ts. Norzalina Othman
Introduction

Components in Device Level:


i. Sensor (Input Device)
ii. Controller/ Processor
iii. Actuator (Output Device)
Sensor
• a sensor is a device that is • Preforms some function of
able to detect changes in an input by sensing or detecting
environment. the changes in the
• all sensors take some characteristics of a system in
physical parameter (thermal, respond to stimuli (i.e:
electric, mechanical, temperature, light, gas,
magnetic, chemical and pressure, sound and etc.)
optical) and turn it into
electrical signals.
Cont.

DHT11/22 – Humidity Sensor Gas Sensor PIR Sensor Water Level Sensor
Function: to sense motion or used to detect Function: to detect the level of substances (i.e: liquid,
Function: to measure the surrounding air, and Function: to detect and identify whether a human has moved in or out of the slurries, granular materials) that can flow
spits out a digital signal on the data pin different types of gasses. sensors range.

Ultrasonic Sensor
Rain Detector Sensor Force Sensing Resistor
Function: to measures the distance of a target object by
emitting ultrasonic sound waves and convert to electrical Function: acts as a force sensing resistor in
Function: to detects the presence of water signal. an electrical circuit
Sensor Classification
Sensor

Passive & Active

Analog & Digital

Scalar &

Vector
Sensor Classification (cont.)
Passive Sensor Active Sensor
• is a device that detects and responds to • is a sensing device that requires an
some type of input from the physical external source of power to operate
environment. • Active sensor is used for sensing
• Passive sensor technologies gather environment conditions and transmitted
target data through the detection of signals. It is an electronic sensing
vibrations, light, radiation, heat or device which requires AC and DC source
other phenomena occurring in the for produce output.
subject's environment. • Example of active sensor – GPS, blood
• Example of passive sensor – motion/PIR pressure sensor
sensor, metal detector sensor, IR
sensor
Sensor Classification (cont.)
Analog Sensor Digital Sensor
• An analog sensor measures continuously • A digital sensor only detects two possible
the variable and detects any proportional status: if it is working at 100% (1) or at
value between 100% and 0%. 0% (0).
• Example: TMP36 Temp Sensor - can • Example: DS18S20 Temp Sensor - only
measure short intervals at high resolution measure if it is working over 50°C
(approximately 0.1°C of variation). (displaying 1) or under 50°C (displaying 0).
• Example: LDR – Light Dependent Resistor, • Example: Motion sensor, Digital
Accelerometer, Sound Sensor, Piezoelectric Accelerometer
sensor,
Sensor Classification (cont.)
Scalar Sensor Vector Sensor
• The sensor which produce output • The sensor which produce output
signal/voltage which is proportional to signal/voltage which is proportional to
magnitude of quantity to be measured magnitude, direction as well as
is known as scalar sensor. orientation of quantity being measured
is known as Vector sensor.
• Temperature of a room is measured
using scalar sensor (i.e. thermometer or • Acceleration of body is measured using
thermocouple) which measures accelerometer which measures
temperature changes irrespective of component of acceleration of body with
sensor orientation. respect to x, y, z coordinate axes.
• Examples: • Examples:
Temperature sensor, Color sensor, Sound sensor, image sensor, velocity
pressure sensor, strain sensor etc. sensor, acceleration sensor etc.
Actuator
• an actuator operates in the • Actuators can be categorized by
reverse direction of a sensor. the energy source they require to
• It takes an electrical input generate motion. Example:
and i. Pneumatic actuators use
turns it into physical action. compressed air to generate
• For instance, an electric motion.
motor, a ii. Hydrolic actuators use
hydraulic system, and a generate
liquid to motion.
pneumatic system are all different iii. Electric actuators use an
types of actuators. external power source, such as
a battery, to generate motion.
iv. Thermal actuators use a heat
source to generate motion.
What is RFID?
Types of RFID Tags
• RFID also known as Radio – Passive Tags Does not have power supply. Used
Frequency Identification
works using electromagnetic to obtain power from incoming
fields that automatically radio waves from the Readers.
recognize and trace tags
that is attached to any Active Tags Have power source in the internal
products. RFID mainly circuit. Uses own power supply to
operated with three
frequency bands varies from send response to the reader.
country to country. There
are LF (Low – Frequency Semi Have power supply in the internal
band), HF (High Frequency Passive Tags circuit but to send response, this
band) and UHF (Ultra High – tags depends on the radio waves
Frequency band)
from Reader.
• RFID technology has been used
in real applications such as
supply chain management in
which RFID tags are attached to
products so that they can be
RFID False conveniently identified by tag
readers.
Authentication • Such RFID applications may
s encounter insecure situations like
duplication of tag IDs, invalid or
counterfeit tags and readers, or
even malicious attacks
Devices Power Management in IoT
• One aspect to consider • Usually, an IoT device uses one
developing
while an IoT project is device or
power management. more sensors to acquire information
• With the rise of the Internet related to the environment.
of Things, the optimization of • The data acquired are used
battery-operated devices is an
the locally or remotely to take
important aspect that can make decisions.
sensors, and each sensor has
huge
a difference.
• Device power management in • specific power consumption.
This information is acquired
• using
Therefore, it is very important
the to
IoT is a challenging task as a device
could always be powered up select sensors carefully in order
and to optimize power management.
could be located everywhere. Often,
IoT devices are located remotely and
they must use a battery to work.
Cont.

An IoT device during its operations can


send and receive data remotely.
Usually, several IoT devices are
connected to an IoT gateway that
collects such information and sends
them to the cloud.
The sending and receiving operation is
one of the most expensive tasks from
the power management point of view.
This operation involves the radio
connection (cellular, Wi-Fi, Bluetooth,
etc.).
Implementing Power Management in IoT

• Since the development of IoT system involved hardware and software part, the easiest
methods on implementing the code in loop() structure.
• For examples, when acquire data from sensor at specific time interval, add the delay()
function in loop() structure by specifying how long the devices should wait before
starting again and repeat the same task.
Implementing Power Management in IoT
• Another methods for power management in IoT system by applying four different modes to “sleep” or save the battery:
i No sleep
. • This is the most inefficient way to use this device.
• The supply always on.
ii. Modem sleep
• This mode is enabled only when the ESP8266 is connected to Wi-Fi.
• In this mode, the ESP8266 turns off the Wi-Fi module between two DTIM Beacon interval.
• The ESP8266 turns on again the Wi-Fi module before the next Beacon.
• Sleep mode is used when it is necessary to keep the processor on.
iii. Light sleep
• ESP8266 suspends the CPU and turns off the clock.
• This mode is more efficient than the previous mode.
• In Light-sleep mode, the ESP8266 should be woken up using a GPIO pin.
iv. Deep-sleep
• In this mode, everything is turned off except the RTC (Real Time Clock), so that the ESP8266 can be turned on periodically.
• This is the most the most efficient mode. The deep-sleep mode can be used in scenarios where the device should send data at specific intervals.
• This is the example of an application that uses sensors.
• The application reads sensor data, sends the values and the goes into a deep-sleep mode.
IoT
Hardware
&
Software
Interfacing
Arduino Uno Pin Diagram
1. Reset Button – This will restart any code that is loaded to the Arduino board

2. AREF – Stands for “Analog Reference” and is used to set an external reference voltage

3. Ground Pin – There are a few ground pins on the Arduino and they all work the same

4. Digital Input/Output – Pins 0-13 can be used for digital input or output

5. PWM – The pins marked with the (~) symbol can simulate analog output

6. USB Connection – Used for powering up your Arduino and uploading sketches

7. TX/RX – Transmit and receive data indication LEDs

8. ATmega Microcontroller – This is the brains and is where the programs are stored

9. Power LED Indicator – This LED lights up anytime the board is plugged in a power
source

10. Voltage Regulator – This controls the amount of voltage going into the Arduino board

11. DC Power Barrel Jack – This is used for powering your Arduino with a power supply

12. 3.3V Pin – This pin supplies 3.3 volts of power to your projects

13. 5V Pin – This pin supplies 5 volts of power to your projects

14. Ground Pins – There are a few ground pins on the Arduino and they all work the same

15. Analog Pins – These pins can read the signal from an analog sensor and convert it to
digital
Basic C Programming Structure in IDE
Arduino code (also called Arduino sketch) includes two
main parts: setup code and loop code.
Setup Code
• Is code in setup() function.
• Executed right after power-up or reset
• Executed only one time.
• Used to initialize variables, pin modes, start using
libraries,
Loop Code
• Is code in loop() function.
• Executed right after setup code.
• Executed repeatedly (infinitely).
• Used to do the main task of application
Basic C Programming Structure in IDE
Apart from setup and loop code, an
Arduino sketch can include some of the
following parts:
• Block comment: usually used to write
some information about the author,
the wiring instruction, the license ...
Arduino will ignore this part.
• Libraries inclusion: is used to include
libraries into the sketch.
• Constant definition: used to define
constant
• Global variables declaration
Arduino - C Datatype
Arduino – C Variable & Constant
Variable – refer to an Constant – refer to an identifier
identifier used to hold a data where the data remain
during execution time. unchangeable during execution
time.

i. Local Variable
• Inside a function or a
block

ii. Global Variable


• Outside of all
functions
Arduino – C Arithmetic
Operator
Arduino – C Comparison Operator
Arduino – C Control Structure
Control Structure

Sequence Selection Repetition/ Loop


Selection Structure
Repetition/ Loop Structure
Arduino – C Logical Operator
Arduino – C Bitwise Operator
Arduino – C Compound Operator
Practical Activity
Simulator -
TinkerCAD
Practical 1 – Digital Output
Schematic Diagram – LED Blinking
//setup I/O pin
void setup()
{
pinMode(12, OUTPUT); //configure pin 12 as output pin
pinMode(11, OUTPUT);
}

void loop()
{
digitalWrite(12, HIGH); //turn ON Led in pin 12
digitalWrite(11, HIGH);
delay(1000); // Wait for 1000 millisecond(s)

digitalWrite(12, LOW);
digitalWrite(11,
LOW);
delay(1000); // Wait
for 1000 millisecond(s)
}
Practical 2 – Digital Output
Prac. Lab – Running LEDs from left to right and
Schematic Diagram – Chasing LEDs
right to left

Component List
Firmware code
int pinsCount=7; // declaring the integer variable pinsCount
int pins[] = {8,9,10,11,12,13}; // declaring the array pins[]

void setup()
{
pinMode(13, OUTPUT);
pinMode(12,
OUTPUT); pinMode(11,
OUTPUT); pinMode(10,
OUTPUT); pinMode(9,
OUTPUT); pinMode(8,
OUTPUT);
}
void loop()
{
for (int i=0; i<pinsCount; i=i+1) // chasing right
{
digitalWrite(pins[i], HIGH); // switching the LED at index i on
delay(500); // stopping the program for 500 milliseconds
digitalWrite(pins[i], LOW); // switching the LED at index i off
}

for (int i=pinsCount-1; i>0; i=i-1) // chasing left (except the outer leds)
{
digitalWrite(pins[i], HIGH); // switching the LED at index i on
delay(500); // stopping the program for 500 milliseconds
digitalWrite(pins[i], LOW); // switching the LED at index i off
}
}
Practical 3 – Digital Input Output
Prac. Lab – Press switch, LEDs on for 5 seconds Schematic Diagram – Digital IO

Component List
Firmware code
void loop()
{

const int switch1 = 2;


currentState=digitalRead(switch1);
const int LED1=10;
if(currentState==HIGH)
const int LED2=9;
{
const int LED3=8; digitalWrite(13, HIGH);
digitalWrite(12, HIGH);
int currentState=LOW;
digitalWrite(11, HIGH);
digitalWrite(LED1, HIGH);
void setup() digitalWrite(LED2,
HIGH);
{ digitalWrite(LED3, HIGH);
pinMode(13, OUTPUT); } delay(5000);

pinMode(12, else
OUTPUT); {
digitalWrite(13, LOW);
pinMode(11, OUTPUT);
digitalWrite(12, LOW);
pinMode(LED1, digitalWrite(11, LOW);
OUTPUT); digitalWrite(LED1, LOW);
pinMode(LED2, OUTPUT); digitalWrite(LED2, LOW);
digitalWrite(LED3,
pinMode(LED3, LOW);
OUTPUT); }
delay(10);
pinMode (switch1,
}
INPUT);
}
Practical 4 – Digital Input Output
Prac. Lab – Press switch, LEDs will blink for 10 times. Set Schematic Diagram – Digital IO
time interval for each operation to 0.5sc.

Component List
Firmware code
//Prac Lab - Digital I/O void loop() else
//Press switch - leds will blink for 10 times { {
digitalWrite(LED1, LOW);
int counter; digitalWrite(LED2,
const int switch1 = 2;
currentState=digitalRead(switch1); //1(5v)-on/0(0V)-off LOW);
const int LED1=13;
digitalWrite(LED3, LOW);
const int LED2=12;
if(currentState==HIGH)//5v received -press switch digitalWrite(LED4,
const int LED3=11;
{ LOW);
const int LED4=10;
for(counter=1; counter<=10; counter++) digitalWrite(LED5, LOW);
const int LED5=9;
{ digitalWrite(LED6,
const int LED6=8; LOW);
digitalWrite(LED1, HIGH);
int currentState; } }
digitalWrite(LED2, HIGH);
digitalWrite(LED3, HIGH); delay(10);
void setup() //configure I/O pin
digitalWrite(LED4,
{ HIGH);
pinMode(switch1, INPUT); digitalWrite(LED5, HIGH);
pinMode(LED1, OUTPUT); //setup digitalWrite(LED6,
pinMode(LED2, HIGH); delay(500);
OUTPUT); digitalWrite(LED1, LOW);
pinMode(LED3, OUTPUT); digitalWrite(LED2, LOW);
pinMode(LED4, digitalWrite(LED3, LOW);
OUTPUT); digitalWrite(LED4, LOW);
} pinMode(LED5, OUTPUT); digitalWrite(LED5, LOW);
pinMode(LED6, digitalWrite(LED6, LOW);
OUTPUT); delay(500);
} }
Practical 5 – Digital Input Output
Prac. Lab Schematic Diagram – Digital IO

Input Output

Switch1 All LEDs blink for 10 times. Set time interval for 0.5s

Switch2 Turn on first 3 LEDs, then follow by another 3 LEDs. Program will
repeat for 5 times. Set time interval for each operation to 0.5s.

Component List
Firmware code
//Prac Lab - Digital I/O void loop() if(currentState2==HIGH)//5v received -press sw
{ {
const int switch1 = 2; for(counter=1; counter<=5; counter++)
const int switch1 = int counter; {
currentState1=digitalRead(switch1); //1(5v)-on/0(0V)-off digitalWrite(LED1, HIGH);
3; const int LED1=13;
digitalWrite(LED2, HIGH);
const int LED2=12;
currentState2=digitalRead(switch2); digitalWrite(LED3, HIGH);
const int LED3=11;
if(currentState1==HIGH)//5v received -press switch digitalWrite(LED4, LOW);
const int LED4=10;
{ digitalWrite(LED5, LOW);
const int LED5=9;
for(counter=1; counter<=10; counter++) digitalWrite(LED6, LOW);
const int LED6=8;
{ delay(500);
int currentState1; digitalWrite(LED1, LOW);
digitalWrite(LED1, HIGH);
int currentState2; digitalWrite(LED2, LOW);
digitalWrite(LED2, HIGH);
digitalWrite(LED3, digitalWrite(LED3, LOW);
void setup() //configure I/O pin HIGH); digitalWrite(LED4, HIGH);
{ digitalWrite(LED4, HIGH); digitalWrite(LED5, HIGH);
pinMode(switch1, INPUT); digitalWrite(LED5, digitalWrite(LED6, HIGH);
pinMode(switch2, HIGH); delay(500);
INPUT);
pinMode(LED1, OUTPUT); //setup digitalWrite(LED6, HIGH); }
pinMode(LED2, delay(500); }
OUTPUT); digitalWrite(LED1, LOW); else
pinMode(LED3, OUTPUT); digitalWrite(LED2, LOW); {
pinMode(LED4, digitalWrite(LED3, LOW); digitalWrite(LED1, LOW);
OUTPUT); digitalWrite(LED4, LOW); digitalWrite(LED2,
} pinMode(LED5, OUTPUT); digitalWrite(LED5, LOW); LOW);
pinMode(LED6, digitalWrite(LED6, LOW); digitalWrite(LED3, LOW);
OUTPUT); } delay(500); digitalWrite(LED4,
} LOW);
digitalWrite(LED5, LOW);

You might also like