Ce projet ESP32 est un moyen passionnant et interactif de contrôler les LED à l’aide de gestes de la main. Nous utiliserons une carte ESP32, Python, Medioppe et OpenCV pour créer un système qui peut détecter des gestes de main spécifiques et les traduire en actions qui contrôlent les LED. Medioppe sera utilisé pour reconnaître les gestes de la main, tandis que OpenCV capturera le flux vidéo en temps réel à partir d’une webcam. Sur la base des gestes (tels que des mouvements de main, de poing ou de doigts), les commandes seront envoyées à l’ESP32, qui contrôleront les LED connectées. Cela nous permettra d’allumer et de désactiver les LED, de modifier leur luminosité, ou même de contrôler différentes LED avec des gestes spécifiques. C’est une façon pratique et amusante d’apprendre la reconnaissance des gestes, le contrôle du matériel et la communication entre Python et les microcontrôleurs.
https://www.youtube.com/watch?v=m0wuhyfhroq


#include
#include
const char* ssid = "Wifi_name";
const char* password = "Wifi_password";
AsyncWebServer server(80);
// Define GPIO pins for LEDs
const int thumbLedPin = 27;
const int indexLedPin = 26;
const int middleLedPin = 25;
const int ringLedPin = 33;
const int pinkyLedPin = 32;
void setup() {
Serial.begin(115200);
pinMode(thumbLedPin, OUTPUT);
pinMode(indexLedPin, OUTPUT);
pinMode(middleLedPin, OUTPUT);
pinMode(ringLedPin, OUTPUT);
pinMode(pinkyLedPin, OUTPUT);
digitalWrite(thumbLedPin, LOW);
digitalWrite(indexLedPin, LOW);
digitalWrite(middleLedPin, LOW);
digitalWrite(ringLedPin, LOW);
digitalWrite(pinkyLedPin, LOW);
Serial.println("Connecting to WiFi...");
WiFi.begin(ssid, password);
int attempts = 0;
while (WiFi.status() != WL_CONNECTED && attempts < 20) { // Try for 20 seconds
delay(1000);
Serial.print(".");
attempts++;
}
if (WiFi.status() == WL_CONNECTED) {
Serial.println("\nConnected to WiFi");
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());
// Define HTTP request handlers for each LED
server.on("/led/thumb/on", HTTP_GET, [](AsyncWebServerRequest *request){
digitalWrite(thumbLedPin, HIGH);
request->send(200, "text/plain", "Price - 300");
});
server.on("/led/thumb/off", HTTP_GET, [](AsyncWebServerRequest *request){
digitalWrite(thumbLedPin, LOW);
request->send(200, "text/plain", "Thumb LED is OFF");
});
server.on("/led/index/on", HTTP_GET, [](AsyncWebServerRequest *request){
digitalWrite(indexLedPin, HIGH);
request->send(200, "text/plain", "Index finger LED is ON");
});
server.on("/led/index/off", HTTP_GET, [](AsyncWebServerRequest *request){
digitalWrite(indexLedPin, LOW);
request->send(200, "text/plain", "Index finger LED is OFF");
});
server.on("/led/middle/on", HTTP_GET, [](AsyncWebServerRequest *request){
digitalWrite(middleLedPin, HIGH);
request->send(200, "text/plain", "Middle finger LED is ON");
});
server.on("/led/middle/off", HTTP_GET, [](AsyncWebServerRequest *request){
digitalWrite(middleLedPin, LOW);
request->send(200, "text/plain", "Middle finger LED is OFF");
});
server.on("/led/ring/on", HTTP_GET, [](AsyncWebServerRequest *request){
digitalWrite(ringLedPin, HIGH);
request->send(200, "text/plain", "Ring finger LED is ON");
});
server.on("/led/ring/off", HTTP_GET, [](AsyncWebServerRequest *request){
digitalWrite(ringLedPin, LOW);
request->send(200, "text/plain", "Ring finger LED is OFF");
});
server.on("/led/pinky/on", HTTP_GET, [](AsyncWebServerRequest *request){
digitalWrite(pinkyLedPin, HIGH);
request->send(200, "text/plain", "Pinky finger LED is ON");
});
server.on("/led/pinky/off", HTTP_GET, [](AsyncWebServerRequest *request){
digitalWrite(pinkyLedPin, LOW);
request->send(200, "text/plain", "Pinky finger LED is OFF");
});
server.begin();
Serial.println("Server started");
} else {
Serial.println("\nFailed to connect to WiFi");
}
}
void loop() {
// Additional code can be added here if needed, but typically not necessary for basic HTTP server operations.
}
import cv2
import mediapipe as mp
import requests
# ESP32 Base URL
ESP32_IP = "http://192.168.137.123" # Change this to your ESP32 IP address
# Initialize MediaPipe Hands
mp_hands = mp.solutions.hands
hands = mp_hands.Hands()
mp_drawing = mp.solutions.drawing_utils
# Function to send hand gesture commands to ESP32
def control_led(endpoint):
url = f"{ESP32_IP}/cart/{endpoint}"
try:
response = requests.get(url)
print(f"Sent command: {endpoint}, ESP32 Response: {response.text}")
except Exception as e:
print(f"Failed to send command: {endpoint}, Error: {e}")
# Function to fetch commands from ESP32
def fetch_esp32_command():
try:
url = f"{ESP32_IP}/command"
response = requests.get(url)
return response.text.strip()
except Exception as e:
print(f"Error fetching command from ESP32: {e}")
return None
# Function to detect the state of each finger
def count_fingers(hand_landmarks):
# Detect finger states (up or down)
thumb_up = hand_landmarks.landmark[mp_hands.HandLandmark.THUMB_TIP].x < hand_landmarks.landmark[mp_hands.HandLandmark.THUMB_IP].x
index_up = hand_landmarks.landmark[mp_hands.HandLandmark.INDEX_FINGER_TIP].y < hand_landmarks.landmark[mp_hands.HandLandmark.INDEX_FINGER_PIP].y
middle_up = hand_landmarks.landmark[mp_hands.HandLandmark.MIDDLE_FINGER_TIP].y < hand_landmarks.landmark[mp_hands.HandLandmark.MIDDLE_FINGER_PIP].y
ring_up = hand_landmarks.landmark[mp_hands.HandLandmark.RING_FINGER_TIP].y < hand_landmarks.landmark[mp_hands.HandLandmark.RING_FINGER_PIP].y
pinky_up = hand_landmarks.landmark[mp_hands.HandLandmark.PINKY_TIP].y < hand_landmarks.landmark[mp_hands.HandLandmark.PINKY_PIP].y
# Combine finger statuses into a list
finger_status = [thumb_up, index_up, middle_up, ring_up, pinky_up]
# Send control commands to ESP32 for each finger
control_led("add" if thumb_up else "remove")
control_led("index/on" if index_up else "index/off")
control_led("middle/on" if middle_up else "middle/off")
# Check if all fingers are down
if not any(finger_status):
print("All fingers are down") # Message when all fingers are down
control_led("all/down") # Example action when all fingers are down
return finger_status
# Initialize VideoCapture
cap = cv2.VideoCapture(1)
while cap.isOpened():
ret, frame = cap.read()
if not ret:
break
frame = cv2.flip(frame, 1)
frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
# Detect hand landmarks
results = hands.process(frame_rgb)
if results.multi_hand_landmarks:
for hand_landmarks in results.multi_hand_landmarks:
mp_drawing.draw_landmarks(frame, hand_landmarks, mp_hands.HAND_CONNECTIONS)
fingers = count_fingers(hand_landmarks)
# Fetch and display command from ESP32
esp32_command = fetch_esp32_command()
if esp32_command:
cv2.putText(frame, f"ESP32 Command: {esp32_command}", (10, 50), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 255, 0), 2)
cv2.imshow('Hand Gesture Recognition', frame)
if cv2.waitKey(5) & 0xFF == 27: # Exit on pressing 'Esc'
break
cap.release()
cv2.destroyAllWindows()

