Pir + Relais

Bonjour j'aurais besoin de votre aide.
Je souhaiterai commander un relais via un PIR.
Je dispose de ce code:

//the time we give the sensor to calibrate (10-60 secs according to the datasheet)
int calibrationTime = 30;  
// The time the device will stay on
int delayTime = 5000;

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

void setup() {
  pinMode(ledPin, OUTPUT);      // declare LED as output
  pinMode(relayPin, OUTPUT);
  pinMode(inputPin, INPUT);     // declare sensor as input
  Serial.begin(9600);
  digitalWrite(relayPin, stateRelay);
  //give the sensor some time to calibrate
  Serial.print("calibrating sensor ");
  for(int i = 0; i < calibrationTime; i++){
    Serial.print(".");
    delay(1000);
  }
  Serial.println("SENSOR ACTIVE");
  delay(50);
}

void loop(){
  val = digitalRead(inputPin);  // read input value
  //Serial.println(val);
  if (val == HIGH) { // check if the input is HIGH
    digitalWrite(ledPin, HIGH);  // turn LED ON
    delay(150);    

    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
    delay(300);    
      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;
    }
  }

  Serial.println(pirState);
  if(pirState == HIGH){
     digitalWrite(relayPin, LOW);
     delay(delayTime);
  } else {
     digitalWrite(relayPin, HIGH);
  }
}

Le problème c'est que je souhaite que le relais s'éteigne une fois que je repasse ma main devant le PIR.
Est ce possible ?

Merci de votre aide.
Tom

Salut Tom,

Un petit post à ce sujet, peut être pour te faire un peut avancé, cordialement.

http://forum.arduino.cc/index.php?topic=89242.0

Merci beaucoup je vais regarder cela

Mon montage fonctionne bien, le seul problème c'est que mon relais reclaque au bout d'un certain temps, comme prévu dans le code ci dessous, hors j'aimerai également avoir la possibilité de repasser ma main devant le capteur PIR pour "désactiver" mon relais

//the time we give the sensor to calibrate (10-60 secs according to the datasheet)
int calibrationTime = 30;

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);

Serial.print("calibrating sensor ");
for(int i = 0; i < calibrationTime; i++){
Serial.print(".");
delay(500);
}
}

void loop(){
val = digitalRead(inputPin); // read input value
Serial.println(val);
if (val == HIGH) { // check if the input is HIGH
digitalWrite(ledPin, HIGH); // turn LED ON
delay(15000);

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
delay(300);
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;
}
}
}