ESP32 Sonar Cabinet Lighting Controller ESP32 Sonar Cabinet Lighting Controller

ESP32 Sonar Cabinet Lighting Controller

Overview

This ESP32-powered cabinet lighting system automatically illuminates your cabinets when doors are opened using a sonar sensor for detection.

It features RGBW LED strips with customizable colors, brightness, and threshold settings through a responsive web interface, plus OTA updates for easy maintenance.

Features

Motion-Activated Lighting

  • Uses HC-SR04 sonar sensor to detect cabinet door opening
  • Filtered detection with rolling buffer to prevent false triggers
  • Automatic on/off based on configurable distance threshold

RGBW LED Control

  • Full RGBW color control via web interface
  • Real-time color sliders with live preview
  • Configurable number of LEDs (1-300 supported)
  • SK6812 RGBW strip compatibility with proper color mapping

Web-Based Control Panel

  • Responsive dark-themed UI accessible from any device
  • Live door status monitoring (Open/Closed)
  • Real-time distance readings in inches
  • Adjustable threshold sensitivity for different cabinet sizes

Smart Connectivity Features

  • WiFi auto-reconnect with visual LED status indicators
  • Over-The-Air (OTA) updates for remote code deployment
  • JSON API endpoints for integration with home automation

Robust Operation

  • Connection monitoring with automatic WiFi recovery
  • Visual status feedback using LED colors (red for disconnected, green for connected)
  • Debounced sensor readings to prevent flickering

Tech Stack

  • ESP32 → Core microcontroller with WiFi
  • HC-SR04 → Ultrasonic distance sensor
  • SK6812 RGBW → Addressable LED strips
  • Adafruit NeoPixel → LED control library
  • ESPAsyncWebServer → Web interface hosting
  • ArduinoOTA → Over-the-air updates
  • HTML/CSS/JavaScript → Responsive web UI

Hardware Setup

ComponentPurposePin Connection
HC-SR04 SonarDistance detectionTRIG: Pin 12, ECHO: Pin 14
SK6812 RGBW StripCabinet lightingData: Pin 27
ESP32 DevKitMain controller5V/3.3V power

Key Features Breakdown

Intelligent Door Detection

The system uses a rolling buffer algorithm to filter out noise and false triggers:

  • Samples distance every 75ms
  • Maintains a 5-sample rolling buffer
  • Only triggers when majority of samples indicate “door open”
  • Configurable threshold distance (default: 2.0 inches)

Web Interface Controls

  • Color Sliders: Independent RGBW control (0-255)
  • LED Count: Adjustable strip length (1-300 LEDs)
  • Threshold: Distance sensitivity (1-40 inches)
  • Live Status: Real-time door state and distance readings

WiFi Reliability

  • Automatic reconnection attempts every 15 seconds
  • Visual feedback via LED colors during connection issues
  • Auto-restart after multiple failed reconnection attempts

Project Images & Screenshots

Web Interface

Cabinet Lights Web UI Responsive web control panel showing real-time door status, distance readings, and RGBW color controls

Hardware Setup & Components

All Components ESP32, HC-SR04 sonar sensor and supporting components

Assembly & Installation

Fully Assembled System Complete system assembled and ready for cabinet installation

Installation - Lights Off Cabinet installation showing sensor placement and LED strip routing

Installation - Top View Off Top-down view of the installed system in cabinet

Shopping & Parts Reference

Amazon Cart Example Amazon cart showing required components for the build


Parts List & Estimated Cost

PartQtyApprox. Price
ESP32-C3 Development Board (3-pack)1~$13.88
SK6812 RGBW LED Strip (1m, 144 LEDs/m)1~$25.99
HC-SR04 Ultrasonic Sensor (3-pack)1~$7.99
Jumper Wires & Breadboard1~$5
5V Power Supply (for LED strip)1~$8
Total:~$39

Prices may vary depending on strip length and supplier


Installation & Setup

  1. Hardware Assembly

    • Connect HC-SR04 sensor to ESP32 (TRIG→12, ECHO→14)
    • Wire SK6812 strip data line to Pin 27
    • Ensure proper 5V power supply for LED strip
  2. Software Configuration

    • Update WiFi credentials in code
    • Set OTA password for secure updates
    • Adjust default LED count and threshold as needed
  3. Cabinet Installation

    • Mount sensor inside cabinet frame
    • Position to detect door opening movement
    • Route LED strip along cabinet interior

API Endpoints

  • GET / → Main control interface
  • GET /status → JSON status (door state, distance, LED settings)
  • GET /set → Update LED colors, count, and threshold

Future Plans & Improvements

  • Add motion sensor for enhanced detection
  • Integrate ambient light sensor for automatic brightness adjustment
  • Support for multiple cabinet zones with independent control
  • Home Assistant integration via MQTT
  • Mobile app for quick control

Get the Code & Follow the Project

GitHub Repo: View the Source Code

Full source code, wiring diagrams, and setup instructions available on GitHub!


← Back to projects