Sauvegarder état détecteur de mouvement

Bonjour,

J'ai un soucis, je parcoure des dizaines de forums pour trouver un peu d'aide sur ce programme. J'explique mon problème, j'ai automatisé une boîte aux lettres, mais j'ai un soucis au niveau du détecteur de mouvement: J'ai mon programme pour détecter un mouvement mais j'aimerais que quand l'utilisateur introduit une lettre cette état "1" soit sauvegarder par le programme et que au moment ou le propriétaire appuie sur un bouton cette état soit reset à "0".

int ledPin = 13; // choose the pin for the LED
int inputPin = 2; // choose the input pin (for PIR sensor)
int pirState = LOW; // we start, assuming no motion detected
int val = 0; // variable for reading the pin status

void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare sensor as input

Serial.begin(9600);
}

void loop(){
val = digitalRead(inputPin); // read input value
if (val == HIGH) { // check if the input is HIGH
digitalWrite(ledPin, HIGH); // turn LED ON
if (pirState == LOW) {
// we have just turned on
Serial.println("Motion detected!");
// We only want to print on the output change, not state
pirState = HIGH;
}
} else {
digitalWrite(ledPin, LOW); // turn LED OFF
if (pirState == HIGH){
// we have just turned of
Serial.println("Motion ended!");
// We only want to print on the output change, not state
pirState = LOW;
}
}
}

Si quelqu'un a une petite idée sur le sujet, je suis preneur, merci d'avance!

Cordialement,

Thomas.

Il faut mettre un flag à 1 lors de la détection.
Ne mettre le flag à 0 que lors de l'appui sur le bouton, et non pas quand il n'y a pas de détection
:wink:

bonjour,
simplement en mettant un truc comme ca, j'ai pas testé

int ledPin = 13;                // choose the pin for the LED
int inputPin = 2;               // choose the input pin (for PIR sensor)
int pirState = LOW;             // we start, assuming no motion detected
int val = 0;                    // variable for reading the pin status
[b] 
const int bouton = 5;
int detection = 0;

[/b]
void setup() {
  pinMode(ledPin, OUTPUT);      // declare LED as output
  pinMode(inputPin, INPUT);     // declare sensor as input
[b] pinMode(bouton, INPUT); [/b]
  Serial.begin(9600);
}
 
void loop(){
  val = digitalRead(inputPin);  // read input value
  if (val == HIGH) {            // check if the input is HIGH
    digitalWrite(ledPin, HIGH);  // turn LED ON
    if (pirState == LOW) {
      // we have just turned on
      Serial.println("Motion detected!");
      // We only want to print on the output change, not state
      pirState = HIGH;
[b]detection = 1;[/b]
    }
  } else {
    digitalWrite(ledPin, LOW); // turn LED OFF
    if (pirState == HIGH){
      // we have just turned of
      Serial.println("Motion ended!");
      // We only want to print on the output change, not state
      pirState = LOW;
detection = 1;
    }
  }

[b]if (bouton == HIGH) detection =0;[/b]
}