0% found this document useful (0 votes)
6 views19 pages

IT Section 3

Uploaded by

Mirna Attallah
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)
6 views19 pages

IT Section 3

Uploaded by

Mirna Attallah
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/ 19

Information Technology Principles

(Arduino)
Section 3
Sensor

• 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 Example
Sensors we need to learn

• PIR sensor--- Detecting Movement

• Ultrasonic Sensor--- Measuring Distance


PIR 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 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.
PIR SENSOR
• 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 Diagram

• Pin1 -VCC
• Pin 2- Output of PIR sensor connected to 2 pin of arduino
• Pin 3-Ground
Code
int ledPin = 13; // choose the pin for the LED
int inputPin = 2; // choose the input pin (for PIR sensor)
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);
}
Code
void loop()
{
val = digitalRead(inputPin); // read input value
if (val == HIGH)
{ // check if the input is HIGH
digitalWrite(ledPin, HIGH); // turn LED ON
// we have just turned on
Serial.println("Motion detected!"); // We only want to print on the output change, not state

}
Code
else
{
digitalWrite(ledPin, LOW); // turn LED OFF

Serial.println("Motion ended!"); // We only want to print on the output change, not


state

}
}
Ultrasonic Sensor
Ultrasonic Sensor
• 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.
Ultrasonic Sensor
• 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.
Ultrasonic Sensor
Ultrasonic Sensor
• The Trig pin will be used to send the signal and the Echo pin will be used to listen
for returning signal
Code
#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)
}
Code
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);}
THANK YOU

You might also like