Voici le lien vers notre repo GitHub, où vous trouverez le code source de ce projet.
Projets similaires utilisant des systèmes de contrôle des gestes

Robot contrôlé par geste utilisant Arduino
Découvrez comment construire un robot contrôlé par des gestes à l’aide d’Arduino, vous permettant de contrôler ses mouvements avec des gestes de la main simples. Ce projet démontre l’intégration des capteurs et de la communication sans fil pour un système robotique interactif et innovant.

Bras robotique contrôlé à la main à l’aide d’Arduino Nano
Découvrez comment construire un bras robotique qui fonctionne à travers des gestes de la main à l’aide d’un arduino nano et d’un capteur MPU6050. Ce projet fournit un guide étape par étape pour mettre en œuvre un contrôle basé sur les gestes, ce qui rend la robotique plus interactive et intuitive.



Retrouvez l’histoire de Raspberry Pi dans cette vidéo :
-
Freenove ESP32 Kit de Carte de Développement (Pack 2), Développement de Microcontrôleur à Double Noyau 32 Bits 240 MHz, WiFi+BT Embarqué, Code Python C, Exemple de Projets Tutorial
-
Ulegqin ESP32 S3 ESP-S3-Devkitc-1 N16R8 Carte mère avec IPEX Interface ESP32 S3 Module avec WiFi, Bluetooth 5.0 Extension de mémoire Externe Typ-C Interface Compatible avec Arduino(2 Pièces)
