Ligne 22 : |
Ligne 22 : |
| | | |
| == Code == | | == Code == |
− | The code is very simple, and is basically just keeps track of whether the input to pin 2 is high or low. It also tracks the state of the pin, so that it prints out a message when motion has started and stopped.
| + | Le code est assez simple, il ne fait que surveiller l'état Haut/Bas (HIGH/LOW) de la Pin 2. |
| + | |
| + | Il surveille également '''le changement d'état''' de la Pin 2, ce qui permet d'afficher un message quand un déplacement est détecter (lorsqu'il commence) et lorsque le mouvement à cessé. |
| | | |
| <nowiki> | | <nowiki> |
| /* | | /* |
− | * PIR sensor tester | + | * Test du senseur PIR |
| */ | | */ |
| | | |
− | int ledPin = 13; // choose the pin for the LED | + | int ledPin = 13; // Pin choisie à cause de sa LED (visible sur la carte) |
− | int inputPin = 2; // choose the input pin (for PIR sensor) | + | int inputPin = 2; // Pin d'entrée choisie pour surveillé le senseur PIR |
− | int pirState = LOW; // we start, assuming no motion detected | + | int pirMotionState = LOW; // Pour commencer, nous considérons qu'il n'y a pas de nouvement. |
− | int val = 0; // variable for reading the pin status | + | int val = 0; // Variable utilisée pour lire l'entrée Pin 2 (valeur du PIR) |
| | | |
| void setup() { | | void setup() { |
− | pinMode(ledPin, OUTPUT); // declare LED as output | + | pinMode(ledPin, OUTPUT); // déclarer LED comme sortie |
− | pinMode(inputPin, INPUT); // declare sensor as input | + | pinMode(inputPin, INPUT); // déclarer le Senseur comme entrée |
| | | |
| Serial.begin(9600); | | Serial.begin(9600); |
Ligne 42 : |
Ligne 44 : |
| | | |
| void loop(){ | | void loop(){ |
− | val = digitalRead(inputPin); // read input value | + | val = digitalRead(inputPin); // Lire la valeur d'entrée |
− | if (val == HIGH) { // check if the input is HIGH | + | if (val == HIGH) { // Vérifier si l'entrée est HIGH |
− | digitalWrite(ledPin, HIGH); // turn LED ON | + | digitalWrite(ledPin, HIGH); // Allumer la LED (activité PIR) |
− | if (pirState == LOW) { | + | if (pirMotionState == LOW) { |
− | // we have just turned on | + | // Si l'état du PIR est LOW, comme nous venons de détecter un mouvement |
− | Serial.println("Motion detected!"); | + | // nous changeons l'état pirMotionState à HIGH (mouvement détecté) |
− | // We only want to print on the output change, not state | + | Serial.println("Mouvement détecté!"); |
− | pirState = HIGH; | + | // Nous affichons le message seulement quand la sortie change |
| + | pirMotionState = HIGH; |
| } | | } |
| } else { | | } else { |
− | digitalWrite(ledPin, LOW); // turn LED OFF | + | digitalWrite(ledPin, LOW); // Eteindre la LED (plus d'activité PIR) |
− | if (pirState == HIGH){ | + | if (pirMotionState == HIGH){ |
− | // we have just turned of | + | // Si l'état PIR est HIGH (mouvement détecté) et que la sortie du PIR |
− | Serial.println("Motion ended!"); | + | // passe à LOW, c'est que le mouvement à cessé! |
− | // We only want to print on the output change, not state | + | Serial.println("Mouvement terminé!"); |
− | pirState = LOW; | + | // Nous affichons le message que pour le changement d'état (détection mouvement) |
| + | pirMotionState = LOW; |
| } | | } |
| } | | } |