Sensor name: Parallax
PIR Sensor (Rev B)
Information URL: http://www.parallax.com/product/555-28027
Cost per unit: $10.99 USD (approx. 86 HKD)
About Infrared
Radiation
Infrared (IR) is invisible radiant energy, electromagnetic
radiation with longer wavelengths than visible light, extending from the
nominal red edge of the visible spectrum at 700 nanometers (frequency 430 THz)
to 1 mm (300 GHz). Infrared radiation was discovered by astronomer Sir William
Herschel who discovered a type of invisible radiation in the spectrum beyond
red light.
General Information
PIR sensor is made of a pyroelectric sensor and it detected
the motion of the object walks to the sensor by the infrared radiation. It works by detecting a rapid change of infrared
energy and send a signal. The round metal in the center of the sensor can detect the levels of
infrared radiation.
The sensor in the motion
detector has split in two halves. The two halves are wired up so that they
cancel each other out. If one of half sees sense or less IR radiation than another
half, the output will swing high or low.
Features and Specifications
- Typically detects a person up to 15 ft away to
approximately 30 ft away
- Approximately 90 degree field of view
- Onboard LEDs light up the lens for fast visual
feedback when movement is detected
- Mounting holes for 2-56 sized screws provide
easy integration in permanent applications
- 3-pin SIP package is good for
breadboard-friendly projects
- Communication: Any microcontroller
- Easy to conceal because of the small size
- Dimensions: 1.41 x 1.0 x 0.8 in (3.6 x 2.5 x
2.0 cm)
- Voltage requirements: 3 to 6 VDC
Getting it to
work!
Connection
VCC of the PIR))) connected to Breadboard +
GNC of the PIR))) connected to Breadboard
–
OUT of the PIR))) connected to Pin7
on Arduino
VDD of the LCD))) connected to Breadboard
+
GNC of the LCD))) connected to Breadboard
–
RX of the LCD))) connected to Pin2 on Arduino
GND of 9V Battery))) connected to Breadboard-
VCC of 9V Battery))) connected to Breadboard+
1 Pin of MOSFET))) connected
to Pin5 on Arduino
1 Pin of MOSFET))) connected
to Resistor
1 Pin of MOSFET))) connected
to Breadboard –
GND of Motor))) connected to Resistor
VCC of Motor))) connected to Breadboard +
5V pin on Arduino))) connected to Breadboard +
GND on Arduino))) connected to Breadboard -
Example Code
#include
<SoftwareSerial.h>
//Attach the serial display's RX line to digital pin 2
SoftwareSerial
mySerial(3,2);
//pin 2= TX, pin 3 = RX (unused)
const int sensor_pin =
7; //set constant variable for PIR sensor
int prepTime = 30; //seconds
for sensor to prepare
long unsigned int
lowIn; // the time when the sensor outputs a low impulse
long unsigned int
pause = 5000; // timeout before we "all" motion has ceased
boolean lockLow =
true;
boolean takeLowTime;
//set variables
int pirPin = 7; //the digital
pin connected to the PIR sensor's OUTPUT
int motorPin = 5; //the pin
connected to the motor
void setup(){
//initialize
serial communication:
mySerial.begin(9600);
mySerial.write(254); //set LCD cursor start from the beginning
mySerial.write(128);
mySerial.write("
"); //clear LCD
mySerial.write("
");
mySerial.write(254);
mySerial.write(128);
mySerial.write("Ready!"); //show information to tell the
sensor is warming up
Serial.begin(9600);
pinMode(pirPin,
INPUT);
//use PIR reading as INPUT and
related to motor OUTPUT
pinMode(motorPin, OUTPUT);
digitalWrite(pirPin, LOW);
//give the
sensor some time to prep
Serial.print("preparing sensor ");
for(int i = 0;
i < prepTime; i++){
Serial.print(".");
delay(500);
}
//show the
sensor is prepared
//delay some time
before the sensor actual work
Serial.println(" done");
Serial.println("SENSOR ACTIVE");
mySerial.write(254);
mySerial.write(128);
mySerial.write("
");
mySerial.write("
");
mySerial.write(254);
mySerial.write(128);
mySerial.write("GET SET!");
//show the information that the
sensor is ready to function
delay(1000);
}
//the main function
void loop(){
if(digitalRead(pirPin) == HIGH){
//if the
sensor has reading, turn on the motor and change display "go"
digitalWrite(motorPin, HIGH);
mySerial.write(254);
mySerial.write(128);
mySerial.write("
");
mySerial.write("
");
mySerial.write(254);
mySerial.write(128);
mySerial.write("GO!GO!GO!");
// makes sure we wait for a transition to LOW
before any further
// output is made:
if(lockLow){
lockLow = false;
//show how long the motion that the sensor detected
Serial.println("---");
Serial.print("motion detected at ");
Serial.print(millis()/1000);
Serial.println(" sec");
delay(50);
}
takeLowTime = true;
}
//if the sensor does not have any reading, stop the
motor and change display
if(digitalRead(pirPin) == LOW){
digitalWrite(motorPin, LOW);
mySerial.write(254);
mySerial.write(128);
mySerial.write("
");
mySerial.write(254);
mySerial.write(128);
mySerial.write("STOP! STOP!");
// save the time of the transition from high
to LOW
// make sure this is only done at the start
of a LOW phase
if(takeLowTime){
lowIn = millis();
takeLowTime = false;
}
// if the sensor is low for more than the
given pause,
if(!lockLow && millis() - lowIn > pause){
// makes sure this block of code is
only executed again after
// a new motion sequence has been
detected
lockLow = true;
//show the motion end
Serial.print("motion ended at ");
Serial.print((millis() - pause)/1000);
Serial.println(" sec");
delay(50);
//sources https://www.youtube.com/watch?v=sOz41WQF7wE
//sources http://www.instructables.com/id/Arduino-Motion-Detector-Make-it-Wireless-Call-Phon/step7/Part-2-Results/
}
}
}
沒有留言:
張貼留言