2010年6月8日火曜日

Sensor 03 Motion sensor

This tutorial is based on http://www.ladyada.net/learn/sensors/pir.html

In this tutorial enable you to use motion sensor (PIR sensor) in your art work.

I figure out that my room has some problems that causes bad effect for a motion sensor.

Therefore, the program of motion sensor works better in my room but you can change it for your purpose,  such as change the sensibility of the sensor.

Requirements

PIR sensor

LED

wires

Arduino



Circuit






detail of the circuit



Setup jumper in H


Program


The following program is made for my room to use motion sensor. However, this program takes continuous 3 second movements in order to light up LED.

If you have a same trouble same as  me. Try following  program.

/*

This program is designed for my room's situation.

What I did is that I ignore the pulse that send from PIR sensor

if it is less than 3 second continuous pulse(continuous motion).

You can change that section as sensibility of PIR sensor.

*/


int motion=2;

int light =13;
int val,count;

void setup()
{
Serial.begin(9600);
pinMode(motion, INPUT);// for PIR seonsor 
pinMode(light, OUTPUT);// for LED 
}
void loop()
{

val = digitalRead(motion); //get data from pin.

if ( val == 1) //to ignore the noise pulse 
{
count++;//counter for the number of noise pulse 
Serial.println(count);
delay(500); //regulate the frequency of activating sensor
if (count >=6) //threshold for the continuous pulses 
{
digitalWrite(light, HIGH);
delay(300);
Serial.print("the object is moving");
Serial.println(count);// just for check whether the program works properly or not. 
}
}

else//no motion is detected
{
digitalWrite(light, LOW);
delay(10); // If this delay is shorter the sensor react more quicker 
count =0; // reset counter. 
Serial.println("reset");
delay(10);// If this delay is shorter the sensor react more quicker 
}
}

0 件のコメント:

コメントを投稿