SlideShare a Scribd company logo
SENSORS ANDSENSORS AND
ARDUINOARDUINO
SensorSensor
• A sensor is a device that detects and responds to
some type of input from the physical environment.
• The specific input could be light, heat, motion,
moisture, pressure, or any one of a great number of
other environmental phenomena.
• The output is generally a signal that is converted to
human-readable display at the sensor location or
transmitted electronically over a network for
reading or further processing.
Sensors ExampleSensors Example
Sensors we need to learnSensors we need to learn
• PIR sensor--- Detecting Movement
• Ultrasonic Sensor--- Measuring Distance
PIR SENSORPIR SENSOR
• PIR sensors allow you to sense motion, almost always
used to detect whether a human has moved in or
out of the sensors range.
• They are small, inexpensive, low-power, easy to use
and don't wear out.
• For that reason they are commonly found in
appliances and gadgets used in homes or
businesses.
• They are often referred to as PIR, "Passive Infrared",
"Pyroelectric", or "IR motion" sensors.
PIR SensorPIR Sensor
• PIRs are basically made of a pyroelectric sensor
 (which you can see above as the round metal can
with a rectangular crystal in the center), which can
detect levels of infrared radiation.
• Everything emits some low level radiation, and the
hotter something is, the more radiation is emitted. 
• The PIR sensor itself has two slots in it, each slot is made
of a special material that is sensitive to IR. 
• When the sensor is idle, both slots detect the same
amount of IR, the ambient amount radiated from the
room or walls or outdoors.
• When a warm body like a human or animal passes by, it
first intercepts one half of the PIR sensor, which causes
a positive differential change between the two halves.
• When the warm body leaves the sensing area, the
reverse happens, whereby the sensor generates a
negative differential change. These change pulses are
what is detected.
Circuit DiagramCircuit Diagram
• Pin1 -VCC
• Pin 2- Output of PIR sensor connected to 2 pin of
arduino
• Pin 3-Ground
int ledPin = 13; // choose the pin for the LED
int inputPin = 2; // choose the input pin (for PIR sensor)
int pirState = LOW; // we start, assuming no motion detected
int val = 0; // variable for reading the pin status
void setup()
{
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare sensor as input
Serial.begin(9600);
}
void loop()
{
val = digitalRead(inputPin); // read input value
if (val == HIGH)
{ // check if the input is HIGH
digitalWrite(ledPin, HIGH); // turn LED ON
if (pirState == LOW)
{
// we have just turned on
Serial.println("Motion detected!");
// We only want to print on the
output change, not state
pirState = HIGH;
}
}
else
{
digitalWrite(ledPin, LOW); // turn LED OFF
if (pirState == HIGH){ // we have just turned of
Serial.println("Motion ended!"); // We only want to
print on the output change, not state
pirState = LOW;
}
}
}
UltrasonicUltrasonic
SensorSensor
• An Ultrasonic sensor is a device that can measure
the distance to an object by using sound waves.
• It measures distance by sending out a sound wave
at a specific frequency and listening for that sound
wave to bounce back.
• By recording the elapsed time between the sound
wave being generated and the sound wave
bouncing back, it is possible to calculate the
distance between the sonar sensor and the object.
 
