รหัสสินค้า | SKU-00032 |
หมวดหมู่ | Sensor ( เซ็นเซอร์ ) |
ราคา | 149.00 บาท |
สถานะสินค้า | พร้อมส่ง |
ลงสินค้า | 23 ก.พ. 2557 |
อัพเดทล่าสุด | 23 ก.พ. 2557 |
คงเหลือ | ไม่จำกัด |
จำนวน | ชิ้น |
The PIR Motion Sensor on the left is made by Parallax and sold by Radio Shack. The one on the right comes from Sparkfun. The difference between the two is important to note: The Sparkfun PIR has an open collector output — this means that the sensor requires a pullup resistor so that the output is always high, and when the sensor triggers it will pull the output low. The Parallax model is the opposite — the output is low until it is triggered, and then the output goes high. A simple way to think of the sensor is a switch; the diagram below explains the difference between the two approaches. It doesn’t matter which approach is used as long as you know which one you are using so you can write the code accordingly.
The circuit for the Parallax sensor looks like this:
Connections are as follows
Here is the Arduino code for the Parallax sensor
int motion_1 = 2;
int light_1 = 13;
void setup(){
pinMode (motion_1,INPUT);
pinMode (light_1, OUTPUT);
}
void loop (){
digitalWrite (light_1,LOW);
delay(1000); //this delay is to let the sensor settle down before taking a reading
int sensor_1 = digitalRead(motion_1);\
if (sensor_1 == HIGH){
digitalWrite(light_1,HIGH);
delay(500);
digitalWrite(light_1,LOW);
delay(500);
}
}
Here is the circuit for the Sparkfun Active Low style sensor.
The code for the active low Sparkfun style motion detector looks like this.
int motion_1 = 2;
int light_1 = 13;
void setup(){
pinMode (motion_1,INPUT);
pinMode (light_1, OUTPUT);
}
void loop (){
digitalWrite (light_1,LOW);
delay(1000); //this delay is to let the sensor settle down before taking a reading
int sensor_1 = digitalRead(motion_1);
if (sensor_1 == LOW){
digitalWrite(light_1,HIGH);
delay(500);
digitalWrite(light_1,LOW);
delay(500);
}
}
Regardless of the type you are using the code does the same thing: Check to see if the sensor is triggered; if it is, flash the on-board LED in front of digital pin 13. This is a good way to not only test the sensor but to see if it is going to be too sensitive and trigger to early. If it’s too sensitive you can use a cardboard tube to narrow the focus of the sensor. Just place the tube over the sensor to block any heat signatures approaching from the side.
Of course you can use multiple sensors and outputs to trigger different effects depending on your needs. The Arduino is capable of driving small loads like an LED without extra components. Next week we will look at driving larger loads like buzzers, lights and sound modules.
If you’re new to the Arduino, you should read Brian McLaughlin’s introductory articles about the Arduino. The Sparkfun PIR Sensor can be found on the Sparkfun Website as well as the the datasheet. The Parallax sensor can be found at Radioshack, and here is the datasheet.
Finally you should check out the Geekdad Community Forums. I will be setting this up as a project and you can post questions and comments there. Have fun playing with this and see you next week when we look at controlling bigger things with the Arduino.
หน้าที่เข้าชม | 124,129 ครั้ง |
ผู้ชมทั้งหมด | 51,783 ครั้ง |
เปิดร้าน | 11 ธ.ค. 2556 |
ร้านค้าอัพเดท | 10 ส.ค. 2568 |