Arduino Nano-Controlled Lighting System with Gesture and Sound Interaction

Arduino Nano Lighting System with Gesture & Sound | MakeMindz
⚡ New projects added weekly — Browse all at MakeMindz.com
LED & Lighting Project

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.

🧠 Intermediate
⏱ ~2 Hours Build
🔌 4 AC Bulbs
🖥 Arduino Nano
📡 APDS-9960 + KY-038

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.

💡 What you'll learn Interfacing the APDS-9960 gesture sensor over I²C, reading analog microphone data, controlling relay outputs, and structuring clean toggle logic in Arduino.
⚠️ Safety Warning This project involves mains AC voltage. Do not touch the high-voltage section while powered. Use proper insulated connectors and enclosures. If in doubt, test with low-voltage LEDs first.

Components Required

🧠
Arduino Nano
ATmega328P, 5V, I²C support
🔌
4-Channel Relay Module
5V coil, 10A/250VAC rated
👋
APDS-9960 Gesture Sensor
I²C, 3.3V/5V compatible
🎤
KY-038 Sound Sensor
Analog + digital output
💡
AC Bulbs × 4
Standard E27 / B22 bulbs
🔋
Power Adapter
5V DC for Arduino + relay
🔧
Connecting Wires
Male-to-male & male-to-female
📦
Mini Breadboard
For sensor breakouts

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.

Arduino Nano 5V GND SDA(A4) SCL(A5) A0 D4 D5 D6 D7 APDS-9960 Gesture Sensor VCC→5V GND SDA SCL KY-038 Sound Sensor VCC→5V GND AO→A0 4-Channel Relay Module R1 R2 R3 R4 VCC←5V GND IN1←D4 IN2←D5 IN3←D6 IN4←D7 Bulb 1 Bulb 2 Bulb 3 Bulb 4 AC 230V Legend I²C (SDA/SCL) Analog Signal Relay Control AC 230V (DANGER) 5V Power GND

Pin Connection Table

ComponentComponent PinArduino Nano PinWire Colour
APDS-9960 Gesture SensorVCC5V🔴 Red
APDS-9960 Gesture SensorGNDGND⚫ Black
APDS-9960 Gesture SensorSDAA4🔵 Blue
APDS-9960 Gesture SensorSCLA5🩵 Cyan
KY-038 Sound SensorVCC5V🔴 Red
KY-038 Sound SensorGNDGND⚫ Black
KY-038 Sound SensorAO (Analog Out)A0🟢 Green
4-CH Relay ModuleVCC5V🔴 Red
4-CH Relay ModuleGNDGND⚫ Black
4-CH Relay ModuleIN1D4🟠 Orange
4-CH Relay ModuleIN2D5🟠 Orange
4-CH Relay ModuleIN3D6🟠 Orange
4-CH Relay ModuleIN4D7🟠 Orange

Step-by-Step Instructions

1

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)
2

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.

3

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.

4

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.

⚠️ Relay polarity check Some relay modules are active-HIGH. Check your board's datasheet and flip the initial digitalWrite if needed.
5

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
6

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.

7

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
8

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 (.ino)
/*
 * 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.

Key Features

👋
Touchless Gesture Control
Swipe up/down/left/right to independently toggle each bulb.
👏
Clap-to-Toggle
A single clap toggles all lights simultaneously.
💡
4 Independent Channels
Each AC bulb is controlled by its own relay channel.
🔒
Safe AC Switching
Low-voltage logic isolated from high-voltage AC by relay coil.
🏠
Smart Home Ready
Easily expand with Wi-Fi (ESP8266) or Bluetooth for remote control.
🏆
Exhibition-Worthy
Impressive demo for science fairs and engineering competitions.
MakeMindz Electronics tutorials, IoT projects & maker guides — makemindz.com
© 2026 MakeMindz · All rights reserved

Comments

try for free