Capteur de distance

Bonjour,

J’ai réalisé un capteur de distance pour détecter si une voiture est présente dans le garage (ou ailleurs).
Pour ceux que ça intéresse, je ne vais pas réalisé de tuto mais je partage rapidement ce que j’ai fais.

Matériel:
-ESP8266 (j’ai un type Wemos d1 Mini)
-Capteur Ă  ultrasons HC-SR04

Application:
-Homeyduino

Il faudra ensuite par le logiciel Arduino IDE (dispo sur Mac et Windows) paramétrer et téléverser le code ci dessous dans la carte ESP8266 (sans oublier modifier votre type de carte et de télécharger les librairies adaptées, le sujet est traité partout sur le web).

Fixer l’adresse IP de votre ESP8266 dans votre routeur/box internet (C’est du moins conseillé)

Ajouter un device depuis l’application Homeyduino, elle devrait détecter votre carte avec le nom que vous lui aurez donné.

J’espère que ça en aidera certains.

Bonne année 2022!

image

GOOGLE TRANSLATE:

Hello,

I made a distance sensor to detect if a car is present in the garage (or elsewhere).
For those who are interested, I will not do a tutorial but I quickly share what I have done.

Equipment:
-ESP8266 (I have a Wemos d1 Mini type)
-Hc-SR04 Ultrasonic Sensor

Application:
-Homeyduino

You will then have to use the Arduino IDE software (available on Mac and Windows) to configure and upload the code below in the ESP8266 card (without forgetting to change your card type and download the appropriate libraries, the subject is covered everywhere on the web) .

Set the IP address of your ESP8266 in your router / internet box (at least it is recommended)

Add a device from the Homeyduino application, it should detect your card with the name you have given it.

Hope this helps some.

Happy New Year 2022!




// Project: Get a distance measurement sensor with an ESP8266 Wemos d1 Mini board (ESP-12x) connected to a HC-SR04 Ultrasonic sensor


#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <Homey.h>
#include <HCSR04.h>




/*
                            MAPPING PINOUT

                           _________________
                         /   WEMOS d1 Mini   \
                        |                     |
                        |                     |
               1 -->    |o TX            RST o|
               3 -->    |o RX             A0 o|
               5 -->    |o D1             D0 o|    <-- 16
               4 -->    |o D2             D5 o|    <-- 14
               0 -->    |o D3             D6 o|    <-- 12
               2 -->    |o D4             D7 o|    <-- 13
                        |o G              D8 o|    <-- 15
                        |o 5v    _____   3v3 o|
                        |       |micro|       |
                        |_______|_usb_|_______| 
*/

UltraSonicDistanceSensor distanceSensor(12, 13);  // Initialize sensor that uses digital pins. The first number is Trigger and the Second is Echo. (Here Trigger is on 12 (D6) and Echo on 13 (D7) )



unsigned long previousMillis = 0;
const unsigned long interval = 5000; //Interval between two measures in milliseconds

void wifi() {
  if (WiFi.status() != WL_CONNECTED) {
    WiFi.begin("YOUR_SSID", "PASSWORD"); // Replace YOUR_SSID by your WiFi router's name and the PASSWORD by the password to connect to your WiFi
    uint8_t timeout = 30;
    while (WiFi.status() != WL_CONNECTED) {
      delay(500);
      Serial.println("connecting...");
      if (timeout<1) break;
    }
    if (WiFi.status() == WL_CONNECTED) {
      //Print IP address
      Serial.print("WiFi Connected! The IP adress is: ");
      Serial.print(WiFi.localIP());
      Serial.println("");
    }
  }
}

void setup() {
  Serial.begin(115200);
  Homey.begin("NAME");  // Replace NAME by the name you want use for your sensor
  Homey.setClass("sensor");
  Homey.addCapability("measure_rain");      //I give measure_rain capability because it's the only one who has a unit in millimeters. To note, It will be appear like a rain sensor. 
                                            //Device Capabilities can be found here: https://apps-sdk-v3.developer.homey.app/tutorial-device-capabilities.html 
}

void loop() {
  wifi();
  Homey.loop();
  unsigned long currentMillis = millis();
  if(currentMillis - previousMillis > interval) {
    previousMillis = currentMillis;
    updatesensor();
  }
}

void updatesensor() {
    int distance = distanceSensor.measureDistanceCm()*10; //Convert centimeters to millimeters
    Serial.print(distance);
    Serial.print(" mm ");
    Serial.println("");

  Homey.setCapabilityValue("measure_rain", (distance));
}
2 Likes

J’ai imprimé un boîtier pour tout mettre en place dedans et je l’ai installé sur la motorisation.
Le capteur est donné pour une mesure jusqu’à 3m j’obtiens 3730mm, j’ai mesuré avec un mètre et cette valeur est correcte.

Bonne journée.

===============================

  • I have printed a box to put everything in and i have installed it on the motorisation. The sensor is give for a measure up to 3 meters but i get 3730 millimeters and i have measured it with a measuring tape and the value is good.

Have a good day *