# Micro:bit - Capteur infrarouge (HC-SR04)

### <span class="JsGRdQ">[![Logo_POPcafe_Capsule.png](https://wiki.popcafe.pop.eu.com/uploads/images/gallery/2022-06/scaled-1680-/50cNLE8lhW3LFjXX-logo-popcafe-capsule.png)](https://wiki.popcafe.pop.eu.com/uploads/images/gallery/2022-06/50cNLE8lhW3LFjXX-logo-popcafe-capsule.png)</span>

### Interfacer un capteur HC-SRO4 sur Micro:bit et mesurer une distance  


[![1665072579746.jpg](https://wiki.popcafe.pop.eu.com/uploads/images/gallery/2022-10/scaled-1680-/CUEXF0OowK91hm0b-1665072579746.jpg)](https://wiki.popcafe.pop.eu.com/uploads/images/gallery/2022-10/CUEXF0OowK91hm0b-1665072579746.jpg)


[![Wifi.png](https://wiki.popcafe.pop.eu.com/uploads/images/gallery/2022-06/scaled-1680-/zXYBvxNd3JnFrt8G-plan-geometre.png)](https://wiki.popcafe.pop.eu.com/uploads/images/gallery/2022-06/PaA43o1HxxGF2tpG-wifi.png)

<table border="1" id="bkmrk-dur%C3%A9e%C2%A0-2h00-age%C2%A0-ado" style="border-collapse: collapse; width: 100%; height: 125.633px;"><tbody><tr style="height: 95.8333px;"><td style="width: 49.9383%; height: 95.8333px;">#### <span style="color: #0544db;">Durée </span>

20min

</td><td style="width: 49.9383%; height: 95.8333px;">#### <span style="color: #0544db;">Age</span> 

Dès 8 ans

</td></tr><tr style="height: 29.8px;"><td style="width: 49.9383%; height: 29.8px;">#### <span style="color: #0544db;">Nombre de participants</span>

De 1 à 10

</td><td style="width: 49.9383%; height: 29.8px;">#### <span style="color: #0544db;">Matériel</span>

- **Un ordinateur + Connexion internet**
- **Une carte micro:bit**
- **Un shield (Bitmaker)**
- **Un écran LCD avec connexion Grove**
- **Un capteur infrarouge HC-SR04**

</td></tr></tbody></table>

#### [![Smiley clin d'oeil.png](https://wiki.popcafe.pop.eu.com/uploads/images/gallery/2022-06/scaled-1680-/7gLuSLCyYkSxiMJq-smiley-interrogateur.png)](https://wiki.popcafe.pop.eu.com/uploads/images/gallery/2022-06/23QOI3ykXu9BKNy8-smiley-clin-doeil.png)<span style="color: #0544db;">**Intro et Enjeux pédagogiques**</span>

<span class="JsGRdQ" style="color: #000000;"><span class="JsGRdQ" style="font-style: normal; text-decoration: none;"><span class="JsGRdQ" style="font-weight: 400; font-style: normal; text-decoration: none;">L'atelier vise à être autonome dans la mise en place d'un dispositif permettant de mesurer une distance / détecter une présence via l'interface de Vittascience.  
</span></span></span>


#### <span class="JsGRdQ">[![Fusée.png](https://wiki.popcafe.pop.eu.com/uploads/images/gallery/2022-06/scaled-1680-/yL0gfoLhzr5Yju9U-fusee.png)](https://wiki.popcafe.pop.eu.com/uploads/images/gallery/2022-06/yL0gfoLhzr5Yju9U-fusee.png)</span><span class="JsGRdQ">**<span style="color: #0544db;">L'atelier</span>** </span>

#### <span class="JsGRdQ">Déroulé :</span>

1. <span class="JsGRdQ" style="color: #000000; font-weight: 400; font-style: normal; text-decoration: none;"><span class="JsGRdQ" style="color: #000000; font-weight: 400; font-style: normal; text-decoration: none;"><span class="JsGRdQ" style="color: #000000; font-weight: 400; font-style: normal; text-decoration: none;">Connecter le micro:bit sur le shield.</span></span></span>
2. <span class="JsGRdQ" style="color: #000000; font-weight: 400; font-style: normal; text-decoration: none;"><span class="JsGRdQ" style="color: #000000; font-weight: 400; font-style: normal; text-decoration: none;"><span class="JsGRdQ" style="color: #000000; font-weight: 400; font-style: normal; text-decoration: none;"><span class="JsGRdQ" style="color: #000000; font-weight: 400; font-style: normal; text-decoration: none;">Brancher un câble grove / jumper femelle sur la sortie P0 du shield.  
    </span></span></span></span>[![1665070042396.jpg](https://wiki.popcafe.pop.eu.com/uploads/images/gallery/2022-10/scaled-1680-/1C01pqcKiCsRBAP9-1665070042396.jpg)](https://wiki.popcafe.pop.eu.com/uploads/images/gallery/2022-10/1C01pqcKiCsRBAP9-1665070042396.jpg)
3. <span class="JsGRdQ" style="color: #000000; font-weight: 400; font-style: normal; text-decoration: none;"><span class="JsGRdQ" style="color: #000000; font-weight: 400; font-style: normal; text-decoration: none;"><span class="JsGRdQ" style="color: #000000; font-weight: 400; font-style: normal; text-decoration: none;">Brancher le câble rouge (VCC) au pin VCC du capteur ultrason.</span></span></span>
4. <span class="JsGRdQ" style="color: #000000; font-weight: 400; font-style: normal; text-decoration: none;"><span class="JsGRdQ" style="color: #000000; font-weight: 400; font-style: normal; text-decoration: none;"><span class="JsGRdQ" style="color: #000000; font-weight: 400; font-style: normal; text-decoration: none;">Brancher le câble noir (GND) au pin GND du capteur ultrason.</span></span></span>
5. <span class="JsGRdQ" style="color: #000000; font-weight: 400; font-style: normal; text-decoration: none;"><span class="JsGRdQ" style="color: #000000; font-weight: 400; font-style: normal; text-decoration: none;"><span class="JsGRdQ" style="color: #000000; font-weight: 400; font-style: normal; text-decoration: none;">Brancher le câble jaune au pin Echo du capteur ultrason.</span></span></span>
6. <span class="JsGRdQ" style="color: #000000; font-weight: 400; font-style: normal; text-decoration: none;"><span class="JsGRdQ" style="color: #000000; font-weight: 400; font-style: normal; text-decoration: none;"><span class="JsGRdQ" style="color: #000000; font-weight: 400; font-style: normal; text-decoration: none;"><span class="JsGRdQ" style="color: #000000; font-weight: 400; font-style: normal; text-decoration: none;">Brancher le câble blanc au pin Trig du capteur ultrason.  
    </span></span></span></span>[![1665070042369.jpg](https://wiki.popcafe.pop.eu.com/uploads/images/gallery/2022-10/scaled-1680-/wFSPXxKnpuXdN3Xx-1665070042369.jpg)](https://wiki.popcafe.pop.eu.com/uploads/images/gallery/2022-10/wFSPXxKnpuXdN3Xx-1665070042369.jpg)
    
    <span class="JsGRdQ" style="color: #000000; font-weight: 400; font-style: normal; text-decoration: none;"><span class="JsGRdQ" style="color: #000000; font-weight: 400; font-style: normal; text-decoration: none;"><span class="JsGRdQ" style="color: #000000; font-weight: 400; font-style: normal; text-decoration: none;">  
    </span></span></span>
7. <span class="JsGRdQ" style="color: #000000; font-weight: 400; font-style: normal; text-decoration: none;"><span class="JsGRdQ" style="color: #000000; font-weight: 400; font-style: normal; text-decoration: none;"><span class="JsGRdQ" style="color: #000000; font-weight: 400; font-style: normal; text-decoration: none;">Aller sur la plateforme en ligne [Vittascience](https://fr.vittascience.com).</span></span></span>
8. <span class="JsGRdQ" style="color: #000000; font-weight: 400; font-style: normal; text-decoration: none;"><span class="JsGRdQ" style="color: #000000; font-weight: 400; font-style: normal; text-decoration: none;"><span class="JsGRdQ" style="color: #000000; font-weight: 400; font-style: normal; text-decoration: none;">Dans la catégorie "Variables", créer une variable "Distance". Ajouter ensuite "affecter à Distance la valeur 0".  
    [![image.png](https://wiki.popcafe.pop.eu.com/uploads/images/gallery/2022-10/scaled-1680-/OKS15LPoUVXVjcsn-image.png)](https://wiki.popcafe.pop.eu.com/uploads/images/gallery/2022-10/OKS15LPoUVXVjcsn-image.png)  
    </span></span></span>
9. <span class="JsGRdQ" style="color: #000000; font-weight: 400; font-style: normal; text-decoration: none;"><span class="JsGRdQ" style="color: #000000; font-weight: 400; font-style: normal; text-decoration: none;"><span class="JsGRdQ" style="color: #000000; font-weight: 400; font-style: normal; text-decoration: none;"><span class="JsGRdQ" style="color: #000000; font-weight: 400; font-style: normal; text-decoration: none;">Dans la catégorie "Capteurs", dans la sous-catégorie "Capteur de distance et mouvement" glisser/déposer le bloc "Capteur à ultrason" dans le bloc précédent.  
    </span></span></span></span>[![image.png](https://wiki.popcafe.pop.eu.com/uploads/images/gallery/2022-10/scaled-1680-/VI0YPWZ9zfqT6OTN-image.png)](https://wiki.popcafe.pop.eu.com/uploads/images/gallery/2022-10/VI0YPWZ9zfqT6OTN-image.png)
    
    <span class="JsGRdQ" style="color: #000000; font-weight: 400; font-style: normal; text-decoration: none;"><span class="JsGRdQ" style="color: #000000; font-weight: 400; font-style: normal; text-decoration: none;"><span class="JsGRdQ" style="color: #000000; font-weight: 400; font-style: normal; text-decoration: none;"><span class="JsGRdQ" style="color: #000000; font-weight: 400; font-style: normal; text-decoration: none;">  
    </span></span></span></span>[![image.png](https://wiki.popcafe.pop.eu.com/uploads/images/gallery/2022-10/scaled-1680-/IZSYeqJRMrcYdcJF-image.png)](https://wiki.popcafe.pop.eu.com/uploads/images/gallery/2022-10/IZSYeqJRMrcYdcJF-image.png)
    
    <span class="JsGRdQ" style="color: #000000; font-weight: 400; font-style: normal; text-decoration: none;"><span class="JsGRdQ" style="color: #000000; font-weight: 400; font-style: normal; text-decoration: none;"><span class="JsGRdQ" style="color: #000000; font-weight: 400; font-style: normal; text-decoration: none;">  
    </span></span></span>
10. Changer "Grove" en "HC-SR04" si votre capteur n'est pas grove.
11. Changer les pin TRIG et ECHO selon les valeurs inscrites sur le shield. Le câble jaune a été branché au pin Echo. Sur la photo, le câble jaune est relié au pin P0. Le câble blanc (Trig) est sur le pin P1. Les valeurs du capteurs seront alors envoyés dans la variable "Distance".  
    [![1665070042396.jpg](https://wiki.popcafe.pop.eu.com/uploads/images/gallery/2022-10/scaled-1680-/OiQivnKuqMiKK5gt-1665070042396.jpg)](https://wiki.popcafe.pop.eu.com/uploads/images/gallery/2022-10/OiQivnKuqMiKK5gt-1665070042396.jpg)
    
    [![image.png](https://wiki.popcafe.pop.eu.com/uploads/images/gallery/2022-10/scaled-1680-/tIYJM4C3eNYk3MSf-image.png)](https://wiki.popcafe.pop.eu.com/uploads/images/gallery/2022-10/tIYJM4C3eNYk3MSf-image.png)
12. <span class="JsGRdQ" style="color: #000000; font-weight: 400; font-style: normal; text-decoration: none;"><span class="JsGRdQ" style="color: #000000; font-weight: 400; font-style: normal; text-decoration: none;"><span class="JsGRdQ" style="color: #000000; font-weight: 400; font-style: normal; text-decoration: none;"><span class="JsGRdQ" style="color: #000000; font-weight: 400; font-style: normal; text-decoration: none;">Pour interfacer l'écran LCD, suivre la [fiche atelier de l'écran LCD](https://wiki.popcafe.pop.eu.com/books/transition-ecologique/page/microbit-ecran-lcd-pour-temperature).  
    </span></span></span></span>[![image.png](https://wiki.popcafe.pop.eu.com/uploads/images/gallery/2022-10/scaled-1680-/K5p0iExh7RCIHIvI-image.png)](https://wiki.popcafe.pop.eu.com/uploads/images/gallery/2022-10/K5p0iExh7RCIHIvI-image.png)
    
    <span class="JsGRdQ" style="color: #000000; font-weight: 400; font-style: normal; text-decoration: none;"><span class="JsGRdQ" style="color: #000000; font-weight: 400; font-style: normal; text-decoration: none;"><span class="JsGRdQ" style="color: #000000; font-weight: 400; font-style: normal; text-decoration: none;">  
    </span></span></span>
13. Dans la catégorie "Logique", choisir le bloc "Si...Alors...Sinon".
    
    [![image.png](https://wiki.popcafe.pop.eu.com/uploads/images/gallery/2022-10/scaled-1680-/S70mgU7OEOD5IGeK-image.png)](https://wiki.popcafe.pop.eu.com/uploads/images/gallery/2022-10/S70mgU7OEOD5IGeK-image.png)
    
    [![image.png](https://wiki.popcafe.pop.eu.com/uploads/images/gallery/2022-10/scaled-1680-/VjdZAx4DuaPmrwtD-image.png)](https://wiki.popcafe.pop.eu.com/uploads/images/gallery/2022-10/VjdZAx4DuaPmrwtD-image.png)
14. Dans la catégorie "Variables", trouver "Distance" et l'insérer dans la boucle si. Changer la valeur comparative en "inférieur à 50".  
    [![image.png](https://wiki.popcafe.pop.eu.com/uploads/images/gallery/2022-10/scaled-1680-/TOYbrBfliwXFYUFy-image.png)](https://wiki.popcafe.pop.eu.com/uploads/images/gallery/2022-10/TOYbrBfliwXFYUFy-image.png)
15. Définir l'action à faire lorsque la distance est inférieure à 50cm et celle à faire si c'est supérieur à 50cm: jouer un son, déclencher un moteur etc. Par exemple, il est possible de changer l’icône affichée sur la carte micro:bit.
16. Dans la catégorie "Affichage", choisir le bloc "Afficher l'icone" et choisir les icônes.  
    [![image.png](https://wiki.popcafe.pop.eu.com/uploads/images/gallery/2022-10/scaled-1680-/q2jHOHL2sPlhmP8k-image.png)](https://wiki.popcafe.pop.eu.com/uploads/images/gallery/2022-10/q2jHOHL2sPlhmP8k-image.png)
    
    [![image.png](https://wiki.popcafe.pop.eu.com/uploads/images/gallery/2022-10/scaled-1680-/QFss772ZuHVv537c-image.png)](https://wiki.popcafe.pop.eu.com/uploads/images/gallery/2022-10/QFss772ZuHVv537c-image.png)
17. Télécharger le programme et le copier/ coller sur le micro:bit (Cf. <span class="JsGRdQ" style="color: #000000; font-weight: 400; font-style: normal; text-decoration: none;">la [fiche atelier de l'écran LCD](https://wiki.popcafe.pop.eu.com/books/transition-ecologique/page/microbit-ecran-lcd-pour-temperature)).</span>
18. <span class="JsGRdQ" style="color: #000000; font-weight: 400; font-style: normal; text-decoration: none;"><span class="JsGRdQ" style="color: #000000; font-weight: 400; font-style: normal; text-decoration: none;">Expérimenter  
    </span></span>[![1665072579746.jpg](https://wiki.popcafe.pop.eu.com/uploads/images/gallery/2022-10/scaled-1680-/bn0rCpdNAO8EevAJ-1665072579746.jpg)](https://wiki.popcafe.pop.eu.com/uploads/images/gallery/2022-10/bn0rCpdNAO8EevAJ-1665072579746.jpg)
    
    [![1665072579734.jpg](https://wiki.popcafe.pop.eu.com/uploads/images/gallery/2022-10/scaled-1680-/kYjeVdQQEYj4GSSU-1665072579734.jpg)](https://wiki.popcafe.pop.eu.com/uploads/images/gallery/2022-10/kYjeVdQQEYj4GSSU-1665072579734.jpg)

<table border="1" id="bkmrk-les-%2B-les--" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 49.9383%;">[![Smiley Exalté.png](https://wiki.popcafe.pop.eu.com/uploads/images/gallery/2022-06/scaled-1680-/D0jQCBxptk9QCUKS-smiley-exalte.png)](https://wiki.popcafe.pop.eu.com/uploads/images/gallery/2022-06/D0jQCBxptk9QCUKS-smiley-exalte.png)</td><td style="width: 49.9383%;">[![Smiley Contrarié.png](https://wiki.popcafe.pop.eu.com/uploads/images/gallery/2022-06/scaled-1680-/rIjW0obvLw23cZvb-smiley-contrarie.png)](https://wiki.popcafe.pop.eu.com/uploads/images/gallery/2022-06/rIjW0obvLw23cZvb-smiley-contrarie.png)</td></tr><tr><td style="width: 49.9383%;">#### LES +

</td><td style="width: 49.9383%;">#### LES -

</td></tr><tr><td style="width: 49.9383%;"><span class="JsGRdQ" style="color: #162383; font-weight: 400; font-style: normal; text-decoration: none;">Rapide<span style="color: #000000;">  
</span></span>

<span class="JsGRdQ" style="color: #162383; font-weight: 400; font-style: normal; text-decoration: none;">Facile</span>

<span class="JsGRdQ" style="color: #162383; font-weight: 400; font-style: normal; text-decoration: none;">Pas de code</span>

</td><td style="width: 49.9383%;"><span class="JsGRdQ" style="color: #162383; font-weight: 400; font-style: normal; text-decoration: none;">Basique<span style="color: #000000;">  
</span></span>

<span class="JsGRdQ" style="color: #162383; font-weight: 400; font-style: normal; text-decoration: none;">Nécessite un boitier afin de faire un dispositif propre</span>

</td></tr></tbody></table>