| Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente |
| materiels:capteurs:distance:distus [2024/05/03 12:03] – [2.3 HC-SR04P (GPIO - I2C - UART)] phil | materiels:capteurs:distance:distus [2025/06/19 19:30] (Version actuelle) – modification externe 127.0.0.1 |
|---|
| ===== Capteurs - Distance - Ultrasons ===== | ===== Capteurs - Distance - Ultrasons ===== |
| |
| [Mise à jour le 3/5/2024] | [Mise à jour le 25/6/2024] |
| |
| * **Lectures connexes** | * **Lectures connexes** |
| } | } |
| </code> | </code> |
| | |
| |
| {{ :arduino:uc:platformioico.png?nolink&50|}} | {{ :arduino:uc:platformioico.png?nolink&50|}} |
| | |
| |
| === 2.2 Module VMA306 à capteur HC-SR05 === | === 2.2 HC-SR05 (GPIO) === |
| {{ :materiels:capteurs:hc-scr05.png?nolink&150|VMA306}} | {{ :materiels:capteurs:hc-scr05.png?nolink&150|VMA306}} |
| |
| | == 2.2.1 Présentation == |
| * //**Source**// : <html><a href="https://www.velleman.eu/downloads/29/vma306_a4v01.pdf" target="_blank">pdf</a></html> | * //**Source**// : <html><a href="https://www.velleman.eu/downloads/29/vma306_a4v01.pdf" target="_blank">pdf</a></html> |
| |
| * //Connexion à un shield// <html><a href="https://webge.fr/doc/wikis/pdf/TinkerkitV2.pdf" target="_blank">Tinkerkit v2</a></html>. {{ :materiels:capteurs:hcsr05.jpg?nolink&600 |}} | * //Connexion à un shield// <html><a href="https://webge.fr/doc/wikis/pdf/TinkerkitV2.pdf" target="_blank">Tinkerkit v2</a></html>. {{ :materiels:capteurs:hcsr05.jpg?nolink&600 |}} |
| * // Un premier exemple // {{ :materiels:capteurs:distance:arduinoico.png?nolink&30|}} | * // Un premier exemple // {{ :materiels:capteurs:distance:arduinoico.png?nolink&30|}} |
| <file cpp HCSR05.cpp> | <code cpp HCSR05.cpp> |
| /////////////////////////////////////////////// | /////////////////////////////////////////////// |
| // Programme test pour capteur HC-SR05 // | // Programme test pour capteur HC-SR05 // |
| // Go Tronic 2017 // | // Go Tronic 2017 // |
| /////////////////////////////////////////////// | /////////////////////////////////////////////// |
| #define trigPin 10 // Tinkerkit O1 | #define trigPin 10 // Tinkerkit O1 |
| delay(500); // délai entre deux mesures | delay(500); // délai entre deux mesures |
| } | } |
| </file> | </code> |
| |
| |
| |
| === 2.3 HC-SR04P (GPIO - I2C - UART) === | === 2.3 HC-SR04P (GPIO - I2C - UART) === |
| {{ :materiels:capteurs:hc-scr05.png?nolink&150|VMA306}} | {{ :materiels:capteurs:distance:hc-sr04p.png?nolink&150|JOY-IT HC-SR04P}} |
| |
| == 2.3.1 Présentation == | == 2.3.1 Présentation == |
| * Connecteur mâle 4 broches coudé pré-soudé (pas 2,54 mm): Vcc/Trig/Echo/GND | * Connecteur mâle 4 broches coudé pré-soudé (pas 2,54 mm): Vcc/Trig/Echo/GND |
| * Dimensions: 45,5 x 20,3 x 15,5 mm | * Dimensions: 45,5 x 20,3 x 15,5 mm |
| | |
| | * //**Configuration**// de M1 et M2 sur le CI (1 : R=10k à ajouter) \\ **M1 M2** \\ 0 0 : GPIO \\ 1 0 : I2C \\ 1 1 : 1-wire \\ 0 1 : UART \\ |
| |
| {{ :materiels:capteurs:acrobate.gif?nolink&30|}} | {{ :materiels:capteurs:acrobate.gif?nolink&30|}} |
| * //**Documentation**// | * //**Documentation**// |
| * Fichier Acrobat Reader à télécharger <html><a href="https://webge.fr/doc/projets/datasheets/SEN-US01.pdf" target="_blank">ici</a></html> | * A télécharger <html><a href="https://webge.fr/doc/projets/datasheets/SEN-US01.pdf" target="_blank"><b>ici</a></b></html> |
| | |
| | {{ :materiels:capteurs:environnement:iconechronogrammes.png?nolink&50|}} |
| | * //**Chronogrammes**// |
| | * Relevé des signaux du bus I2C. A télécharger <html><a href="https://webge.fr/doc/wikis/img/Mesures_HCSR04.zip" target="_blank"><b>ici</b></a></html>. |
| |
| \\ | \\ |
| |
| | {{ :materiels:capteurs:environnement:code.png?nolink|}} |
| == 2.3.2 Exemples de code == | == 2.3.2 Exemples de code == |
| <tabs> | <tabs> |
| |
| <pane id="tab-hcsr04pduinogpio_1"> | <pane id="tab-hcsr04pduinogpio_1"> |
| * //**Ressources**// : <html><a href="https://www.arduino.cc/reference/en/language/functions/digital-io/pinmode/" target="_blank">pinMode()</a></html> | <html><a href="https://www.arduino.cc/reference/en/language/functions/advanced-io/pulsein/" target="_blank">pulseIn()</a></html> | <html><a href="https://www.arduino.cc/reference/en/language/functions/communication/serial/" target="_blank">serial</a></html> | * //**Ressources**// |
| | * <html><a href="https://www.arduino.cc/reference/en/language/functions/digital-io/pinmode/" target="_blank">pinMode()</a></html> | <html><a href="https://www.arduino.cc/reference/en/language/functions/advanced-io/pulsein/" target="_blank">pulseIn()</a></html> | <html><a href="https://www.arduino.cc/reference/en/language/functions/communication/serial/" target="_blank">serial</a></html> |
| | * //**Fiche guide**// pour l'étude d'une chaîne d'information comprenant un **HCSR04P** <html><a href="https://webge.fr/doc/projets/tsin/0_Fiches guide TSIN/TSIN_FGA_HCSR04P.zip">[Télécharger]</a></html> |
| | |
| | * //**Connexion**// à une <html><a href="https://wiki.seeedstudio.com/Base_Shield_V2/" target="_blank">Base Shield V2</a></html> montée sur une Arduino Uno \\ <html><span style="color:red">A venir</span></html> |
| |
| * //**Exemple** utilisant les **GPIO** pour tester le capteur// | * //**Exemple** utilisant les **GPIO** pour tester le capteur// |
| duration = pulseIn(echo, HIGH); | duration = pulseIn(echo, HIGH); |
| distance = duration * 340 / 2 / 10000; | distance = duration * 340 / 2 / 10000; |
| if (distance < 2 || distance > 450) { // On vérifie si la valeur mesurée se situe dans l'intervalle prévu | Serial.println("distance: " + String(distance) + " cm"); // Affichage dans la console |
| Serial.println("Distance en dehors de l'intervalle de mesure"); | |
| } else { | |
| Serial.println("distance: " + String(distance) + " cm"); // Affichage dans la console | |
| } | |
| delay(3000); // Attente entre 2 mesures | delay(3000); // Attente entre 2 mesures |
| } | } |
| |
| <pane id="tab-hcsr04pduinoi2c_1"> | <pane id="tab-hcsr04pduinoi2c_1"> |
| * //**Ressource**// : <html><a href="https://www.arduino.cc/reference/en/language/functions/communication/wire/" target="_blank">Wire</a></html> | * //**Ressources**// |
| | * <html><a href="https://www.arduino.cc/reference/en/language/functions/communication/wire/" target="_blank">Wire</a></html> |
| | {{ :materiels:capteurs:intensite:doc.gif?nolink|}} |
| |
| * //**Exemple** utilisant l'**I2C** pour tester le capteur// | * //**Exemple** utilisant l'**I2C** pour tester le capteur// |