working with sensors internet of things€¦ · types of sensors • hardware-based sensors –...

43
Working with Sensors & Internet of Things Mobile Application Development – Lecture 4 Satish Srirama [email protected] 1

Upload: others

Post on 25-Jun-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Working with Sensors Internet of Things€¦ · Types of sensors • Hardware-based sensors – Physical components built into a handset – Some of the sensors are always hardware-based

Working with Sensors

&

Internet of Things

Mobile Application Development – Lecture 4

Satish Srirama

[email protected]

1

Page 2: Working with Sensors Internet of Things€¦ · Types of sensors • Hardware-based sensors – Physical components built into a handset – Some of the sensors are always hardware-based

Mobile sensing• More and more sensors are being incorporated

into today’s smartphones

• These sensors are enabling new applications

across a wide variety of domains

– Healthcare, social networks, safety, environment,

etc.

Image Source -http://csce.uark.edu/~tingxiny/courses/5013sp14/reading/Lane2010SMP.pdf

2

Page 3: Working with Sensors Internet of Things€¦ · Types of sensors • Hardware-based sensors – Physical components built into a handset – Some of the sensors are always hardware-based

What is a Sensor?

• A sensor is a physical or virtual object that can

sense events or changes in its environment,

and produce corresponding output

• Most of the times sensor output will be an

electrical/optical pulse

3

Page 4: Working with Sensors Internet of Things€¦ · Types of sensors • Hardware-based sensors – Physical components built into a handset – Some of the sensors are always hardware-based

Modern android mobile devices come

with a variety of built-in sensors • MIC

• Camera

• Temperature

• Location (GPS or Network)

• Orientation

• Accelerometer

• Proximity

• Pressure

• Light

Note: not every device has all kinds of sensors

Image Source - http://www.bosch-sensortec.com/en4

Page 5: Working with Sensors Internet of Things€¦ · Types of sensors • Hardware-based sensors – Physical components built into a handset – Some of the sensors are always hardware-based

Categories of sensors

• The Android platform supports three broad

categories of sensors

• Motion sensors

– These sensors measure acceleration forces and

rotational forces along X, Y, Z axes

– Includes accelerometers, gravity sensors,

gyroscopes, rotational vector, step counter, and

step detector sensors

http://developer.android.com/guide/topics/sensors/sensors_overview.html#sensors-intro5

Page 6: Working with Sensors Internet of Things€¦ · Types of sensors • Hardware-based sensors – Physical components built into a handset – Some of the sensors are always hardware-based

Categories of sensors – continued

• Environmental sensors

– Measure various environmental parameters

• Ambient air temperature and pressure

• Illumination

• Humidity

– Includes barometers, photometers, and thermometers, etc.

• Position sensors

– Measure the physical position of a device

– Includes orientation sensors and magnetometers

6

Page 7: Working with Sensors Internet of Things€¦ · Types of sensors • Hardware-based sensors – Physical components built into a handset – Some of the sensors are always hardware-based

Types of sensors

• Hardware-based sensors– Physical components built into a handset

– Some of the sensors are always hardware-based• E.g. Accelerometer, gyroscope, temperature, light, magnetometer

etc.

• Software-based sensors– They are not physical devices, although they mimic

hardware-based sensors

– Derive their data from one or more of the hardware-based sensors

– Also called virtual sensors or synthetic sensors

– E.g. linear acceleration sensor, gravity sensor etc.

7

https://developer.android.com/guide/topics/sensors/sensors_overview.html

Page 8: Working with Sensors Internet of Things€¦ · Types of sensors • Hardware-based sensors – Physical components built into a handset – Some of the sensors are always hardware-based

Motion Sensors - Accelerometer

• Measures the acceleration force (m/s2) on all three physical axes (X, Y, Z)

• Useful for monitoring device movement

– Tilt, shake, rotation, or swing

Image Source -http://tectrick.org/wp-

content/uploads/2014/10/What-is-an-

Accelerometer-sensor.png

