Inspiration The idea came from wanting to create a comprehensive IoT access control system that goes beyond simple door locks. I wanted to integrate multiple safety features: automated obstacle detection for preventing accidents, environmental monitoring for fire/humidity alerts, IR remote and emergency button access, AI-powered chatbot assistance, and seamless remote management with web dashboard—all on a single microcontroller platform.
What it does The ESP32 Smart Door Control System is a multi-functional access control solution featuring:
- IR remote control for door unlock (OK button), LED toggle (* button), and fan toggle (# button)
- Emergency exit button that opens the door for a configurable duration (default 10 seconds)
- Automated servo lock mechanism (configurable angles: default 0° closed, 90° open)
- Ultrasonic obstacle detection that auto-activates lighting when someone approaches (threshold configurable, default 10 cm)
- Real-time temperature & humidity monitoring with configurable alert thresholds (default 30°C temp, 70% humidity; auto-opens door at 85°C or 85%)
- WiFi-enabled web dashboard with real-time WebSocket updates, controls, settings, AI chat, about, and contact tabs
- AI chatbot assistant using Google Gemini for natural language queries and commands (e.g., /open, /led on)
- Voice input support for chatbot via browser speech recognition
- Visual feedback via 20x4 I2C LCD display showing system status, sensor data, alerts, countdown timer, LED/fan status
- Audio alerts through active buzzer for access events, door open, and temp/humidity alerts with different beep patterns
- Relay-controlled lighting (auto-on with obstacle)
- Status LED with blinking patterns (rapid flash when door open)
- Toggle LED and PWM-controlled DC fan with physical buttons and remote/web control
- Data logging (up to 100 entries) with CSV export via web
- Email alerts via Formspree for temp/humidity thresholds (with 5-minute cooldown)
How we built it Hardware Integration:
- ESP32-WROOM-32 as the central controller (dual-core Tensilica LX6 @ 240MHz)
- HC-SR04 ultrasonic sensor for distance detection (trig GPIO19, echo GPIO18)
- DHT22 sensor for precise temperature (±0.5°C) and humidity (±2% RH) measurements (data GPIO25 with 4.7kΩ-10kΩ pull-up)
- SG90 servo motor controlled via PWM for lock mechanism (GPIO26)
- 5V relay module for automated lighting control (GPIO27)
- IR receiver for remote control (GPIO14)
- Emergency exit button (GPIO34, active LOW with pull-up)
- Active buzzer for alerts (GPIO15)
- Status LED (GPIO5)
- 20x4 I2C LCD for real-time status display (address 0x27, SDA GPIO21, SCL GPIO22)
- Toggle LED (GPIO13) with button (GPIO35, pull-up)
- DC fan motor with PWM (GPIO32, channel 8, 25kHz freq)
- Fan button (GPIO23, pull-up)
Software Architecture:
- Developed in Arduino C++ using ESP32 core libraries
- AsyncWebServer and AsyncTCP for non-blocking web interface with WebSocket (/ws)
- IRremote library for IR decoding (updated to new version)
- DHT library for sensor reading with rate limiting (every 2 seconds)
- ESP32Servo for servo control
- LiquidCrystal_I2C (ESP32-compatible) for LCD
- Preferences for persistent storage of configurable settings (thresholds, angles, timing, API keys)
- HTTPClient for Formspree email alerts
- Multi-threading utilizing FreeRTOS tasks on both ESP32 cores
- State machine for door control (manual, auto-ventilation modes)
- Debouncing for buttons (50ms delay)
- Data logging in circular buffer with CSV generation
- AI integration via Gemini API in web client (generateContent endpoint)
- Voice recognition using Web Speech API in browser
- WiFi AP mode (SSID: ESP32SEG, password: letmeinplease)
Key Technical Implementations:
- Custom handling for DHT22 with timestamp-based interval checks
- Proper pull-up configurations (e.g., 4.7kΩ on DHT data, external 10kΩ on buttons)
- Power budgeting to avoid brownouts (separate power for actuators)
- Ultrasonic pulse timing with timeout (30ms) and distance calculation (temperature-compensated implicitly via stable readings)
- Responsive HTML/CSS/JS web dashboard with tabs, real-time updates via WebSocket, AJAX, toast notifications
- Command parsing in chatbot for system control (e.g., regex matching for /open, /fan on)
- Different buzzer patterns: fast for door open, slow for alerts, rapid for multiple, continuous for manual
- LCD optimization: update only changed lines, periodic backlight refresh
- Settings persistence and API key management (Gemini, Formspree)
Challenges we ran into
Voltage level compatibility: HC-SR04 outputs 5V ECHO signal, but ESP32 GPIO is only 3.3V tolerant. Solved with precision voltage divider (1kΩ + 2kΩ resistors).
Power consumption: Initial design tried powering servo and relay from ESP32's 3.3V rail, causing brownouts. Redesigned power distribution using VIN (5V USB) rail with proper current budgeting.
DHT22 timing sensitivity: Sensor requires minimum 2-second intervals between reads. Implemented timestamp-based rate limiting to prevent corrupt readings.
Ultrasonic noise: Raw HC-SR04 readings showed spurious spikes. Implemented timeout and default to 999cm on failure (median filter from original retained conceptually).
Web server blocking: Initial synchronous web server caused main loop delays. Switched to AsyncWebServer for true non-blocking operation.
Memory constraints: ESP32's 520KB SRAM filled quickly with large web pages and data log. Optimized HTML/CSS, used PROGMEM for static strings, implemented chunked HTTP responses, and limited log to 100 entries.
IR library compatibility: Updated to new IRremote.hpp for better decoding and repeat flag handling.
PWM channel conflicts: Servo and fan PWM conflicted; reassigned fan to channel 8.
Browser voice recognition: Handled browser support checks and error states for Web Speech API.
Alert spam prevention: Added 5-minute cooldown for email alerts and edge detection for state changes.
Accomplishments that we're proud of
- Successfully integrated over 10 different components (sensors, actuators, displays, buttons, remote) on a single microcontroller
- Achieved robust door control with multiple modes: manual (button/IR/web/AI), auto-ventilation with no timer
- Designed a professional-grade web dashboard with tabbed interface, real-time updates, voice-enabled AI chatbot, and CSV export
- Implemented AI assistance with natural language and command parsing, integrated with system status
- Created configurable system with web-based settings for thresholds, angles, timing, and API keys
- Added voice control and email notifications for enhanced usability
- Implemented data logging and export for analysis
- Maintained modular code architecture for easy feature additions, with comprehensive debugging via Serial
- Optimized for stability: debouncing, rate limiting, I2C traffic reduction
What we learned
- Deep understanding of ESP32 architecture: dual-core processing, FreeRTOS, peripheral buses (I2C, PWM channels), power distribution, pin constraints (e.g., input-only pins, strapping pins)
- Hands-on experience with multiple communication protocols: I2C (LCD), 1-Wire (DHT22), PWM (servo/fan), GPIO (matrix scanning, interrupts implicitly via polling)
- Importance of electrical safety: voltage level translation, current limiting, proper grounding, pull-ups
- Web development for embedded systems: asynchronous JavaScript, WebSocket, AJAX polling, responsive design, client-side API calls (Gemini, speech)
- Signal processing: debouncing, edge detection, pulse timing, noise handling
- Power management and current budgeting for battery-powered applications
- API integration: Google Gemini for AI, Formspree for emails, persistent storage with Preferences
- Browser features: Web Speech API for voice, toast notifications, dynamic UI updates
- System design: State tracking (e.g., auto vs manual open), alert patterns, data logging structures
Built With
- 1-wire
- 1-wire-(for-dht22-sensor)
- 1k?
- 2k?
- 4x4-matrix-keypad
- 5v-relay-module
- 802.11
- active-buzzer
- ap
- arduino
- asynctcp
- asyncwebserver
- breadboad
- c++
- core
- cp210x
- css3
- dht22-sensor
- electronic
- embedded
- esp32
- esp32-wroom-32
- espasyncwebserver-(for-non-blocking-web-server)
- espressif
- firebase
- formspree
- formspree-(for-contact-form-integration)
- freertos
- gemini
- google-gemini-(for-ai-chatbot-integration)-databases:-preferences-(for-storing-system-configurations-locally-on-the-esp32)-apis:-google-gemini-api-(for-ai-powered-chatbot)
- gpio
- hc-sr04-ultrasonic-sensor
- html5
- httpclient
- httpclient-(for-sending-email-alerts)-other-technologies:-i2c-(for-lcd-communication)
- i2c
- i2c-lcd-(20x4)
- ieee
- if-applicable)
- irremote.hpp-(for-ir-remote-control)-platforms:-esp32-wroom-32-(microcontroller-platform)-cloud-services:-firebase-(for-hosting-and-database
- javascript
- javascript-(for-web-interface)-frameworks:-freertos-(for-multi-core-task-handling)
- lcd
- libraries
- microcontroller
- progmem
- pwm
- pwm-(for-servo-motor-control)
- resistor
- sg90-servo-motor
- usb
- websocket
- wi-fi
- wifi
- wire
Log in or sign up for Devpost to join the conversation.