To avoid the risk of contracting Covid-19, it is important not to touch surfaces including switches, doorknobs, and keys that have been frequently used by other people. This project is for a contactless switch that works with hand gestures.
The smart switch includes a sensor that can detect hand movements and translate them into commands for controlling lights, fans, and various other home appliances. The author’s prototype for this switch, with its OLED display installed on the wall switchboard, is shown in Fig. 1. The list of components required for designing the gesture-controlled switch is given in Table 1.
Fig. 1: Prototype of gesture-controlled contactless switch with OLED display
First, install the required libraries in the Arduino IDE. Go to Select->Library Manager->Search APDS9960 and U8g2lib as shown in Fig. 2. Then add each library to Arduino code as shown in Fig. 3. Define Arduino pin numbers for controlling the light and fan. Next, create a setup function where you can initialise the sensor and set the pin mode output for light and fan control as shown in Fig. 4.
Fig. 2: Library Manager windowFig. 3: Arduino code with libraries and pin numbers for light and fanFig. 4: Setup function with pinMode functions
Create a loop function to update the sensor readings and use your hand gestures as inputs to control Arduino output pins. Also create a switch condition in the code, as shown in Fig. 5, for specifying the commands based on the type of hand gestures (up, down, left, and right). The icons (arrow symbols) below indicate the gestures and commands to be displayed on the OLED:
Up: Light on
Down: Light off
Left: Fan on
Right: Fan off
After coding is done, compile it in Arduino IDE and upload the code to Arduino board.
Fig. 5: Arduino code with switch conditions
Connections and testing
Connect the components as shown in Fig. 6, following Table 2. Then connect the 230V AC mains with the common pin of the relay module to control the light and fan as shown in Fig. 7.
Fig. 6: Connection diagramFig. 7: Relay connections with bulb and fan
Install the automatic contactless switch on the wall switchboard as shown in Fig. 8. Switch on 5V adaptor to power the device and relay module.
Fig. 8: Installation of gesture-controlled switch on wall switchboard
When you move your hand from down to up direction in front of the sensor, as shown in Fig. 9, light will switch on and at the same time an up arrow will be displayed on the OLED. If you move your hand from up to down position, the light will switch off and a down arrow will be displayed on the OLED.
Fig. 9: Moving hand up in front of the contactless switch switches on light bulb
Download Source Code
Similarly, when you move your hand from left to right in front of the sensor, the fan will switch on and a left arrow symbol will be displayed on the OLED. If you move your hand from right to left, the fan will switch off and a right arrow will be displayed on the OLED.
Ashwini Kumar Sinha is an electronics hobbyist and tech journalist at EFYi