Examples - Sensorboard - Motion PIR

PIR Motion Sensor SE-90

This Example shows the use of a PIR Motion Sensor SE-90.





/**************************************************************************************************
*
*  PIR Motion Sensor SE-90
*
*   Version:      1.0.0 - September 2008
*   Author:       Etienne Ribeiro    / tutorial assistant caad      /  eribeiro[at]ethz.ch
*   Supervisor:   Christoph Wartmann / chair for caad - ETH Zürich  /  wartmann[at].arch.ethz.ch
*
*   Desc:         Shows the use of the PIR Motion Sensor SE-90. Remarks: The sensor needs up to 30
*                 seconds after beeing powerd to return accurate results.
*
***************************************************************************************************/




//
// Const

int TURN_OFF_AFTER = 3000; // Milliseconds. Periode to torn on sensor again.
int digitalPin = 24; // Pin where PIR-Sensor's out pin is connected
int ledPin = 25;


//
// Var
boolean isTransition = true;
long tmpMillis = 0;


//
// Setup

void setup() {

        // LED (2 * blink)
        pinMode(48, OUTPUT);
        digitalWrite(48, HIGH);
        delay(200);
        digitalWrite(48, LOW);
        delay(200);
        digitalWrite(48, HIGH);


        // Start Serial
        Serial.begin(9600);


        // Pin
        pinMode(digitalPin, INPUT);
        pinMode(ledPin, OUTPUT);

}




//
// Loop

void loop() {

        // Something detected
        if (digitalRead(digitalPin) == LOW) {

                tmpMillis = millis();

                //digitalWrite(ledPin, HIGH); // LED

                if (isTransition == true) { // go in only one time

                        isTransition = false;
                        Serial.print("Something moved...");

                }

        } else {

                //digitalWrite(ledPin, LOW); // LED

                // Commit detection if nothing moved for TURN_OFF_AFTER-time
                if (isTransition == false && tmpMillis + TURN_OFF_AFTER < millis()) { // go in only one time

                        isTransition = true;
                        Serial.println("and stopped.");

                }

        }

        delay (200);

}


This website has been archived and is no longer maintained.