Détecteur de mouvement

Schema

/*  
    Arduino with PIR motion sensor
*/
 
int led = 12;                // the pin that the LED is atteched to
int sensor = 2;              // the pin that the sensor is atteched to
int sensorValue = 0;        // variable to store the sensor status (value)

void setup() {
  pinMode(led, OUTPUT);      // initalize LED as an output
  pinMode(sensor, INPUT);    // initialize sensor as an input
  Serial.begin(9600);        // initialize serial
}

void loop(){
  sensorValue = digitalRead(sensor);     // read sensor value
  if (sensorValue == HIGH) {             // check if the sensor is HIGH
    digitalWrite(led, HIGH);             // turn LED ON
    Serial.println("Motion detected!"); 
  } 
  else {
      digitalWrite(led, LOW);            // turn LED OFF
      Serial.println("Motion stopped!");
  }
}

Arduino détecteur de mouvement

By NicoHash

Arduino détecteur de mouvement

  • 45