Zompopo: Mobile Calendar Prediction Based on Human Activities Recognition Using the Accelerometer and Cloud

Services: Srirama, Satish Narayana, Huber Flores, and Carlos Paniagua. NGMAST IEEE, 2011 8

Page 9: Working with Sensors Internet of Things€¦ · Types of sensors • Hardware-based sensors – Physical components built into a handset – Some of the sensors are always hardware-based

• Measures a device's rate of rotation - angular

velocity (rad/s)

• When the device is not rotating, the sensor

values will be zero

Image Source -http://www.embedds.com/connecting-gy521-gyroscope-module-to-arduino/

Motion Sensors - Gyroscope

9

Page 10: Working with Sensors Internet of Things€¦ · Types of sensors • Hardware-based sensors – Physical components built into a handset – Some of the sensors are always hardware-based

Environmental Sensors

• Android provides four hardware-based

sensors to monitor

– Relative ambient humidity

– Illuminance

– Ambient pressure

– Ambient temperature

10

Page 11: Working with Sensors Internet of Things€¦ · Types of sensors • Hardware-based sensors – Physical components built into a handset – Some of the sensors are always hardware-based

• Monitor changes in the earth's magnetic field

on X,Y,Z axes

• With the orientation sensor, you can

determine the position of a device

Image Source - http://gadgetstouse.com/gadget-tech/magnetic-feiled-sensor-necessity-navigation-

android-devices/10620

Position Sensors - Magnetic Field

11

Page 12: Working with Sensors Internet of Things€¦ · Types of sensors • Hardware-based sensors – Physical components built into a handset – Some of the sensors are always hardware-based

Position Sensors - Proximity sensor

• Most proximity sensors are simply light sensors(IR) that will detect "proximity“

• Reduce display power consumption by turning off the LCD backlight

• Disable the touch screen to avoid accidental touch events

12

– E.g. the ear contact with the screen and generating touch events while on a call

Page 13: Working with Sensors Internet of Things€¦ · Types of sensors • Hardware-based sensors – Physical components built into a handset – Some of the sensors are always hardware-based

Sensor Framework

• You can access the raw sensor data by accessing the

Android sensor framework

• Android’s sensors are controlled by external services

• The framework has provided call back to obtain

sensor dataApp SensorManager

Register Callback

Sensor Event

Sensor Event

SensorEventListener call back 13

Page 14: Working with Sensors Internet of Things€¦ · Types of sensors • Hardware-based sensors – Physical components built into a handset – Some of the sensors are always hardware-based

Main Classes and Interfaces in Sensor

Framework• The Android sensor framework contains the following classes and

interfaces– SensorManager

• This class provides various methods for – Accessing and listing sensors

– Registering and unregistering sensor event listeners

SensorManager mSensorManager;

mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);

• ServiceManager provides access to Sensor Manager Service

– Sensor• A class representing a sensor

• Use this to create an instance of a specific sensor

Sensor mAccelerometer;

mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);

14

Page 15: Working with Sensors Internet of Things€¦ · Types of sensors • Hardware-based sensors – Physical components built into a handset – Some of the sensors are always hardware-based

Main Classes and Interfaces in Sensor

Framework - continued

• SensorEvent

– The system uses this class to create a sensor event object

– holds information such as the sensor's type, raw sensor data etc. of a sensory event

• SensorEventListener

– Provides two callback methods that receive notifications (sensor events)

• onAccuracyChanged ()

• onSensorChanged()

15

Page 16: Working with Sensors Internet of Things€¦ · Types of sensors • Hardware-based sensors – Physical components built into a handset – Some of the sensors are always hardware-based

SensorEventListener

• When sensor accuracy changes– System invokes the onAccuracyChanged() method

– Accuracy is represented by one of four status constants• SENSOR_STATUS_ACCURACY_LOW, SENSOR_STATUS_ACCURACY_MEDIUM,

SENSOR_STATUS_ACCURACY_HIGH, or SENSOR_STATUS_UNRELIABLE

public void onAccuracyChanged(Sensor sensor, int accuracy) {

// Do something here if sensor accuracy changes

}

