#include <BluetoothSerial.
h>
BluetoothSerial BT;
// ── Pins HB100 ──────────────────────
#define HB100_PIN 34 // DO du module
// ── Pins HC-SR04 ────────────────────
#define TRIG_PIN 5
#define ECHO_PIN 18
// ── Pins moteurs ────────────────────
#define MOT_L_A 25
#define MOT_L_B 26
#define MOT_R_A 27
#define MOT_R_B 14
// ── Filtre anti micro-vibrations ────
int compteurPresence = 0;
#define SEUIL_FILTRE 5 // 5 lectures positives consécutives
long lireDistance() {
digitalWrite(TRIG_PIN, LOW); delayMicroseconds(2);
digitalWrite(TRIG_PIN, HIGH); delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
long duree = pulseIn(ECHO_PIN, HIGH, 30000);
return duree * 0.034 / 2;
void stopMoteurs() {
digitalWrite(MOT_L_A, LOW); digitalWrite(MOT_L_B, LOW);
digitalWrite(MOT_R_A, LOW); digitalWrite(MOT_R_B, LOW);
void setup() {
[Link](115200);
[Link]("Robot_Tondeuse");
pinMode(HB100_PIN, INPUT);
pinMode(TRIG_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
pinMode(MOT_L_A, OUTPUT); pinMode(MOT_L_B, OUTPUT);
pinMode(MOT_R_A, OUTPUT); pinMode(MOT_R_B, OUTPUT);
void loop() {
// ── FILTRE HB100 (anti-vibrations) ──
if (digitalRead(HB100_PIN) == HIGH) {
compteurPresence++;
} else {
compteurPresence = 0; // reset si plus de signal
}
bool presenceConfirmee = (compteurPresence >= SEUIL_FILTRE);
// ── Priorité 1 : Présence humaine ──
if (presenceConfirmee) {
stopMoteurs();
[Link]("⚠ PRESENCE DETECTEE — Robot arrêté !");
[Link]("HB100: Présence confirmée");
delay(3000);
compteurPresence = 0;
return;
// ── Priorité 2 : Obstacle proche ──
long distance = lireDistance();
if (distance > 0 && distance < 30) {
stopMoteurs();
[Link]("🚧 OBSTACLE à " + String(distance) + " cm");
delay(500);
return;
// ── Priorité 3 : Commandes téléphone ──
if ([Link]()) {
char cmd = [Link]();
if (cmd == 'F') { /* avancer */ }
else if (cmd == 'B') { /* reculer */ }
else if (cmd == 'S') { stopMoteurs(); }
delay(50);