Arduino Nano Smart Lighting with Gesture & Sound
Control AC bulbs touchlessly using hand gestures and clap detection — a complete build guide with circuit diagram and simulation links.
📋 Table of Contents
Project Overview
This project builds an advanced smart lighting control system powered by the compact Arduino Nano. The system lets you control up to four AC bulbs using hand gestures (up, down, left, right) detected by the APDS-9960 sensor, and toggle all lights with a clap via the KY-038 sound sensor.
A 4-channel relay module safely bridges the Arduino's 5V logic to the high-voltage AC circuit, making this a safe and practical home automation project. It's ideal for science exhibitions, engineering demos, and as a foundation for a full smart home system.
Components Required
Circuit Diagram
The diagram below shows how the Arduino Nano connects to the gesture sensor (I²C), sound sensor (analog), and the 4-channel relay module (digital). The AC side wiring for bulbs is shown in red.
Pin Connection Table
| Component | Component Pin | Arduino Nano Pin | Wire Colour |
|---|---|---|---|
| APDS-9960 Gesture Sensor | VCC | 5V | 🔴 Red |
| APDS-9960 Gesture Sensor | GND | GND | ⚫ Black |
| APDS-9960 Gesture Sensor | SDA | A4 | 🔵 Blue |
| APDS-9960 Gesture Sensor | SCL | A5 | 🩵 Cyan |
| KY-038 Sound Sensor | VCC | 5V | 🔴 Red |
| KY-038 Sound Sensor | GND | GND | ⚫ Black |
| KY-038 Sound Sensor | AO (Analog Out) | A0 | 🟢 Green |
| 4-CH Relay Module | VCC | 5V | 🔴 Red |
| 4-CH Relay Module | GND | GND | ⚫ Black |
| 4-CH Relay Module | IN1 | D4 | 🟠 Orange |
| 4-CH Relay Module | IN2 | D5 | 🟠 Orange |
| 4-CH Relay Module | IN3 | D6 | 🟠 Orange |
| 4-CH Relay Module | IN4 | D7 | 🟠 Orange |
Step-by-Step Instructions
Install the Arduino IDE & Libraries
Download and install the Arduino IDE. Then open the Library Manager (Ctrl+Shift+I) and install:
- Adafruit APDS9960 — gesture sensor driver
- Wire — built-in I²C library (no install needed)
Connect the APDS-9960 Gesture Sensor
Wire the sensor to the Arduino Nano's I²C bus. SDA goes to A4 and SCL goes to A5. Power with 5V and share the GND. The APDS-9960 breakout includes a 3.3V regulator so it works at 5V directly.
Connect the KY-038 Sound Sensor
Connect VCC to 5V, GND to GND, and the AO (analog out) pin to A0. Use the potentiometer on the sensor to adjust sensitivity — rotate clockwise to increase sensitivity for clap detection.
Wire the 4-Channel Relay Module
Connect IN1–IN4 to D4–D7 respectively. Power the relay VCC from the Arduino's 5V pin and share GND. Most 4-channel relay boards use active-LOW logic — sending LOW turns the relay ON. The code uses the default HIGH=off, LOW=on convention.
digitalWrite if needed.
AC Wiring (⚡ High Voltage — Use Caution)
Each relay COM terminal connects to the Live (L) wire of the AC supply. The NO (normally open) terminal connects to the bulb's Live input. Neutral (N) is wired directly to each bulb. Always work with the AC power disconnected while wiring.
- Relay COM → AC Live (L)
- Relay NO → Bulb Live terminal
- AC Neutral (N) → Bulb Neutral terminal
Upload the Arduino Code
Copy the code from the section below. Connect the Nano via USB, select Board: Arduino Nano and the correct COM port, then click Upload. Open the Serial Monitor at 9600 baud to debug sensor readings.
Test Gesture Controls
Hold your hand about 5–10 cm from the APDS-9960 and make slow directional swipes:
- 👆 Swipe UP → toggles Bulb 1
- 👇 Swipe DOWN → toggles Bulb 2
- 👈 Swipe LEFT → toggles Bulb 3
- 👉 Swipe RIGHT → toggles Bulb 4
Test Sound / Clap Control
Clap near the KY-038 module. If no response, adjust the potentiometer clockwise. The analog threshold in code is set to 512 (mid-range). Lower it for a quieter trigger environment. The 500ms delay prevents double-triggers.
Arduino Code
Complete, well-commented sketch. Uses the Adafruit APDS9960 library for gesture detection and analogRead for sound level monitoring.
/* * Arduino Nano-Controlled Lighting System * Gesture and Sound Interaction * * Author : MakeMindz (makemindz.com) * Sensors: APDS-9960 (gesture, I2C) + KY-038 (sound, analog) * Outputs: 4-channel relay module on D4–D7 * * Gesture → individual relay toggle * Clap → all relays toggle simultaneously */ #include <Wire.h> #include <Adafruit_APDS9960.h> Adafruit_APDS9960 apds; // Sound sensor analog pin const int soundSensorPin = A0; // Relay control pins D4–D7 const int relayPins[] = {4, 5, 6, 7}; void setup() { Serial.begin(9600); Wire.begin(); // Initialise APDS-9960 if (!apds.begin()) { Serial.println("Failed to initialise APDS-9960!"); while (1); } apds.enableGesture(true); Serial.println("APDS-9960 ready."); // Set relay pins as outputs (off by default) for (int i = 0; i < 4; i++) { pinMode(relayPins[i], OUTPUT); digitalWrite(relayPins[i], LOW); } } void loop() { // ── Gesture Input ────────────────────── if (apds.gestureAvailable()) { int gesture = apds.readGesture(); switch (gesture) { case APDS9960_UP: toggleRelay(0); break; // Bulb 1 case APDS9960_DOWN: toggleRelay(1); break; // Bulb 2 case APDS9960_LEFT: toggleRelay(2); break; // Bulb 3 case APDS9960_RIGHT: toggleRelay(3); break; // Bulb 4 } } // ── Sound / Clap Input ───────────────── int soundLevel = analogRead(soundSensorPin); if (soundLevel > 512) { // Adjust threshold if needed toggleAllRelays(); delay(500); // Debounce delay } } // Toggle a single relay by index void toggleRelay(int relayIndex) { int currentState = digitalRead(relayPins[relayIndex]); digitalWrite(relayPins[relayIndex], !currentState); Serial.print("Relay "); Serial.print(relayIndex + 1); Serial.println(currentState ? " → OFF" : " → ON"); } // Toggle all relays simultaneously (clap) void toggleAllRelays() { for (int i = 0; i < 4; i++) { int currentState = digitalRead(relayPins[i]); digitalWrite(relayPins[i], !currentState); } Serial.println("Clap detected – all relays toggled."); }
Simulation Links
🖥 Run this project in your browser
No hardware? Try the circuit in an online simulator first. Wokwi supports the Arduino Nano and APDS-9960 natively. Cirkit Designer has a relay module and visual wiring tool.
💡 Tip: In Wokwi, paste the diagram.json above into the Diagram tab, then paste the code into sketch.ino and hit ▶ Run.
Comments
Post a Comment