• When sensor values change– system invokes the onSensorChanged() method

public void onSensorChanged(SensorEvent event) {

// Many sensors return 3 values, one for each axis.

float value1 = event.values[0];

…………….

// Do something with this sensor value.

}

16

Page 17: Working with Sensors Internet of Things€¦ · Types of sensors • Hardware-based sensors – Physical components built into a handset – Some of the sensors are always hardware-based

Some good practices

• Important : Make sure to disable any sensor when you don’t use or when the sensor activity pauses

protected void onPause() {

super.onPause();

mSensorManager.unregisterListener(this);

}

– The system will not disable sensors when the screen turns off

– That leads to the battery drain in a few hours

• You can register sensor listener when the activity is resumed

protected void onResume() {

super.onResume();

mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_NORMAL);

}

17

Page 18: Working with Sensors Internet of Things€¦ · Types of sensors • Hardware-based sensors – Physical components built into a handset – Some of the sensors are always hardware-based

Handling different sensor

configurations• Android does not specify a standard sensor configuration for

devices– Device manufacturers can incorporate any sensor configuration

• Two options for ensuring that a given sensor is present on a device– Detect sensors at runtime and enable or disable application features

as appropriateif (mSensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE) != null){

// Success! There's a pressure sensor.

} else {

// Failure! No pressure sensor.

}

– Use Google Play filters to target devices with specific sensor configurations<uses-feature android:name="android.hardware.sensor.accelerometer"

android:required="true" />

• Putting the above element in Manifest file ensures users will see your application on Google Play only if their device has an accelerometer

18

Page 19: Working with Sensors Internet of Things€¦ · Types of sensors • Hardware-based sensors – Physical components built into a handset – Some of the sensors are always hardware-based

Course Exercise - task 1

• Identify the sensors on your device

19

Page 20: Working with Sensors Internet of Things€¦ · Types of sensors • Hardware-based sensors – Physical components built into a handset – Some of the sensors are always hardware-based

Reading accelerometer data

Reading accelerometer data

20

Page 21: Working with Sensors Internet of Things€¦ · Types of sensors • Hardware-based sensors – Physical components built into a handset – Some of the sensors are always hardware-based

@Override

public final void onSensorChanged(SensorEvent event) {

float x = event.values[0];

float y= event.values[1];

float z = event.values[2];

tv1.setText( "X : " +x+" Y : "+y+" Z : "+z);

}

@Override

protected void onResume() {

super.onResume();

mSensorManager.registerListener(this, mAcc,

SensorManager.SENSOR_DELAY_NORMAL);

}

@Override

protected void onPause() {

super.onPause();

mSensorManager.unregisterListener(this);

}

}

Reading accelerometer data -

continued

21

Page 22: Working with Sensors Internet of Things€¦ · Types of sensors • Hardware-based sensors – Physical components built into a handset – Some of the sensors are always hardware-based

Test with the Android Emulator

• The Android Emulator includes a set of virtual sensor controls that allow you to test sensors

• Supports accelerometer, ambient temperature, magnetometer, proximity, light, and more.

1. Start the Android Emulator

2. Select Extended controls22

Page 23: Working with Sensors Internet of Things€¦ · Types of sensors • Hardware-based sensors – Physical components built into a handset – Some of the sensors are always hardware-based

3. Select Virtual sensors.

23

Page 24: Working with Sensors Internet of Things€¦ · Types of sensors • Hardware-based sensors – Physical components built into a handset – Some of the sensors are always hardware-based

Course Exercise – task 2

• Orientation indicator that displays the device

orientation as Left , Middle and Right

24

Page 25: Working with Sensors Internet of Things€¦ · Types of sensors • Hardware-based sensors – Physical components built into a handset – Some of the sensors are always hardware-based

Mobile Sensing and Internet of Things

http://iotworldnews.com/2014/10/qualcomm-snaps-up-bluetooth-pioneer-csr-to-capitalise-on-iot/25

