Tuesday, December 3, 2024

Wireless Gesture Controller for Home Automation using Raspberry Pi

Today, we will create a Wireless Gesture Controller System that tracks finger movement, recognizes gestures, and uses them to control lights. This system can be expanded to control other functions like adjusting volume or fan speed.

Controlling lights, speaker volume, or fan speed with voice commands and hand gestures is fascinating. It adds a modern and futuristic touch to our homes, making it convenient to operate without physical contact.

With the rise of technologies like metaverse and AR/VR, finger tracking and gesture control have become essential.

- Advertisement -

Additionally, the code can be integrated into metaverse and AR/VR environments for gesture-based control.

Gesture Controller using Raspberry Pi

Join us as we explore the exciting possibilities of gesture-based control for a more intuitive and immersive home automation experience.

- Advertisement -

So let’s start the project with a collection of the following components-

Bill of Materials 

Components Quantity Description Price 
Raspberry Pi 41SBC 1GB RAM4000
5V Relay Module 15V AC SPST50
RPi camera 1CSI Ribbon 300
Total4350

Code for Gesture Controller

To recognize the hand and fingers, calculate the distance between fingertips, and detect gestures; we can employ two different approaches-

The first approach involves using Numpy and OpenCV, while the second approach combines OpenCV with Mediapipe.

Although the Mediapipe-based system is accurate and efficient, there may be installation issues with the library. For now, we will focus on using OpenCV exclusively for coding purposes.

However, we plan to update this project in the next version by incorporating Mediapipe.

To begin, you need to install OpenCV and Numpy on your Raspberry Pi using the Linux terminal. Execute the following commands:

sudo pip3 install opencv
sudo pip3 install numpy

Once the installation is complete, you can proceed with the code implementation.

First, import the OpenCV and Numpy libraries. Then, utilize the gpiozero library to control the GPIO pins on the Raspberry Pi. Assign the appropriate LED number to control the light based on finger movements. Next, capture the frames in the code.

Afterward, process the video frames to detect the hand and fingers. Use an if condition to determine the distance between the index and thumb fingers. If the thumb and index finger touch each other, set a function to turn the lights on.

DIY Hand Gesture Controller

Gesture Controller Circuit Diagram

To connect the relay to your Raspberry Pi, follow these steps:

  1. Locate the 5V and GND pins on the Raspberry Pi. Connect the corresponding pins of the relay to these pins. The 5V pin provides power to the relay, while the GND pin establishes the ground connection.
  2. Choose a free pin on the Raspberry Pi for relay control. In this example, we’ll use pin 17, but you can use any available pin that suits your needs.
  3. Connect the input pin of the relay to pin 17 on the Raspberry Pi. This pin will control the relay’s state.
Raspberry Pi and Relay Connection

Make sure to refer to the circuit diagram for a visual representation of the connections. Remember that you can use any free pin on the Raspberry Pi for relay control, not just pin 17.

Testing and Working

To test the code, follow these steps:

  1. Run the code you have implemented.
  2. Position your finger in front of the Raspberry Pi camera.
  3. Move your fingers and touch your index finger to your thumb.
Hand Gesture Tracking using OpenCV

If the code is functioning correctly, touching the index and thumb fingers should activate the relay, turning it on. However, please note that the accuracy of finger and palm detection may not be optimal since you did not utilize any machine learning (ML) models in the current implementation.

Also Check: Implementing Gesture Recognition in DIY Projects

To enhance the accuracy of finger and palm detection, consider updating the project by incorporating Mediapipe. Mediapipe provides robust ML models for hand and gesture recognition, leading to improved accuracy in detecting fingers and palm positions.

Raspberry Pi based Gesture Controller
Ashwini Sinha
Ashwini Sinha
A tech journalist at EFY, with hands-on expertise in electronics DIY. He has an extraordinary passion for AI, IoT, and electronics. Holder of two design records and two times winner of US-China Makers Award.

SHARE YOUR THOUGHTS & COMMENTS

EFY Prime

Unique DIY Projects

Electronics News

Truly Innovative Electronics

Latest DIY Videos

Electronics Components

Electronics Jobs

Calculators For Electronics