0% found this document useful (0 votes)
33 views44 pages

Unit 2 IOT

The document provides an overview of microcontrollers and sensors, focusing on their definitions, types, and interfacing with Arduino. It details various sensors such as gas, obstacle, ultrasonic, LDR, and heartbeat sensors, including their working principles and code examples for Arduino integration. Additionally, it explains key functions in the Arduino IDE used for sensor data processing and communication.

Uploaded by

yashvispatel.20
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views44 pages

Unit 2 IOT

The document provides an overview of microcontrollers and sensors, focusing on their definitions, types, and interfacing with Arduino. It details various sensors such as gas, obstacle, ultrasonic, LDR, and heartbeat sensors, including their working principles and code examples for Arduino integration. Additionally, it explains key functions in the Arduino IDE used for sensor data processing and communication.

Uploaded by

yashvispatel.20
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 44

Unit-2

Sensors, Microcontrollers
and their
Interfacing
Overview of Microcontrollers
• Microcontroller is a digital device consisting of CPU,
peripheral I/Os, memories, interrupts, etc. in a single chip
or IC.
• Microcontroller is a compact integrated circuit designed for a
specific operation in an embedded system.
• TheAtmel
examples
AVR of various
Microchip – microcontrollers
Intel 8051 are given as:
PIC
AtMega8 PIC18F452 AT89C51
AtMega328P PIC16F877 AT89S52
AtMega16 PIC16F676 AT89c2051
AtMega2560 PIC16F72 P89V51
Introduction to Arduino
USB Digital Pins
Socket Uno
• Atmega328p Microcontroller inside
• The operating voltage is 5V which is given
by
• USB socket or
• External power socket
• DC Current for each input/output pin is 40
mA
• Digital input/output pins are 14 to
interface digital input or output devices
• There are 6 Analog i/p pins used for
interfacing analog input devices.
External Power Atmega328p Analog Pins • What is Digital and Analog?
socket
• Memory Components:
• 32KB flash (program) memory
• SRAM is 2 KB
Components in Arduino
6 2 3
Uno
1. Atmega328p Microcontroller: The heart of
the board.
2. On-board LED interfaced with pin 13.
3. Power LED: Indicates the status of
Arduino whether it is powered or not.
4. GND and 5V pins: Used for providing +5V
and ground to other components of
circuits.
5. TX and RX LEDs: These LEDs indicate
communication between Arduino and
computer.
5 4 1
6. Reset button: Use to reset
the ATmega328P microcontroller
Definition of Sensor
• Sensor is a device that detects or measures a physical property
and records, indicates, or otherwise responds to it.
• A sensor is a device that measures physical input from its
environment and converts it into data that can be interpreted
by either a human or a machine.
• Normally, the sensors are input devices and there are two types
of sensors.
• Analog Sensors
• Digital Sensors
List of Sensors
• The list of sensors which is to be covered in the chapter is as
follows:
MQ-02/05 Gas Sensor Obstacle Sensor Ultrasonic Distance Sensor

LDR Sensor Heartbeat Sensor Gyro Sensor

GPS Sensor Color Sensor pH Sensor


MQ-02/05 Gas Sensor
• MQ -02 sensor is used to detect
smoke.
• H2, LPG, CH4 alcohol and smoke
can be detected by MQ-02.
• MQ-05 is not sensitive to
smoke, hence less used in the
application.
• Pinout of MQ-02 sensor module
are
• Vcc – Connected to 5V
• Gnd – Connected to ground
• D0 – Digital output pin
• A0 – Analog output pin
MQ-02/05 Gas Sensor – Working principle
• When any flammable gas passes through the coil of the sensor,
the coil burns and internal resistance decreases.
• This results in an increased voltage across it. Hence we get
variable voltage at A0 pin of MQ-05 gas sensor.
• If gas present -> voltage is high.
• If gas is not present -> voltage is low.

Smoke/Gas MQ-05 Gas Sensor Variable Voltage


