« Item:Détecteur de Mouvement HC-SR501 » : différence entre les versions

Djbrown (discussion | contributions)
Page créée avec « {{Item |Main_Picture=Item-Motion_Sensor_HC-SR501_motion_sensor_hc_sr-501.jpg |Description=Détecteur de mouvement PIR |Categories=Matériel, Parts |Cost=0.72 |Currency=EUR... »
 
Djbrown (discussion | contributions)
Aucun résumé des modifications
Ligne 11 : Ligne 11 :
<br />
<br />


= Caractéristiques =
=Caractéristiques=
<br />
<br />


* alimentation maxi : 5V
*alimentation maxi : 5V


= Bibliothèque : =
=Bibliothèque : =
Pour utiliser le détecteur de mouvement il n'y a besoin d'aucunes bibliothèques
Pour utiliser le détecteur de mouvement il n'y a besoin d'aucunes bibliothèques


= Câblage : =
=Câblage : =
<br />
{{#annotatedImageLight:Fichier:Item Motion Sensor HC-SR501.png|0=509px|hash=|jsondata=|mediaClass=Image|type=frameless|alt=Item Motion Sensor HC-SR501|align=center|src=https://www.wikidebrouillard.org/images/9/91/Item_Motion_Sensor_HC-SR501.png|href=./Fichier:Item Motion Sensor HC-SR501.png|resource=./Fichier:Item Motion Sensor HC-SR501.png|caption=|size=509px}}
=Le code minimal : =
{| class="wikitable" cellspacing="0" border="0"
| height="17" bgcolor="#999999" align="left" |
| valign="middle" bgcolor="#999999" align="center" |
| bgcolor="#999999" align="center" |Motion Sensor HC SR-501
|-
| rowspan="2" valign="middle" height="49" bgcolor="#999999" align="center" |Avant le Setup
| valign="middle" bgcolor="#999999" align="center" |Importation de la bibliothèque
| valign="middle" align="left" |Aucunes bibliothèques
|-
| valign="middle" bgcolor="#999999" align="center" |Création de l’objet
| valign="middle" align="left" |#define pirPin <numéro de broche>; // je défini la broche
int val = LOW;
 
bool motionState = false;
|-
| valign="middle" height="17" bgcolor="#999999" align="center" |Dans le Setup
| valign="middle" bgcolor="#999999" align="center" |Démarrage de l’objet
| valign="middle" align="left" |pinMode(pirPin, INPUT);
|-
| valign="middle" height="41" bgcolor="#999999" align="center" |Dans le Loop
| valign="middle" bgcolor="#999999" align="center" |Utilisation
| valign="middle" align="left" |val = digitalRead(pirPin);
if (motionState == false)
|}
=Autres fonctionnalités=
Aucune autres fonctionnalités
=Exemple : =
<syntaxhighlight lang="arduino" line="1" start="1">
#define pirPin 2
int val = LOW;
bool motionState = false;
 
void setup() {
  Serial.begin(9600);
  pinMode(pirPin, INPUT);
}
 
void loop() {
  val = digitalRead(pirPin);
  if (val == HIGH) {
    if (motionState == false) {
      Serial.println("Mouvement détecté !");
      motionState = true;
    }
  } else if (val == LOW) {
    if (motionState == true) {
      Serial.println("Mouvement non détecté !");
      motionState = false;
    }
  }
}
 
</syntaxhighlight><br />
}}
}}
{{Tuto Status
{{Tuto Status
|Complete=Draft
|Complete=Draft
}}
}}

Version du 27 avril 2023 à 13:46


Détecteur de Mouvement HC-SR501

Détecteur de mouvement PIR

0.72EUR (€)


Description longue

Il doit être alimenté en 5V

plus d'infos : https://pdf1.alldatasheet.fr/datasheet-pdf/view/1131987/ETC2/HC-SR501.html


Caractéristiques


  • alimentation maxi : 5V

Bibliothèque :

Pour utiliser le détecteur de mouvement il n'y a besoin d'aucunes bibliothèques

Câblage :

Item Motion Sensor HC-SR501

Le code minimal :

Motion Sensor HC SR-501
Avant le Setup Importation de la bibliothèque Aucunes bibliothèques
Création de l’objet #define pirPin <numéro de broche>; // je défini la broche

int val = LOW;

bool motionState = false;

Dans le Setup Démarrage de l’objet pinMode(pirPin, INPUT);
Dans le Loop Utilisation val = digitalRead(pirPin);

if (motionState == false)

Autres fonctionnalités

Aucune autres fonctionnalités

Exemple :

#define pirPin 2
int val = LOW; 
bool motionState = false;

void setup() {
  Serial.begin(9600);
  pinMode(pirPin, INPUT);
}

void loop() {
  val = digitalRead(pirPin);
  if (val == HIGH) {
    if (motionState == false) {
      Serial.println("Mouvement détecté !");
      motionState = true;
    }
  } else if (val == LOW) {
    if (motionState == true) {
      Serial.println("Mouvement non détecté !");
      motionState = false; 
    }
  }
}

Pages liées

Commentaires

Draft