Code produit: | HC-SR505 |
The HC-SR505 is the little brother of the HC-SR501 which means it sure lacks some of the HC-SR501 functionality such as:
1- Single/Repeated triggering is not adjustable. The HC-SR505 triggering is repeatedly by default
2- The HC-SR501 range is around 7 meters while the HC-SR505 is around 3 - 4 meters
3- The delay between repeated triggering is not adjustable
Still, the HC-SR505 enjoy some features where it outbeats the older brother such as:
1- Size
2- Very low current consumption which is around 60 uAmps
3- As reliable as the older brother
//temps de calibration du capteur (10-60 secs selon la doc technique) int calibrationTime = 15; int ledPin = 13; // pin pour la led int pinCapteur = 7; // pin pour la sortie du capteur int pirState = LOW; // nous considérons le début sans mouvement int val = 0; // variable de lecture de pin void setup() { pinMode(ledPin, OUTPUT); pinMode(pinCapteur, INPUT); Serial.begin(9600); Serial.print("Calibration du capteur "); for(int i = 0; i < calibrationTime; i++){ Serial.print("."); delay(1000); } } void loop(){ val = digitalRead(pinCapteur); // lit la valeur du capteur Serial.println(val); if (val == HIGH) { // vérifie si il y a un mouvement digitalWrite(ledPin, HIGH); // allumage de la led delay(150); if (pirState == LOW) { // we have just turned on Serial.println("Mouvement détecté!"); //changement de l'état pirState = HIGH; } } else { digitalWrite(ledPin, LOW); // extinction de la led delay(300); if (pirState == HIGH){ Serial.println("Fin du mouvement!"); //changement de l'état pirState = LOW; } } }