MQ-02/05 Gas Sensor – Interfacing with
Arduino
• The interfacing of MQ-02
with Arduino Uno is as
shown in the figure.
• Here, Vcc and Gnd pins of
MQ-02 are connected to
5V and GND of Arduino
board.
• We want to take the input
from a Gas sensor in an
analog format so pin A0 is
connected to one of the
analog pins of Arduino i.e.
A0.
MQ-02/05 Gas Sensor – Code explanation
• The code in Arduino for MQ-02 gas sensor can be written as
following
gas_sensor.ino
1 int gas_level;
2 void setup() { Initialize the serial communication
3 pinMode(A0, INPUT); between Arduino and computer with
4 Serial.begin(9600); baud rate 9600.
5 } Reads the analog value from specified
6 pin and stores it in the mentioned
7 void loop() { variable.
8 gas_level = analogRead(A0); Prints data on the serial port in ASCII
9 Serial.print("Gas Level : "); text given in double quotes.
10 Serial.println(gas_level);
11 delay(500); Prints the data of specified variable on
12 } the serial port and also prints new line
at the end.
Functions in Arduino IDE
• Serial.begin( ): It is used to start serial communication between Arduino
board and other device. Normally, it is connected with computer for
monitoring the data. Serial communication uses pin 0 and 1 also working as
Rx and Tx respectively.
• Syntax : Serial.begin(baud_rate)
• Parameters :
• baud_rate: It defines the speed of data transfer rate between Arduino and other device. It is
compulsory to set this baud rate same at both the side for proper transfer of data.
• Serial.print( ) : Print the data from Arduino to other device.
• Syntax : Serial.print(“text”)
• Parameters :
• The text which is to be printed by Arduino board is written in double quote so as to convert it in its
ASCII values.
• Serial.println( ) : Print the data with newline from Arduino to other device.
• Syntax : Serial.println(“text”)
• Parameters :
• The text which is to be printed by Arduino board is written in double quote so as to convert it in its
ASCII values.
Functions in Arduino IDE (Cont.)
• analogRead( ): The syntax reads analog value from specified pin
and converts it into 1024 levels or in 0 to 1023 range. The
values is stored into specified variable in the code statement.
The value is converted into 1024 levels because Arduino has 10
bit built in A-D converter unit.
• Syntax : analogRead(pin)
• Parameters :
• pin: The Arduino analog pin number.
MQ-02/05 Gas Sensor – Output
Obstacle Sensor
• Obstacle sensor is used for
detection of obstacle.
• It is a digital sensor, hence gives
binary output ‘1’ or ‘0’.
• The range for detection of
obstacle can be changed by
potentiometer given.
• Pinout of obstacle sensor module
are
• Vcc – Connected to 5V
• Gnd – Connected to ground
• Out/D0 – Digital output pin
Obstacle Sensor – Working principle
• IR emitter transmits IR signals and IR receiver receives those
signals from reflection.
• If the obstacle is present then the transmitted signals are
reflected back by obstacle and if they have amplitude greater
then threshold the output signal will be ‘0’.
• If the obstacle is not present then the transmitted signals are
not reflected and the output signal will be ‘1’.

Obstacle in the way Obstacle IR Sensor Digital Output


Obstacle Sensor – Interfacing with Arduino
• The interfacing of obstacle
sensor with Arduino Uno is
as shown in figure.
• Here, Vcc and Gnd pins of
obstacle sensor is
connected to 5V and Gnd
of Arduino board.
• The output of obstacle
sensor is in digital form.
So it is connected to digital
pin 2 of Arduino.
Obstacle Sensor – Code explanation
• The code in Arduino for Obstacle sensor can be written as
obstacle-
following:
detect.ino
1 int obstacle_pres=0;
2 void setup() {
3 pinMode(2, INPUT);
4 pinMode(13, OUTPUT);
5 Serial.begin(9600);
6 }
7
8 void loop() {
Reads the digital data from
9 obstacle_pres = digitalRead(2);
10 if (obstacle_pres == LOW) specified pin and stores it into
11 { given variable.
12
13 Serial.print("Obstacle is present");
14 digitalWrite(13,HIGH);
}
Obstacle Sensor – Code explanation
(Cont.)
obstacle-
detect.ino
13 else
14 {
15 digitalWrite(13,LOW);
16 }
17 delay(1000);
18 }

• digitalRead( ) : Reads digital data from specified pin and stores


it into given variable.
• Syntax : digitalRead(pin)
• Parameters :
• Pin : The Arduino digital pin number.
HC-SR04 Ultrasonic Sound Sensor
• Ultrasonic Sound Sensor is used to
measure the distance of an
object.
• The sensor can only measure the
distance of object. It can not
identify the type of object.
• It is also known as Ultrasonic
distance sensor.
• Pinout of HC-SR04 module are
• Vcc – Connected to 5V
• Gnd – Connected to ground
• Trigger – Generates the transmit
pulse
• Echo – Receives echo from obstacle
HC-SR04 Ultrasonic Sound Sensor –
Working principle
• The emitter transmits ultrasonic sound waves which are
reflected by near by objects.
• The reflected pulse is received by sensor.
• Some mathematical operations are performed to obtain the
distance value.
• The distance value is converted into desired unit.

Ultrasonic waves Mathematical operations Measurement of distance