Page 26: Working with Sensors Internet of Things€¦ · Types of sensors • Hardware-based sensors – Physical components built into a handset – Some of the sensors are always hardware-based

Internet of Things (IoT)

• International Telecommunication Union

defined IoT as

“A global infrastructure for the information

society enabling advanced services by

interconnecting (physical and virtual) things

based on existing and evolving, interoperable

information and communication technologies

”(ITU Internet report-2005)

26

Page 27: Working with Sensors Internet of Things€¦ · Types of sensors • Hardware-based sensors – Physical components built into a handset – Some of the sensors are always hardware-based

IoT - continued

• European Research Cluster on the Internet of

Things defined IoT as:

“The Internet of Things allows people and

things to be connected Anytime, Anyplace, with

Anything and Anyone, ideally using Any

path/network and Any service.”

27

Page 28: Working with Sensors Internet of Things€¦ · Types of sensors • Hardware-based sensors – Physical components built into a handset – Some of the sensors are always hardware-based

What is a thing?

• Can be a person with a heart monitor implant

• A farm animal with a biochip transponder

• An automobile that has built-in sensors

• Other natural or man-made objects

• With a unique identifier and the ability to communicate over the internet, without requiring human interaction.

28

Page 29: Working with Sensors Internet of Things€¦ · Types of sensors • Hardware-based sensors – Physical components built into a handset – Some of the sensors are always hardware-based

Why it is so important?

• More connected devices than people

• Cisco believes the market size will be $19

trillion by 2025

29

Page 30: Working with Sensors Internet of Things€¦ · Types of sensors • Hardware-based sensors – Physical components built into a handset – Some of the sensors are always hardware-based

Environment Protection

• Great Barrier Reef in

Australia

• Buoys equipped with

sensors

– collect biological,

physical, and

chemical data

– to minimize and

prevent reef damage

30Source : Kip Compton, VP Internet of Things (IoT) Systems and Software Group The Internet of Things: What Does it Take to Make the Internet of Everything

Real?

Page 31: Working with Sensors Internet of Things€¦ · Types of sensors • Hardware-based sensors – Physical components built into a handset – Some of the sensors are always hardware-based

Forest Fire & Flood Prevention

Cities in La Garrotxa spain, 35

sensor nodes power three main

application configurations,

measuring parameters for forest

fire prevention, river flood

monitoring, and ambient control,

such as air quality and greenhouse

gases.

31Urban Resilience in the Smart City: River Flood and Forest Fire Early Detection

January 26th, 2015 - Libelium

Page 32: Working with Sensors Internet of Things€¦ · Types of sensors • Hardware-based sensors – Physical components built into a handset – Some of the sensors are always hardware-based

Smart Home Scenario

Sensing as a Service Model for Smart Cities Supported by Internet of Things”, Charith Perera1, Arkady Zaslavsky, Peter Christen,

Dimitrios Georgakopoulos, TRANSACTIONS ON EMERGING TELECOMMUNICATIONS TECHNOLOGIES Trans. Emerging Tel. Tech. 2014

32

Page 33: Working with Sensors Internet of Things€¦ · Types of sensors • Hardware-based sensors – Physical components built into a handset – Some of the sensors are always hardware-based

Smart Healthcare

• Medication in The

United States

• Smart pill bottles

– remind patients to

take their

medication

– records that the

patient has taken

the correct dosage

Source : Kip Compton, VP Internet of Things (IoT) Systems and Software Group The Internet of Things: What Does it Take to Make the Internet of Everything

Real? 33

Page 34: Working with Sensors Internet of Things€¦ · Types of sensors • Hardware-based sensors – Physical components built into a handset – Some of the sensors are always hardware-based

Smart health

Dr. M, project KAIST34

Page 35: Working with Sensors Internet of Things€¦ · Types of sensors • Hardware-based sensors – Physical components built into a handset – Some of the sensors are always hardware-based

Smart Agriculture• Red Tecnoparque Colombia has deployed a wireless sensors

network technology to monitor plantain crops in Lembo area, in Santa Rosa de Cabal region

