Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

ESP32-Based Gesture-Controlled Smart Lighting System

View and Edit Project In Cirkit DesignerImage of ESP32-Based Gesture-Controlled Smart Lighting System

Circuit Documentation

Summary

This circuit utilizes an ESP32 microcontroller to control two appliances via a 2-channel relay module. The control is based on gestures detected by an APDS-9960 RGB and Gesture Sensor. The ESP32 reads gestures and accordingly switches the relays to turn the appliances (bulbs) on or off. The circuit is powered by an AC power plug.

Component List

  1. ESP32

    • Description: A powerful microcontroller with built-in Wi-Fi and Bluetooth capabilities.
    • Pins: EN, VP, VN, D34, D35, D32, D33, D25, D26, D27, D14, D12, D13, GND, VIN, 3V3, D15, D2, D4, RX2, TX2, D5, D18, D19, D21, RX0, TX0, D22, D23, BOOT
  2. APDS-9960 RGB and Gesture Sensor

    • Description: A sensor capable of detecting RGB color and gestures.
    • Pins: VL, GND, VCC, SDA, SCL, INT
  3. 2-channel Relay

    • Description: A relay module with two channels for controlling high voltage appliances.
    • Pins: NC, COM, NO, VCC, IN2, IN1, GND
  4. Bulb (x2)

    • Description: Standard light bulbs used as appliances in this circuit.
    • Pins: GND, power
  5. AC Power Plug

    • Description: Provides AC power to the circuit.
    • Pins: positive terminal, negative terminal

Wiring Details

ESP32

APDS-9960 RGB and Gesture Sensor

2-channel Relay

Bulb 1

Bulb 2

AC Power Plug

Code Documentation

Code for ESP32

#include <Wire.h>
#include <Adafruit_APDS9960.h>

Adafruit_APDS9960 apds;
const int relay1 = 26;  // GPIO for Relay 1
const int relay2 = 27;  // GPIO for Relay 2

void setup() {
  Serial.begin(115200);
  pinMode(relay1, OUTPUT);
  pinMode(relay2, OUTPUT);
  
  digitalWrite(relay1, LOW); // Start with appliances off
  digitalWrite(relay2, LOW);
  
  if (!apds.begin()) {
    Serial.println("APDS9960 initialization failed!");
    while (1);
  }
  apds.enableGesture(true);
  Serial.println("APDS9960 ready!");
}

void loop() {
  if (apds.gestureAvailable()) {
    int gesture = apds.readGesture();
    switch (gesture) {
      case APDS9960_DOWN: 
        Serial.println("Down Swipe - Appliance 2 OFF");
        digitalWrite(relay2, LOW);
        break;
      case APDS9960_UP: 
        Serial.println("Up Swipe - Appliance 2 ON");
        digitalWrite(relay2, HIGH);
        break;
      case APDS9960_LEFT: 
        Serial.println("Left Swipe - Appliance 1 OFF");
        digitalWrite(relay1, LOW);
        break;
      case APDS9960_RIGHT: 
        Serial.println("Right Swipe - Appliance 1 ON");
        digitalWrite(relay1, HIGH);
        break;
      default:
        break;
    }
  }
}

This code initializes the APDS-9960 sensor and sets up the relays connected to the ESP32. It reads gestures and controls the relays to turn the appliances on or off based on the detected gestures.