• Since it is known that sound travels through air at
about 344 m/s (1129 ft/s), you can take the time for
the sound wave to return and multiply it by 344
meters (or 1129 feet) to find the total round-trip
distance of the sound wave.
• Round-trip means that the sound wave traveled 2
times the distance to the object before it was
detected by the sensor; it includes the 'trip' from the
sonar sensor to the object AND the 'trip' from the
object to the Ultrasonic sensor (after the sound
wave bounced off the object).
• To find the distance to the object, simply divide the
round-trip distance in half.
SENSORS AND BLUETOOTH COMMUNICATION
• The Trig pin will be used to send the signal and
the Echo pin will be used to listen for returning signal
Example- Distance MeasurementExample- Distance Measurement
#define echoPin 7 // Echo Pin
#define trigPin 8 // Trigger Pin
#define LEDPin 13 // Onboard LED
int maximumRange = 200; // Maximum range needed
int minimumRange = 0; // Minimum range needed
long duration, distance; // Duration used to calculate distance
void setup()
{
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(LEDPin, OUTPUT); // Use LED indicator (if required)
}
void loop() /* The following trigPin/echoPin
cycle is used to determine the distance of the nearest
object by bouncing soundwaves off of it. */
{
duration = pulseIn(echoPin, HIGH);
//Calculate the distance (in cm) based on the speed
of sound.
distance = duration/58.2;
Serial.print(Distance);
Dealy(1000);}
Interfacing DCInterfacing DC
Motor WithMotor With
ArduinoArduino
DC MotorDC Motor
• Working principle of a DC motor --A motor is an
electrical machine which converts electrical energy into
mechanical energy.
• The principle of working of a DC motor is that "whenever
a current carrying conductor is placed in a magnetic
field, it experiences a mechanical force".
• A DC motor (Direct Current motor) is the most common
type of motor. DC motors normally have just two leads,
one positive and one negative.
• If you connect these two leads directly to a battery, the
motor will rotate. If you switch the leads, the motor will
rotate in the opposite direction.
• To control the direction of the spin of DC motor,
without changing the way that the leads are
connected, you can use a circuit called an H-
Bridge.
• An H bridge is an electronic circuit that can drive
the motor in both directions.
• H-bridges are used in many different applications,
one of the most common being to control motors in
robots.
• It is called an H-bridge because it uses four
transistors connected in such a way that the
schematic diagram looks like an "H." 
• You can use discrete transistors to make this circuit, but
for this lecture, we will be using the L293d/L298 H-Bridge
IC.
• In L293 all four input- output lines are independent, while
in L298, a half H driver cannot be used independently,
full H driver has to be used.
• Protective Diodes against back EMF are provided
internally in L293D but must be provided externally
in L298.
• The L298 can control the speed and direction of DC
motors and stepper motors and can control two motors
simultaneously.
• Its current rating is 2A for each motor. At these currents,
however, you will need to use heat sinks.
L293D Motor Driver ICL293D Motor Driver IC
SENSORS AND BLUETOOTH COMMUNICATION
Controlling Speed of DCControlling Speed of DC
MotorMotor
• We will connect the Arduino to IN1 (pin 5), IN2 (pin
7), and Enable1 (pin 6) of the L293d IC. Pins 5 and 7
are digital, i.e. ON or OFF inputs, while pin 6 needs a
pulse-width modulated (PWM) signal to control the
motor speed.
const int pwm = 2 ; //initializing pin 2 as pwm
const int in_1 = 8 ;
const int in_2 = 9 ; //For providing logic to L293d
IC to choose the direction of the DC motor
void setup()
{
pinMode(pwm,OUTPUT) ; //we have to set PWM pin as
output
pinMode(in_1,OUTPUT) ; //Logic pins are also set as
output
pinMode(in_2,OUTPUT) ; }
void loop()
{
//For Clock wise motion , in_1 = High , in_2 = Low
digitalWrite(in_1,HIGH) ;
digitalWrite(in_2,LOW) ;
analogWrite(pwm,255) ;
delay(3000) ;
/*setting pwm of the motor to 255 we can change the
speed of rotaion by chaning pwm input but we are only
using arduino so we are using higest value to driver the
motor */
//For brake
digitalWrite(in_1,HIGH) ;
digitalWrite(in_2,HIGH) ;
delay(1000) ; }
//For brake
digitalWrite(in_1,HIGH) ;
digitalWrite(in_2,HIGH) ;
delay(1000) ;
//For Anti Clock-wise motion
- IN_1 = LOW , IN_2 = HIGH
digitalWrite(in_1,LOW) ;
digitalWrite(in_2,HIGH) ;
delay(3000) ;
Bluetooth Technology
IntroductionIntroduction

Bluetooth is a wireless communication technology used for
exchange of data over short distances.

It is found in many devices ranging from mobile phones and
computers.

Bluetooth technology is a combination of both hardware and
software.

It is intended to create a personal area networks (PAN) over
a short range.

It operates in the unlicensed industrial, scientific and medical
(ISM) band at 2.4 to 2.485 GHz.

It uses a radio technology called frequency hopping spread
spectrum (FHSS).
FHSSFHSS
• Frequency hopping spread spectrum (FHSS) is a method
of transmitting radio signals by shifting carriers across
numerous channels with pseudorandom sequence
which is already known to the sender and receiver.
• Frequency hopping spread spectrum is defined in the
2.4 GHz band and operates in around 79 frequencies
ranging from 2.402 GHz to 2.480 GHz.
• Every frequency is GFSK modulated with channel width
of 1MHz and rates defined as 1 Mbps and 2 Mbps
respectively.
• Frequency hopping spread spectrum is a robust
technology with only very little influence from
reflections, noise and other environmental factors

It is a packet-based protocol with a master-slave
structure.

Each master can communicate with up to 7 slaves in a
piconet.

The range of Bluetooth depends upon the class of radio
using.

Class 3 radios have range up to 1 meter or 3 feet.

Class 2 radios have range of 10 meters or 33 feet.

Class 1 radios have range of 100 meters or 300 feet.

The most commonly used radio is Class 2.
Advantages andAdvantages and
DisadvantagesDisadvantages
Advantages

The biggest advantage of using this technology is that there
are no cables or wires required for the transfer of data over
short ranges.

Bluetooth technology consumes less power when compared
with other wireless communication technologies.

For example Bluetooth technology using Class 2 radio uses
power of 2.5 mW.

As it is using frequency hopping spread spectrum radio
technology there is less prone to interference of data if the
other device also operates in the same frequency range.

Bluetooth doesn’t require clear line of sight between the
synced devices.
Disadvantage

Since it uses the greater range of Radio Frequency
(RF), it is much more open to interception and
attack.

It can be used for short range communications
only.