• Plantain crops has been monitored with different sensors as:– Digital Humidity & Temperature

– Soil moisture

– Soil temperature

– Trunk diameter

– Fruit diameter

– Pluviometer

– Solar radiation

• Some of the benefits :– Improving environmental and

agricultural sustainability

– Organic waste management

– Crops traceability etc.

Source : http://www.libelium.com/improving-banana-crops-production-and-agricultural-sustainability-in-colombia-using-sensor-networks/35

Page 36: Working with Sensors Internet of Things€¦ · Types of sensors • Hardware-based sensors – Physical components built into a handset – Some of the sensors are always hardware-based

Where Mobiles can Fit?

• Mobiles themselves have lot of inbuilt sensors

• IoT sensors/things do not have a sufficient amount of energy and processing power

– to connect directly to the internet through Wi-Fi or mobile networks

• Mobile device can work as a sink/relay

– to collect the sensor data and upload them to the backend servers

– Especially, when the sensors are deployed sparsely

37

Page 37: Working with Sensors Internet of Things€¦ · Types of sensors • Hardware-based sensors – Physical components built into a handset – Some of the sensors are always hardware-based

Mobile Sensing with Non-integrated

sensors• Mobile phones can collect data from external

sensors and upload them to the backend

servers or provide data directly to the end users

(Mobile Host) - More on lecture 6

• ZebraNet, BikeNet , urban sensing, etc.

http://www.cs.ubc.ca/~krasic/cpsc538a/summaries/29/ZebraNet.htm

http://sensorlab.cs.dartmouth.edu/news.html38

Page 38: Working with Sensors Internet of Things€¦ · Types of sensors • Hardware-based sensors – Physical components built into a handset – Some of the sensors are always hardware-based

Arduino Sensor kit• Basic prototype board with the Arduino Mega

ADK microcontroller and the sensor shield

Microcontroller

Sensor shield 39

https://www.arduino.cc/

Page 39: Working with Sensors Internet of Things€¦ · Types of sensors • Hardware-based sensors – Physical components built into a handset – Some of the sensors are always hardware-based

Reading ambient temperature

Setup

• Mega ADK microcontroller

• Bluetooth module and temperature sensor

• App to communicate with the Arduino

40

Page 40: Working with Sensors Internet of Things€¦ · Types of sensors • Hardware-based sensors – Physical components built into a handset – Some of the sensors are always hardware-based

How does it work?

– Temperature sensor generates an analog signal

according to the temperature variance

– Microcontroller do the A/D conversion and

forward data to the Bluetooth module

42

Page 41: Working with Sensors Internet of Things€¦ · Types of sensors • Hardware-based sensors – Physical components built into a handset – Some of the sensors are always hardware-based

Read data on Mobile

• Bluetooth module transmits data to the Android

device over the established connection

• The Android app reads data over the established BLE

connection, processed and present to the end user

43https://github.com/RedBearLab/Android

Page 42: Working with Sensors Internet of Things€¦ · Types of sensors • Hardware-based sensors – Physical components built into a handset – Some of the sensors are always hardware-based

Next lecture

• Note: Next week (5th October 2018) no lecture

– ICS Day

– Visit Mobile & Cloud Lab (Ulikooli 17 - 321)

• (12.10) Location based services for mobiles

45

Page 43: Working with Sensors Internet of Things€¦ · Types of sensors • Hardware-based sensors – Physical components built into a handset – Some of the sensors are always hardware-based

References

• Sensors overview https://developer.android.com/guide/topics/sensors/

• S. N. Srirama: Mobile Web and Cloud Services Enabling Internet of Things, Special Issue ICAC 2016 of CSIT, CSI Transactions on ICT, ISSN: 2277-9078, 5(1):109-117, 2017. Springer.

• Gubbi, J., Buyya, R., Marusic, S., & Palaniswami, M. (2013). Internet of Things (IoT): A vision, architectural elements, and future directions. Future generation computer systems, 29(7), 1645-1660.

• Arduino https://www.arduino.cc/

46