working with sensors internet of things - ut

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

Upload: others

Post on 07-Nov-2021

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Working with Sensors Internet of Things - ut

Working with Sensors

&

Internet of Things

Mobile Application Development – Lecture 5

Satish Srirama

[email protected]

1

Page 2: Working with Sensors Internet of Things - ut

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 - ut

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 - ut

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 - ut

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 - ut

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 - ut

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 - ut

Motion Sensors - Accelerometer

• Measures the acceleration force 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 - ut

• Measures a device's rate of rotation (angular

velocity)

• 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 - ut

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 - ut

• 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 - ut

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 - ut

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 - ut

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(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 - ut

Main Classes and Interfaces in Sensor

Framework - continued

15

– 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)

• When sensor accuracy change

public void onAccuracyChanged(Sensor sensor, int accuracy) {

// Do something here if sensor accuracy changes

}

• When sensor values changepublic void onSensorChanged(SensorEvent event) {

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

float value1 = event.values[0];

…………….

// Do something with this sensor value.

}

Page 16: Working with Sensors Internet of Things - ut

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);

}

16

Page 17: Working with Sensors Internet of Things - ut

Course Exercise

• Identify which sensors are on the device

17

Page 18: Working with Sensors Internet of Things - ut

Reading accelerometer data

Reading accelerometer data

18

Page 19: Working with Sensors Internet of Things - ut

@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

19

Page 20: Working with Sensors Internet of Things - ut

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 controls20

Page 21: Working with Sensors Internet of Things - ut

3. Select Virtual sensors.

21

Page 22: Working with Sensors Internet of Things - ut

Course Exercise

• Orientation indicator that displays the device

orientation as Left , Middle and Right

22

Page 23: Working with Sensors Internet of Things - ut

Mobile Sensing and Internet of Things

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

Page 24: Working with Sensors Internet of Things - ut

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)

24

Page 25: Working with Sensors Internet of Things - ut

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.”

25

Page 26: Working with Sensors Internet of Things - ut

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.

26

Page 27: Working with Sensors Internet of Things - ut

Why it is so important?

• More connected devices than people

• Cisco believes the market size will be $19

trillion by 2025

27

Page 28: Working with Sensors Internet of Things - ut

Environment Protection

• Great Barrier Reef in Australia

• Buoys equipped with sensors collect

biological, physical, and chemical data to

minimize and prevent

reef damage

28Source : 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 29: Working with Sensors Internet of Things - ut

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.

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

January 26th, 2015 - Libelium

Page 30: Working with Sensors Internet of Things - ut

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

30

Page 31: Working with Sensors Internet of Things - ut

Smart Healthcare

• Medication in The United States

• Smart pill bottles remind patients to take their medication and 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? 31

Page 32: Working with Sensors Internet of Things - ut

Smart health

Dr. M, project KAIST32

Page 33: Working with Sensors Internet of Things - ut

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/33

Page 34: Working with Sensors Internet of Things - ut

Where Mobiles can Fit?

• Mobiles themselves have lot of inbuilt sensors

• Most of the times IoT sensors do not have a sufficient amount of energy and processing power to connect directly to the internet through Wi-Fi or mobile networks

• Especially when the sensors are deployed sparsely, a mobile device can work as a sink/relay to collect the sensor data and upload them to the backend servers

35

Page 35: Working with Sensors Internet of Things - ut

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 next lecture

• ZebraNet, BikeNet , urban sensing, etc.

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

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

Page 36: Working with Sensors Internet of Things - ut

Arduino Sensor kit• Basic prototype board with the Arduino Mega

ADK microcontroller and the sensor shield

Microcontroller

Sensor shield 37

https://www.arduino.cc/

Page 37: Working with Sensors Internet of Things - ut

Reading ambient temperature

Setup

• Mega ADK microcontroller

• Bluetooth module and temperature sensor

• App to communicate with the Arduino

38

Page 38: Working with Sensors Internet of Things - ut

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

40

Page 39: Working with Sensors Internet of Things - ut

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

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

Page 40: Working with Sensors Internet of Things - ut

Home Assignment 2

• An object moves from left to right (and vice-

versa) based on the orientation of the device

43

Page 41: Working with Sensors Internet of Things - ut

• A touch event makes the object to jump over an obstacle

• Submission deadline is 26th October 2017

44