Although there are fewer disadvantages, Bluetooth
still remains best for short wireless technology.
Introduction to HC-05Introduction to HC-05
and HC-06 Modulesand HC-06 Modules
HC 05

HC-05 is a class 2 Bluetooth
module with Serial Port Profile
(SPP).

It can be configure either as
master or salve.

It is a replacement for wired
serial connection.

The module has two modes of
operation, Command Mode
where we can send AT
commands to it and Data
Mode where it transmits and
receives data to another
bluetooth module.
SENSORS AND BLUETOOTH COMMUNICATION

HC-05 Specification:
 Bluetooth Protocol : Bluetooth Specificatio v2.0 + EDR
 Frequency : 2.4 GHz ISM band
 Profiles : Bluetooth Serial Port
 Working Temperature : -20 to + 75 centigrade
 Power of emitting : 3 dBm

The pins on the module are:
 Vcc – Power supply for the module.
 GND – Ground of the module.
 TX – Transmitter of Bluetooth module.
 RX – Receiver of the module.
 Key – Used for the module to enter into AT command mode.

The default mode is DATA Mode, and this is the
default configuration, that may work fine for
many applications:
Baud Rate: 9600 bps, Data : 8 bits, Stop Bits: 1 bit,
Parity : None, Handshake: None

Passkey: 1234

Device Name: HC-05
HC 06

HC-06 is a drop-in replacement for wired serial
connection.

This can be used as serial port replacement to
establish connection between PC and MCU
(Microcontroller).

This is a Slave Mode only Bluetooth device.

HC-06 offers encrypted connection

This module can be configured for baud rates 1200
to 115200 bps
Hooking up with ArduinoHooking up with Arduino

The connections are:
HC-05 Arduino
Vcc -----------> 5V
GND -----------> GND
TX -----------> RX
RX -----------> TX

Let’s control theLet’s control the
LED on ArduinoLED on Arduino
using a basic code tousing a basic code to
send command oversend command over
Bluetooth.Bluetooth.

The code is shown:The code is shown:
void setup() {
Serial.begin(9600);
pinMode(13,OUTPUT);
}
void loop() {
if(Serial.available())
{
ch=Serial.read();
if(ch=='h')
{
digitalWrite(13,HIGH);
}
if(ch=='l')
{
digitalWrite(13,LOW);
}
}
}
Configuring HC-05 withConfiguring HC-05 with
AT commandsAT commands

HC-05 can be configured i.e. its name and
password can be changed and many more using
AT commands.

It can also be configured as either master or slave.

To set the HC-05 into AT command mode the KEY
pin of the module is made high i.e. it is connected
to either 5V or 3.3V pin of Arduino and TX of
Arduino is connected to TX of HC-05 and RX of HC-
05 to RX of Arduino.
SENSORS AND BLUETOOTH COMMUNICATION

To enter the AT commands open up the COM port of
the Arduino to which the Bluetooth module is
connected and set the baud rate to 38400.

After opening COM port if you enter command “AT”
(without quotes) it should return “OK” thus it can be
said that HC-05 entered into AT command mode.

Refer following link for detailed AT commands and its
descriptions:

http://www.linotux.ch/arduino/HC-
0305_serial_module_AT_commamd_set_201104_revise
d.pdf
Popular AT commandsPopular AT commands
1. AT
2. AT+RESET
3. AT+VERSION?
4. AT+ORGL
5. AT+ADDR?
6. AT+ ROLE?
7. AT+NAME?
8. AT+PSWD?
9. AT+UART?
10. AT+STATE?
11. AT+DISC
12. AT+BIND?
13. AT+RMAAD?
14. AT+ADCN?
15. AT+MRAD?
16. AT+PAIR
access AT commandaccess AT command
modemode
• Some bluetooth mode does not have KEY pin.
• In such module, different approach is considered:
• first connect the Bluetooth module to an Arduino
(Nano, UNO or whatever) using the following
connections…
• HC-05 GND –> Gnd
• HC-05 VCC –> +5V (initially disconnected)  *
• HC-05 TX –> D2 (any pin as required)
• HC-05 RX –> D3 (any pin as required)
• STATE (output) and EN (input) are not connected
• Follow these steps:
1. Disconnect the power to the HC-05 module.
2. Load the sketch to the Arduino
3. Depress the small reset button on the HC-05 module and hold
it down while you connect its Vcc pin to +5V.
• The red LED on the module (that would otherwise be blinking
quickly) will flash slowly indicating it is in AT mode.
• Open a serial monitor in the Arduino IDE (or any other
terminal software) and set its baud rate to 57600 and ensure
that on the IDE serial terminal, ensure “Both NL & CR” is
selected.
• You should then see the prompt “Enter AT commands: “.
• You can then type your AT commands into the terminal input
line and have them control the HC-05. 
• Here are a few AT commands that I found useful:
• To ensure the unit is responding, enter AT. The unit should
respond OK
• To return the HC-05 to its default settings, enter AT+ORGL
• To see the version of your HC-05 enter AT+VERSION?
• To change the name of the device to AJCLOCK, for
example, enter AT+NAME=AJCLOCK
• To change the default security code (1234) to 2332 enter
AT+PSWD=2332
• To check baud rate, enter AT+UART? (my unit reset to
38400)
• To change baud rate to say, 115200, 1 stop bit, 0 parity,
enter AT+UART=115200,1,0
CodeCode• #include <SoftwareSerial.h>
• SoftwareSerial btSerial(2, 3); // RX | TX
• void setup() {
• Serial.begin(57600);
• Serial.println("Enter AT commands:");
• btSerial.begin(38400); // HC-05 default speed in AT command more
• }
• void loop() {
• if (btSerial.available())
• Serial.write(btSerial.read());
• if (Serial.available())
• btSerial.write(Serial.read());
• }
Servo MotorServo Motor
• A servo motor allows a precise control of the angular
position, velocity, and acceleration. It’s like you’re at the
steering wheel of your car.
• You control precisely the speed of the car and the
direction.
• These servos are essential parts if we need to control the
position of objects, rotate sensors, move arms and legs,
drive wheels and tracks, and more.
• Inside the micro servo, you will find the pieces from
the above image.
• The top cover hosts the plastic gears while the
middle cover hosts a DC motor, a controller, and
the potentiometer.
• The servo motor has three leads, with one more
than a DC motor.
• Each lead has a color code. So you have to
connect the brown wire from the micro servo to the
GND pin on the Arduino.
• Connect the red wire from the servo to the +5V on
the Arduino. And finally, connect the orange wire
from the SG90 servo to a digital pin (pin 9) on the
Arduino.
SENSORS AND BLUETOOTH COMMUNICATION
SweepSweep
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop() {
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
ProgramProgram
•#include <Servo.h>
•Servo myservo; // create servo
object to control a servo
•int potpin = 0; // analog pin used
to connect the potentiometer
•int val; // variable to read the
value from the analog pin
•void setup() {
• myservo.attach(9); // attaches
the servo on pin 9 to the servo
object
•}
•void loop() {
• val = analogRead(potpin);
// reads the value of the
potentiometer (value between 0
and 1023)
• val = map(val, 0, 1023, 0, 180);
// scale it to use it with the servo
(value between 0 and 180)
• myservo.write(val); //
sets the servo position according
to the scaled value
• delay(15); //
waits for the servo to get there
•}

More Related Content

PPT
ARDUINO AND ITS PIN CONFIGURATION
PPT
Physical prototyping lab2-analog_digital
PDF
Introduction to Arduino
PPTX
02 General Purpose Input - Output on the Arduino
PPT
Serial Communication In Atmega 16
PPTX
Interfacing with Atmega 16
PPT
Physical prototyping lab6-motors
PPTX
Interfacing to the analog world
ARDUINO AND ITS PIN CONFIGURATION
Physical prototyping lab2-analog_digital
Introduction to Arduino
02 General Purpose Input - Output on the Arduino
Serial Communication In Atmega 16
Interfacing with Atmega 16
Physical prototyping lab6-motors
Interfacing to the analog world

What's hot (20)

DOCX
Arduino windows remote control
PPT
Embedded &amp; pcb design
PDF
Codesign-Oriented Platform for Agile Internet of Things Prototype Development
PDF
I2C programming with C and Arduino
PPTX
Basics of open source embedded development board (
PDF
Raspberry Pi - Lecture 3 Embedded Communication Protocols
PPT
Uart 16550
PDF
PPT
Embedded systems and its ports
PPT
PPT
8051 serial communication-UART
PPTX
Interrupts at AVR
DOC
Project
PPTX
Hardware View of Intel 8051
PPTX
UART(universal asynchronous receiver transmitter ) PPT
PPT
8051 microcontroller and it’s interface
PDF
AVR Micro controller Interfacing
PPTX
PDF
Arduino a000066-datasheet
PPTX
Inter intergrated circuits-communication protocol
Arduino windows remote control
Embedded &amp; pcb design
Codesign-Oriented Platform for Agile Internet of Things Prototype Development
I2C programming with C and Arduino
Basics of open source embedded development board (
Raspberry Pi - Lecture 3 Embedded Communication Protocols
Uart 16550
Embedded systems and its ports
8051 serial communication-UART
Interrupts at AVR
Project
Hardware View of Intel 8051
UART(universal asynchronous receiver transmitter ) PPT
8051 microcontroller and it’s interface
AVR Micro controller Interfacing
Arduino a000066-datasheet
Inter intergrated circuits-communication protocol
Ad

Similar to SENSORS AND BLUETOOTH COMMUNICATION (20)

PDF
Arduino Workshop Day 2 - Advance Arduino & DIY
PPTX
Self Obstacle Avoiding Rover
PDF
Automotive report
PPTX
Arduino Based Project.pptx
PPT
360 degree Steering Android.ppt
PDF
IRJET- Line following and Obstacle avoiding Bluetooth Controlled Surveillance...
PPTX
mini project on self driving robot using l293d and arduino
PPTX
Computer networks unit III CHAPTER of frameworks
PPTX
autonomous obstacle avoiding car robot with two wheel using arduino
PDF
OBSTACLE AVOIDACE ROBOT USING ARDUINO UNO AND ULTRASONIC SENSOR
PPTX
major project ppt 27-4-16
PPTX
Topic 7 - Servo_US_Temp_IRrrrrrrrrrrrrrrrrrrrrrrrrr.pptx
PPTX
Robotics and Automation Using Arduino
PDF
Obstacle avoiding car project slide
PPTX
Radar using ultrasonic sensor and arduino.pptx
PPTX
Arduino with brief description of sensorsppt.pptx
PDF
Hand gesture based wheel chair with obstacle detection,wireless &amp; gps tec...
PPTX
How Automatic Vaccum cleaner works in today world.
PDF
Short Range Radar System using Arduino Uno
PPT
Physical prototyping lab5-complex_sensors
Arduino Workshop Day 2 - Advance Arduino & DIY
Self Obstacle Avoiding Rover
Automotive report
Arduino Based Project.pptx
360 degree Steering Android.ppt
IRJET- Line following and Obstacle avoiding Bluetooth Controlled Surveillance...
mini project on self driving robot using l293d and arduino
Computer networks unit III CHAPTER of frameworks
autonomous obstacle avoiding car robot with two wheel using arduino
OBSTACLE AVOIDACE ROBOT USING ARDUINO UNO AND ULTRASONIC SENSOR
major project ppt 27-4-16
Topic 7 - Servo_US_Temp_IRrrrrrrrrrrrrrrrrrrrrrrrrr.pptx
Robotics and Automation Using Arduino
Obstacle avoiding car project slide
Radar using ultrasonic sensor and arduino.pptx
Arduino with brief description of sensorsppt.pptx
Hand gesture based wheel chair with obstacle detection,wireless &amp; gps tec...
How Automatic Vaccum cleaner works in today world.
Short Range Radar System using Arduino Uno
Physical prototyping lab5-complex_sensors
Ad

Recently uploaded (20)

DOCX
573137875-Attendance-Management-System-original
PPTX
Lecture Notes Electrical Wiring System Components
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PDF
PPT on Performance Review to get promotions
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPTX
CH1 Production IntroductoryConcepts.pptx
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPT
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PPTX
bas. eng. economics group 4 presentation 1.pptx
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PPT
Project quality management in manufacturing
PPTX
Sustainable Sites - Green Building Construction
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
573137875-Attendance-Management-System-original
Lecture Notes Electrical Wiring System Components
Foundation to blockchain - A guide to Blockchain Tech
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPT on Performance Review to get promotions
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
CH1 Production IntroductoryConcepts.pptx
Model Code of Practice - Construction Work - 21102022 .pdf
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
bas. eng. economics group 4 presentation 1.pptx
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
Project quality management in manufacturing
Sustainable Sites - Green Building Construction
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
R24 SURVEYING LAB MANUAL for civil enggi
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
CYBER-CRIMES AND SECURITY A guide to understanding
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx

SENSORS AND BLUETOOTH COMMUNICATION

  • 2. SensorSensor • A sensor is a device that detects and responds to some type of input from the physical environment. • The specific input could be light, heat, motion, moisture, pressure, or any one of a great number of other environmental phenomena. • The output is generally a signal that is converted to human-readable display at the sensor location or transmitted electronically over a network for reading or further processing.
  • 4. Sensors we need to learnSensors we need to learn • PIR sensor--- Detecting Movement • Ultrasonic Sensor--- Measuring Distance
  • 5. PIR SENSORPIR SENSOR • PIR sensors allow you to sense motion, almost always used to detect whether a human has moved in or out of the sensors range. • They are small, inexpensive, low-power, easy to use and don't wear out. • For that reason they are commonly found in appliances and gadgets used in homes or businesses. • They are often referred to as PIR, "Passive Infrared", "Pyroelectric", or "IR motion" sensors.
  • 6. PIR SensorPIR Sensor • PIRs are basically made of a pyroelectric sensor  (which you can see above as the round metal can with a rectangular crystal in the center), which can detect levels of infrared radiation. • Everything emits some low level radiation, and the hotter something is, the more radiation is emitted. 
  • 7. • The PIR sensor itself has two slots in it, each slot is made of a special material that is sensitive to IR.  • When the sensor is idle, both slots detect the same amount of IR, the ambient amount radiated from the room or walls or outdoors. • When a warm body like a human or animal passes by, it first intercepts one half of the PIR sensor, which causes a positive differential change between the two halves. • When the warm body leaves the sensing area, the reverse happens, whereby the sensor generates a negative differential change. These change pulses are what is detected.
  • 8. Circuit DiagramCircuit Diagram • Pin1 -VCC • Pin 2- Output of PIR sensor connected to 2 pin of arduino • Pin 3-Ground
  • 9. int ledPin = 13; // choose the pin for the LED int inputPin = 2; // choose the input pin (for PIR sensor) int pirState = LOW; // we start, assuming no motion detected int val = 0; // variable for reading the pin status void setup() { pinMode(ledPin, OUTPUT); // declare LED as output pinMode(inputPin, INPUT); // declare sensor as input Serial.begin(9600); }
  • 10. void loop() { val = digitalRead(inputPin); // read input value if (val == HIGH) { // check if the input is HIGH digitalWrite(ledPin, HIGH); // turn LED ON if (pirState == LOW) { // we have just turned on Serial.println("Motion detected!"); // We only want to print on the output change, not state pirState = HIGH; } }
  • 11. else { digitalWrite(ledPin, LOW); // turn LED OFF if (pirState == HIGH){ // we have just turned of Serial.println("Motion ended!"); // We only want to print on the output change, not state pirState = LOW; } } }
  • 13. • An Ultrasonic sensor is a device that can measure the distance to an object by using sound waves. • It measures distance by sending out a sound wave at a specific frequency and listening for that sound wave to bounce back. • By recording the elapsed time between the sound wave being generated and the sound wave bouncing back, it is possible to calculate the distance between the sonar sensor and the object.  
  • 14. • Since it is known that sound travels through air at about 344 m/s (1129 ft/s), you can take the time for the sound wave to return and multiply it by 344 meters (or 1129 feet) to find the total round-trip distance of the sound wave. • Round-trip means that the sound wave traveled 2 times the distance to the object before it was detected by the sensor; it includes the 'trip' from the sonar sensor to the object AND the 'trip' from the object to the Ultrasonic sensor (after the sound wave bounced off the object). • To find the distance to the object, simply divide the round-trip distance in half.
  • 16. • The Trig pin will be used to send the signal and the Echo pin will be used to listen for returning signal
  • 17. Example- Distance MeasurementExample- Distance Measurement #define echoPin 7 // Echo Pin #define trigPin 8 // Trigger Pin #define LEDPin 13 // Onboard LED int maximumRange = 200; // Maximum range needed int minimumRange = 0; // Minimum range needed long duration, distance; // Duration used to calculate distance void setup() { Serial.begin (9600); pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); pinMode(LEDPin, OUTPUT); // Use LED indicator (if required) }
  • 18. void loop() /* The following trigPin/echoPin cycle is used to determine the distance of the nearest object by bouncing soundwaves off of it. */ { duration = pulseIn(echoPin, HIGH); //Calculate the distance (in cm) based on the speed of sound. distance = duration/58.2; Serial.print(Distance); Dealy(1000);}
  • 19. Interfacing DCInterfacing DC Motor WithMotor With ArduinoArduino
  • 20. DC MotorDC Motor • Working principle of a DC motor --A motor is an electrical machine which converts electrical energy into mechanical energy. • The principle of working of a DC motor is that "whenever a current carrying conductor is placed in a magnetic field, it experiences a mechanical force". • A DC motor (Direct Current motor) is the most common type of motor. DC motors normally have just two leads, one positive and one negative. • If you connect these two leads directly to a battery, the motor will rotate. If you switch the leads, the motor will rotate in the opposite direction.
  • 21. • To control the direction of the spin of DC motor, without changing the way that the leads are connected, you can use a circuit called an H- Bridge. • An H bridge is an electronic circuit that can drive the motor in both directions. • H-bridges are used in many different applications, one of the most common being to control motors in robots. • It is called an H-bridge because it uses four transistors connected in such a way that the schematic diagram looks like an "H." 
  • 22. • You can use discrete transistors to make this circuit, but for this lecture, we will be using the L293d/L298 H-Bridge IC. • In L293 all four input- output lines are independent, while in L298, a half H driver cannot be used independently, full H driver has to be used. • Protective Diodes against back EMF are provided internally in L293D but must be provided externally in L298. • The L298 can control the speed and direction of DC motors and stepper motors and can control two motors simultaneously. • Its current rating is 2A for each motor. At these currents, however, you will need to use heat sinks.
  • 23. L293D Motor Driver ICL293D Motor Driver IC
  • 25. Controlling Speed of DCControlling Speed of DC MotorMotor • We will connect the Arduino to IN1 (pin 5), IN2 (pin 7), and Enable1 (pin 6) of the L293d IC. Pins 5 and 7 are digital, i.e. ON or OFF inputs, while pin 6 needs a pulse-width modulated (PWM) signal to control the motor speed.
  • 26. const int pwm = 2 ; //initializing pin 2 as pwm const int in_1 = 8 ; const int in_2 = 9 ; //For providing logic to L293d IC to choose the direction of the DC motor void setup() { pinMode(pwm,OUTPUT) ; //we have to set PWM pin as output pinMode(in_1,OUTPUT) ; //Logic pins are also set as output pinMode(in_2,OUTPUT) ; }
  • 27. void loop() { //For Clock wise motion , in_1 = High , in_2 = Low digitalWrite(in_1,HIGH) ; digitalWrite(in_2,LOW) ; analogWrite(pwm,255) ; delay(3000) ; /*setting pwm of the motor to 255 we can change the speed of rotaion by chaning pwm input but we are only using arduino so we are using higest value to driver the motor */
  • 28. //For brake digitalWrite(in_1,HIGH) ; digitalWrite(in_2,HIGH) ; delay(1000) ; } //For brake digitalWrite(in_1,HIGH) ; digitalWrite(in_2,HIGH) ; delay(1000) ; //For Anti Clock-wise motion - IN_1 = LOW , IN_2 = HIGH digitalWrite(in_1,LOW) ; digitalWrite(in_2,HIGH) ; delay(3000) ;
  • 30. IntroductionIntroduction  Bluetooth is a wireless communication technology used for exchange of data over short distances.  It is found in many devices ranging from mobile phones and computers.  Bluetooth technology is a combination of both hardware and software.  It is intended to create a personal area networks (PAN) over a short range.  It operates in the unlicensed industrial, scientific and medical (ISM) band at 2.4 to 2.485 GHz.  It uses a radio technology called frequency hopping spread spectrum (FHSS).
  • 31. FHSSFHSS • Frequency hopping spread spectrum (FHSS) is a method of transmitting radio signals by shifting carriers across numerous channels with pseudorandom sequence which is already known to the sender and receiver. • Frequency hopping spread spectrum is defined in the 2.4 GHz band and operates in around 79 frequencies ranging from 2.402 GHz to 2.480 GHz. • Every frequency is GFSK modulated with channel width of 1MHz and rates defined as 1 Mbps and 2 Mbps respectively. • Frequency hopping spread spectrum is a robust technology with only very little influence from reflections, noise and other environmental factors
  • 32.  It is a packet-based protocol with a master-slave structure.  Each master can communicate with up to 7 slaves in a piconet.  The range of Bluetooth depends upon the class of radio using.  Class 3 radios have range up to 1 meter or 3 feet.  Class 2 radios have range of 10 meters or 33 feet.  Class 1 radios have range of 100 meters or 300 feet.  The most commonly used radio is Class 2.
  • 33. Advantages andAdvantages and DisadvantagesDisadvantages Advantages  The biggest advantage of using this technology is that there are no cables or wires required for the transfer of data over short ranges.  Bluetooth technology consumes less power when compared with other wireless communication technologies.  For example Bluetooth technology using Class 2 radio uses power of 2.5 mW.  As it is using frequency hopping spread spectrum radio technology there is less prone to interference of data if the other device also operates in the same frequency range.  Bluetooth doesn’t require clear line of sight between the synced devices.
  • 34. Disadvantage  Since it uses the greater range of Radio Frequency (RF), it is much more open to interception and attack.  It can be used for short range communications only.  Although there are fewer disadvantages, Bluetooth still remains best for short wireless technology.
  • 35. Introduction to HC-05Introduction to HC-05 and HC-06 Modulesand HC-06 Modules HC 05  HC-05 is a class 2 Bluetooth module with Serial Port Profile (SPP).  It can be configure either as master or salve.  It is a replacement for wired serial connection.  The module has two modes of operation, Command Mode where we can send AT commands to it and Data Mode where it transmits and receives data to another bluetooth module.
  • 37.  HC-05 Specification:  Bluetooth Protocol : Bluetooth Specificatio v2.0 + EDR  Frequency : 2.4 GHz ISM band  Profiles : Bluetooth Serial Port  Working Temperature : -20 to + 75 centigrade  Power of emitting : 3 dBm  The pins on the module are:  Vcc – Power supply for the module.  GND – Ground of the module.  TX – Transmitter of Bluetooth module.  RX – Receiver of the module.  Key – Used for the module to enter into AT command mode.
  • 38.  The default mode is DATA Mode, and this is the default configuration, that may work fine for many applications: Baud Rate: 9600 bps, Data : 8 bits, Stop Bits: 1 bit, Parity : None, Handshake: None  Passkey: 1234  Device Name: HC-05
  • 39. HC 06  HC-06 is a drop-in replacement for wired serial connection.  This can be used as serial port replacement to establish connection between PC and MCU (Microcontroller).  This is a Slave Mode only Bluetooth device.  HC-06 offers encrypted connection  This module can be configured for baud rates 1200 to 115200 bps
  • 40. Hooking up with ArduinoHooking up with Arduino  The connections are: HC-05 Arduino Vcc -----------> 5V GND -----------> GND TX -----------> RX RX -----------> TX
  • 41.  Let’s control theLet’s control the LED on ArduinoLED on Arduino using a basic code tousing a basic code to send command oversend command over Bluetooth.Bluetooth.  The code is shown:The code is shown: void setup() { Serial.begin(9600); pinMode(13,OUTPUT); } void loop() { if(Serial.available()) { ch=Serial.read(); if(ch=='h') { digitalWrite(13,HIGH); } if(ch=='l') { digitalWrite(13,LOW); } } }
  • 42. Configuring HC-05 withConfiguring HC-05 with AT commandsAT commands  HC-05 can be configured i.e. its name and password can be changed and many more using AT commands.  It can also be configured as either master or slave.  To set the HC-05 into AT command mode the KEY pin of the module is made high i.e. it is connected to either 5V or 3.3V pin of Arduino and TX of Arduino is connected to TX of HC-05 and RX of HC- 05 to RX of Arduino.
  • 44.  To enter the AT commands open up the COM port of the Arduino to which the Bluetooth module is connected and set the baud rate to 38400.  After opening COM port if you enter command “AT” (without quotes) it should return “OK” thus it can be said that HC-05 entered into AT command mode.  Refer following link for detailed AT commands and its descriptions:  http://www.linotux.ch/arduino/HC- 0305_serial_module_AT_commamd_set_201104_revise d.pdf
  • 45. Popular AT commandsPopular AT commands 1. AT 2. AT+RESET 3. AT+VERSION? 4. AT+ORGL 5. AT+ADDR? 6. AT+ ROLE? 7. AT+NAME? 8. AT+PSWD? 9. AT+UART? 10. AT+STATE? 11. AT+DISC 12. AT+BIND? 13. AT+RMAAD? 14. AT+ADCN? 15. AT+MRAD? 16. AT+PAIR
  • 46. access AT commandaccess AT command modemode • Some bluetooth mode does not have KEY pin. • In such module, different approach is considered: • first connect the Bluetooth module to an Arduino (Nano, UNO or whatever) using the following connections… • HC-05 GND –> Gnd • HC-05 VCC –> +5V (initially disconnected)  * • HC-05 TX –> D2 (any pin as required) • HC-05 RX –> D3 (any pin as required) • STATE (output) and EN (input) are not connected
  • 47. • Follow these steps: 1. Disconnect the power to the HC-05 module. 2. Load the sketch to the Arduino 3. Depress the small reset button on the HC-05 module and hold it down while you connect its Vcc pin to +5V. • The red LED on the module (that would otherwise be blinking quickly) will flash slowly indicating it is in AT mode. • Open a serial monitor in the Arduino IDE (or any other terminal software) and set its baud rate to 57600 and ensure that on the IDE serial terminal, ensure “Both NL & CR” is selected. • You should then see the prompt “Enter AT commands: “. • You can then type your AT commands into the terminal input line and have them control the HC-05. 
  • 48. • Here are a few AT commands that I found useful: • To ensure the unit is responding, enter AT. The unit should respond OK • To return the HC-05 to its default settings, enter AT+ORGL • To see the version of your HC-05 enter AT+VERSION? • To change the name of the device to AJCLOCK, for example, enter AT+NAME=AJCLOCK • To change the default security code (1234) to 2332 enter AT+PSWD=2332 • To check baud rate, enter AT+UART? (my unit reset to 38400) • To change baud rate to say, 115200, 1 stop bit, 0 parity, enter AT+UART=115200,1,0
  • 49. CodeCode• #include <SoftwareSerial.h> • SoftwareSerial btSerial(2, 3); // RX | TX • void setup() { • Serial.begin(57600); • Serial.println("Enter AT commands:"); • btSerial.begin(38400); // HC-05 default speed in AT command more • } • void loop() { • if (btSerial.available()) • Serial.write(btSerial.read()); • if (Serial.available()) • btSerial.write(Serial.read()); • }
  • 51. • A servo motor allows a precise control of the angular position, velocity, and acceleration. It’s like you’re at the steering wheel of your car. • You control precisely the speed of the car and the direction. • These servos are essential parts if we need to control the position of objects, rotate sensors, move arms and legs, drive wheels and tracks, and more.
  • 52. • Inside the micro servo, you will find the pieces from the above image. • The top cover hosts the plastic gears while the middle cover hosts a DC motor, a controller, and the potentiometer.
  • 53. • The servo motor has three leads, with one more than a DC motor. • Each lead has a color code. So you have to connect the brown wire from the micro servo to the GND pin on the Arduino. • Connect the red wire from the servo to the +5V on the Arduino. And finally, connect the orange wire from the SG90 servo to a digital pin (pin 9) on the Arduino.
  • 55. SweepSweep #include <Servo.h> Servo myservo; // create servo object to control a servo // twelve servo objects can be created on most boards int pos = 0; // variable to store the servo position void setup() { myservo.attach(9); // attaches the servo on pin 9 to the servo object } void loop() { for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees // in steps of 1 degree myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } }
  • 56. ProgramProgram •#include <Servo.h> •Servo myservo; // create servo object to control a servo •int potpin = 0; // analog pin used to connect the potentiometer •int val; // variable to read the value from the analog pin •void setup() { • myservo.attach(9); // attaches the servo on pin 9 to the servo object •} •void loop() { • val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023) • val = map(val, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180) • myservo.write(val); // sets the servo position according to the scaled value • delay(15); // waits for the servo to get there •}