#define LED_PIN 13 #define MOTION_PIN 4 // button state int current = 0; int last = 0; void setup() { pinMode(LED_PIN, OUTPUT); pinMode(MOTION_PIN, INPUT); } void loop() { // grab the current state of the button. if(digitalRead(MOTION_PIN) == HIGH) current = 1; else current = 0; // return if the value hasn't changed if(current == last) return; digitalWrite(LED_PIN, current); last = current; }