story
story

Arduino and Python Project for School Exhibition: LEDs Light Up with Camera-Detected Hand Signals

Arduino and Python Project for School Exhibition: LEDs Light Up with Camera-Detected Hand Signals

Arduino and Python Project for School Exhibition: LEDs Light Up with Camera-Detected Hand Signals:

At the age of 15, I created a device that translates hand gesture information using OpenCV and MediaPipe libraries in Python. After processing the hand signals to determine the number of raised fingers, I programmed the device to send a corresponding signal to an Arduino using the cvzone library. This enabled communication with an Arduino device controlling LEDs. Using Python on a Raspberry Pi or a computer, the device processes the signals and lights up a specific number of LEDs based on the gesture detected. For instance, if the gesture indicates '3', three LEDs will light up according to the predefined code in Arduino

information about the project :

python code :
					
#made by oussama taliuan

from cvzone.SerialModule import SerialObject
import cv2
import mediapipe as mp
import time

import serial

#ser = serial.Serial("COM7",9600,timeout=1)


#define arduino
arduino = SerialObject("COM3")

cap = cv2.VideoCapture(0)


mpHands = mp.solutions.hands
hands = mpHands.Hands()
mpDraw = mp.solutions.drawing_utils # من اجل مساعدةعلى الحصول على قيمة نقاط

pTime = 0
cTime = 0


idDe = [8,12,16,20]

idDeN = [6,10,14,18]
reelnum=0

cyn=0
cym=0

rees=[0,0]

cxm = 0
cxn = 0

cx6 = 0

numHand = 0
while True:
    success, img = cap.read()

    #BRG to RGB
    imgRGB = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
    #من اجل معالجة صورة RGB
    results = hands.process(imgRGB)

    if results.multi_hand_landmarks: # اذا قام بايجاد يد على الكمرة
        for handLms in results.multi_hand_landmarks: # للحصول على معلومات لكل يد تضهر
            for id, lm in enumerate(handLms.landmark):# # للجصول على معلم و رقم نقطة
                #print(id, lm)

                h, w, c = img.shape # ارتفاع و العرض و القنواة
                cx, cy = int(lm.x * w), int(lm.y * h)
                #print(id, cx, cy)
                cv2.circle(img, (cx, cy), 15, (255, 0, 255), cv2.FILLED)

                numHand = 0

                if id==4:
                    cxm = cx
                if id==2:
                    cxn=cx
                if id == 20 :
                    cx6 = cx;
                if cxn cxm and cx6>cxn:
                    numHand = numHand + 1
                for m in range(0,4):
                   if id==idDe[m]:
                      cym = cy
                      #print(cym)
                   if id==idDe[m]-2:
                       cyn = cy
                         #   print(cyn)

                   if cym < cyn:
                      #print("hi")
                      #print(cym,cyn)
                      numHand = numHand + 1
                      #print(numHand)
                      reelnum=numHand
                        #print(idDe[m],cy)

            cv2.putText(img, str(int(reelnum)), (555, 90), cv2.FONT_HERSHEY_PLAIN, 6,
                        (255, 230, 0), 6)
            if reelnum == 1 :
                        #  ser.write(b'0')
                          rees[0]=1
                          print('is 1')
                          reelnum=0
                          arduino.sendData([1, 0, 0,0,0,0])

            elif reelnum == 2:
                          rees[0]=2
                          print('is 2')
                          reelnum=0
                          arduino.sendData([1, 1, 0,0,0,0])

            elif reelnum == 3:
                          rees[0]=3
                          print('is 3')
                          reelnum=0
                          arduino.sendData([1, 1, 1,0,0,0])

            elif reelnum == 4:
                          rees[0]=4
                          print('is 4')
                          reelnum=0
                          arduino.sendData([1,1,1, 1, 0,0])

            elif reelnum == 5:
                          print('is 5')
                          reelnum=0
                          #ser.write(b'1')
                        #  data = ser.readline().decode('ascii')
                          arduino.sendData([1,1,1, 1,1,0])
                          rees[0]=5


            else:
                print('is 0')
                arduino.sendData([0,0,0, 0,0,0])

        mpDraw.draw_landmarks(img, handLms, mpHands.HAND_CONNECTIONS)
        #لاضهار النقاط و جعلها متصلة

    cTime = time.time()
    fps = 1 / (cTime - pTime)
    pTime = cTime

    cv2.putText(img, str(int(fps)), (10, 70), cv2.FONT_HERSHEY_PLAIN, 3,
                (255, 0, 255), 3)

    cv2.imshow("Image", img)
    cv2.waitKey(1)


					
					

arduino code :
					
// made by oussama taliuan

#include  < cvzone.h >

SerialData serialData(6,1);


int valsRec[6];

int led1 = 13;
int led2 = 12;
int led3 = 8;
int led4 = 7;
int led5 = 4;
int buzz = 2;


void setup() {
  serialData.begin();
  pinMode(led1,OUTPUT);
  pinMode(led2,OUTPUT);
  pinMode(led3,OUTPUT);
  pinMode(led4,OUTPUT);
  pinMode(led5,OUTPUT);
  pinMode(buzz,OUTPUT);


}

void loop() {

  serialData.Get(valsRec);
  digitalWrite(led1,valsRec[0]);
  digitalWrite(led2,valsRec[1]);
  digitalWrite(led3,valsRec[2]);
  digitalWrite(led4,valsRec[3]);
  digitalWrite(led5,valsRec[4]);
  digitalWrite(buzz,valsRec[5]);

}