Difference between revisions of "PIR Motion Sensor"

From Digipool-Wiki
Jump to: navigation, search
 
Line 37: Line 37:
 
   delay(3000);
 
   delay(3000);
 
   Serial.println(" completed");
 
   Serial.println(" completed");
 
 
}
 
}
  
Line 43: Line 42:
 
void loop(){
 
void loop(){
 
int pirVal = digitalRead(pirPin);
 
int pirVal = digitalRead(pirPin);
//int pirVal = analogRead(5);
 
 
  //Serial.println(pirVal);
 
  //delay(500);
 
 
 
    
 
    
 
   if(pirVal == LOW){ //was motion detected
 
   if(pirVal == LOW){ //was motion detected
Line 53: Line 47:
 
   delay(2000);  
 
   delay(2000);  
 
   }
 
   }
 
+
 
+
 
}
 
}
 
</source>
 
</source>

Latest revision as of 14:21, 20 June 2013

PIR-Motion-Sensor.jpg

Mit dem SEN-08630 von Sparkfun und einem 5V-Arduino kann man leicht einen Bewegungsmelder bauen, der sich programmieren läst.

!Achtung! Der Sensor lässt sich durch einen Bildschirm (Laptop, Computermonitor) irritieren und schlägt dann immer Alarm. Der PIR-Senor sollte also mit etwas Pappe abgeschirmt werden.


Verkabelung

  • Rotes Kabel = +5V
  • Braunes oder weißes Kabel = GND
  • Schwarzes Kabel = pirPin (Digital Pin 2)


Code <source lang = "java">

// PIR Motion Sensor // SEN-08630 by sparkfun // // red wire = +5V // brown or the white wire = GND // black wire = pirPin (2)


int pirPin = 2; //digital 2

void setup(){

 Serial.begin(9600); 
 Serial.println(" ");
 Serial.print("Calibration");
 pinMode(pirPin, INPUT);
 digitalWrite(pirPin, HIGH);
 delay(3000);
 Serial.println(" completed");

}


void loop(){ int pirVal = digitalRead(pirPin);

 if(pirVal == LOW){ //was motion detected
  Serial.println("Motion Detected"); 
  delay(2000); 
  }

} </source>