// // Infrared (PIR) motion detector demonstration // // We use the HC-SR501 motion sensor. // It runs on 5 volts, so we steal the power from TP1 on the Launchpad, and use a 1,000 ohm resistor to // bring the output pulse down to a level the Launchpad can handle. // // The sensor has three pins, power, output, and ground. The output is connects (via the 1,000 ohm resistor) // to Port 1 pin 4. // enum { USE_SERIAL=false }; void setup( void ) { if( USE_SERIAL ) Serial.begin( 9600 ); pinMode( P1_4, INPUT ); pinMode( GREEN_LED, OUTPUT ); } void loop( void ) { if( digitalRead( P1_4 ) == HIGH ) { if( USE_SERIAL) Serial.println( "Motion detected!" ); digitalWrite( GREEN_LED, HIGH ); } else { if( USE_SERIAL ) Serial.println( "All quiet..." ); digitalWrite( GREEN_LED, LOW ); } delay( 10 ); }