HC-SR04 Ultrasonic Sound Sensor– Interfacing with Arduino
• The interfacing of HC-SR04
sensor with Arduino Uno is
as shown in figure.
• Here, Vcc and Gnd pins of
HC-SR04 sensor are
connected to 5V and Gnd
of Arduino board.
• The trigger and echo pin is
connected to (any) digital
pins of Arduino board.
• In this case, trigger is
connected to 11 and echo
is connected to 12.
HC-SR04 Ultrasonic Sound Sensor – Code
explanation
• The code in Arduino for HC-SR04 Ultrasonic Sound Sensor can
Distance-
be written as following
measure.ino
1 int trigPin = 11; // Trigger
2 int echoPin = 12; // Echo
3 long duration, cm, inches;
4
5 void setup() {
6 Serial.begin (9600);
7 pinMode(trigPin, OUTPUT);
8 pinMode(echoPin, INPUT);
9 }
10 void loop() {
11 digitalWrite(trigPin, LOW);
Generates the delay of
12 delayMicroseconds(5);
13 digitalWrite(trigPin, HIGH); specified microseconds.
14 delayMicroseconds(10);
15 digitalWrite(trigPin, LOW);
HC-SR04 Ultrasonic Sound Sensor – Code explanation (Cont.)
Distance-
measure.ino Reads a HIGH pulse on
16 pinMode(echoPin, INPUT); specified pin and returns the
17 duration = pulseIn(echoPin, HIGH); value of time in microsecond
18
for transition from LOW to
19 // Convert the time into a distance Distance(m) = Speed (m/s)x
20 cm = (duration/2) / 29.1; HIGH.
Time (s)
21 inches = (duration/2) / 74; But, Time of pulse we receive is
22 Serial.print(inches); in µs and distance we want to
23 Serial.print("in, "); find is in cm.
24 Serial.print(cm);
Distance(cm) = Speed (cm/µs)
25 Serial.print("cm");
26 Serial.println(); x Time (µs)
Speed of sound is 343m/s
27
which is converted into 0.0343
28 delay(250);
29 } cm/µs.
So either we have to multiply
0.0343 or divide 29.1
Functions in Arduino IDE
• delayMicroseconds( ): It pauses the program for amount of time
in microseconds specified as the parameter.
• Syntax : delayMicroseconds(s)
• Parameters :
• s : The number of microseconds to pause.
• pulseIn( ) : Reads a pulse HIGH or LOW from specified pin and
wait for the time to go the pulse from HIGH to LOW or LOW to
HIGH. It returns the time required to transit the pulse in
variable.
• Syntax : pulseIn(pin, value)
• Parameters :
• Pin: The number of the Arduino pin on which you want to read the pulse.
• Value: The type of pulse that you want to read.
HC-SR04 Ultrasonic Sound Sensor –
Output
LDR Sensor
• LDR is known as Light Dependent
Resistor.
• The internal resistance of LDR
changes with respect to light
intensity.
• Normally LDR works with voltage
divider network.
• The LDR is used in the application
where the task is performed with
light intensity as input.
LDR Sensor – Working principle
• The LDR works on principle of Ohm’s law.
• As the light intensity on LDR is higher, the resistance of LDR
decreases.
• The decreased resistance will drop more voltage across LDR
according to Ohm’s Law.
• The presence of light can be identified by the value of voltage
across LDR.

Light Intensity to be measured Output voltage measurement Calculate the intensity


LDR Sensor– Interfacing with Arduino
• The interfacing of LDR sensor with
Arduino Uno is as shown in figure.
• Here, one terminal of 10k resistor is
connected to 5V of Arduino and
second terminal is connected to A0
pin.
• One terminal of LDR is connected to
A0 pin of Arduino and other is
connected to Gnd.
• This creates a voltage divider network
between fixed resistor and LDR.
• The voltage at A0 pin remains near to
5V when LDR is in dark (high
resistance).
• The voltage at A0 pin remains near to
0V when LDR is in Bright light (low
resistance).
LDR Sensor – Code explanation
• The code in Arduino for LDR Sensor can be written as following
Light-intensity-
measure.ino
1 void setup()
2 {
3 pinMode(A0, INPUT);
4 Serial.begin(9600);
5 }
6
7 void loop()
8 {
9 int light_intensity = analogRead(A0);
10 if (light_intensity > 800)
11 {
12 Serial.println(“Darker");
13 }
LDR Sensor – Code explanation (Cont.)
Light-intensity-
measure.ino
16 else if (light_intensity < 500)
17 {
18 Serial.println(“Too Bright");
19 }
20 delay(1000);
21 }
LDR Sensor – Output
Heartbeat Sensor
• Heartbeat sensor is having typical
application in health care domain.
• This is mainly used in wearable
devices to monitor the heart beat /
heart rate of the person.
• The sensor is inexpensive and
generates square waves for each
pulse. The averaging of pulses
gives analog voltage according to
the heartbeat.
• Pinout of heartbeat sensor module
are
• Vcc – Connected to 5V
• Gnd – Connected to ground
Heartbeat Sensor – Working principle
• The sensor senses the heartbeat as per blood circulation in the
body.
• It generates the output pulse signal according to the rate at
which heart beats.
• The output pulses are considered as PWM waves. Hence they
are converted into analog signals.
• This analog signal is converted to digital which gives the output
beat rate.

Heartbeat input Generation of Digital Pulse Calculates the BPM


as output
Heartbeat Sensor – Interfacing with
Arduino
• The interfacing of
Heartbeat sensor with
Arduino Uno is as shown in
the figure.
• Here, Vcc and Gnd pins of
heartbeat sensor are
connected to 5V and GND
of Arduino board.
• We want to take the input
from the sensor in an
analog format so the
signal pin of the sensor is
connected to one of the
analog pins of Arduino i.e.
A0.
Colour Sensor
• Colour sensor is used to detect the RGB
colour coordinates of a particular colour.
• The colour sensor module has TSC3200
IC that converts colour to frequency by
enabling a particular colour diode turn by
turn.
• The colour sensor is mainly used in the
application where the objects are
identified by their colour.
• Pinout of colour sensor module are
• Vcc – Connected to 5V
• Gnd – Connected to ground
• S0, S1 – Used for output frequency scaling
• S2, S3 – Type of photodiode selected
• (OE)’ – Enable for output
• OUT – Output frequency (fo)
Colour Sensor – Working principle
• The sensor works by imparting a bright light on an object and
recording the reflected colour by the object.
• The selected photodiode for colour of red, green and blue
converts the amount of light to current.
• These RGB values are further processed to identify the exact
colour combination.

Input to photodiode Output RGB colour values Calculation of actual


of colour sensor colour of object
GPS Sensor
• GPS sensor is used to get the
location data of the place where
sensor is situated.
• The data from sensor is acquired in
National Marine Electronics
Association (NEMA) format. The
format is used by marine
department for communication.
• There are multiple variants of GPS
sensors available in the market. We
can select based on our
requirements.
• Here, the given sensor is GY-
GPS6MV2 as shown in the image.
GPS Sensor – Working principle
• The sensor is placed in the system whose location is to be
tracked.
• The GPS device communicates with GPS satellite and the
satellite returns its current location in form of latitude and
longitude.
• The sensor transmits the data to the microcontroller in a
predefined format from which we can extract the tracked
location. Latitude
Longitude

GPS device with antenna Returns latitude and longitude Tracked Location
for communication as output
GPS Sensor – Interfacing with Arduino
• The interfacing of GPS
Sensor with Arduino Uno is
as shown in figure.
• Here, Vcc and Gnd pins of
GPS Sensor are connected to
5V and Gnd of Arduino
board.
• As the GPS communicates
with Arduino serially, we
need to connect Tx and Rx
pin of GPS with serial pins of
Arduino.
•But, wethe
Here, wantTx the
and data
Rx pins of GPS are connected with pins 3 and 2
respectively.
received from the GPS sensor
Gyro Sensor
• The Gyro sensor is very useful in
wearable devices.
• It is used to find the position or angle of
rotation of the body.
• It mainly senses
• Rotational motion
• Changes in orientation
• The Gyro sensor communicates with
microcontroller with I2C (Inter-
Integrated Communication).
• I2C is the most sophisticated two-wire
communication protocol.
• It works with the device address and its
respective data frames.
Gyro Sensor (Cont.)
• The pin out of Gyro sensor
MPU6050 are as following.
• Vcc – connected to 5V
• GND – connected to ground
• SCL – Serial Clock Line
• SDA – Serial Data Line
• XDA – Auxiliary Serial Data
• XCL – Auxiliary Serial Clock
• AD0 – This pin can be used to vary
the address incase of multiple
sensors used
• INT – Interrupt pin available for
certain application
MPU-6050 Gyro Sensor – working principle
• The MPU 6050 senses the gravitational force applied to it.
• Place the sensor in device whose inclination is to be measured.
• Obtain the values of x, y and z coordinates.
• Determine the elevation angle by performing mathematical
caluculations
x,y,z : 507 506 617
x,y,z : 507 504 616
x,y,z : 506 505 617
x,y,z : 506 506 618

Sensor placed for x, y, and z coordinates Determination of Angle


finding Inclination
PH Sensor
• The pH sensor is used to detect hydrogen ions concentration of
a liquid.
• pH sensor are mostly used in laboratories to test the acidity of
solution.
• By the use of pH sensor we can identify the pH of a solution and
whether it is acid or base.
pH Sensor – Working principle
• When this sensor is placed in a solution, the smaller ions
penetrate the boundary area of glass and the lager ions remain
in the solution. This creates potential difference.
• The pH meter measures the difference in electrical potential
between the pH electrodes.
• The potential difference generates different analog values for
different liquids.
• By knowing the analog value of standard water, the pH value of
other liquid can be determined.
pH Sensor with Output Voltage Determination of alkalinity
Electrodes of the liquid

You might also like