Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// A passive infrared sensor (PIR sensor) is an electronic sensor
- // that measures infrared (IR) light radiating from objects in its field of view.
- // They are most often used in PIR-based motion detectors. PIR sensors are commonly
- // used in security alarms and automatic lighting applications.
- // PIR sensors detect general movement, but do not give information on who or what moved.
- int ledPin = 9;
- int buzzerPin = 10;
- int sensorPin = 11;
- bool isSensorDetecting;
- // bool state;
- void setup()
- {
- pinMode(sensorPin, INPUT);
- pinMode(ledPin, OUTPUT);
- pinMode(buzzerPin, OUTPUT);
- }
- void loop()
- {
- isSensorDetecting = digitalRead(sensorPin);
- // The sensor can understand i an object exists or no (0 or 1)
- if(isSensorDetecting == true){
- digitalWrite(ledPin, HIGH);
- tone(buzzerPin, 1000);
- delay(500);
- // I will make the reverse thing in order to have sth like alarm
- digitalWrite(ledPin, LOW);
- noTone(buzzerPin);
- delay(500);
- }
- else{
- digitalWrite(ledPin, LOW);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement