Flashing a light with a Raspberry Pi is nothing new—it’s the first thing many makers do with their first Raspberry Pi. Mohammad Reza Sharifi is taking the idea further by not just controlling an LED but instead is operating a light bulb using hand gestures and virtual buttons to trigger the light on or off.
This isn’t the first time we’ve covered Sharifi’s Raspberry Pi work. Most recently, he created a project that uses a PlayStation 4 controller to operate a drone. He’s also tackled hand gesture-operated projects in the past, including this robotic car that relies on hand signals for steering and control.
control_light_bulb_using_virtual_buttons from r/raspberry_pi
In a demo video shared by Sharifi, we can see a camera fixated on his hand with lines drawn across to show where the Pi has identified the hand shape. Two virtual buttons are overlaid on the camera feed. With the help of Node-Red, an event driven programming language, and some computer vision algorithms, the Pi is able to determine when the hand has moved into position and selects the corresponding button with a virtual “press”. This toggles the light bulb on or off depending on which button has been selected.
It doesn’t take much hardware to create this project but it will take a bit of effort on the software side. You will need a Raspberry Pi 3B+ or Raspberry Pi 4 and a compatible external camera of your choice. If you want to operate an appliance like a lamp or fan, you will need a relay to control it with the Raspberry Pi but more importantly the knowledge to safely work with higher voltages.
Sharifi explains that OpenCV and Python were used to construct the hand gesture detection system. It relies on the Cvzone library to determine the hand shape by measuring the distance between the fingers and its location in relation to the camera feed. If it detects that a virtual button has been pressed, a command is relayed to trigger the Raspberry Pi GPIO using MQTT protocol and Node-Red.
If you want to construct a similar system yourself, the best thing you can do is explore the original thread shared to Reddit by Sharifi. It has a demonstration video of the project in action as well as comments with additional details on how the project operates. We also recommend checking out our list of best Raspberry Pi projects for more inspiring creations from the maker community.