Control a door lock with voice commands using a servo motor.
- ESP32 board
- Servo motor (SG90 or similar)
- External 5V power supply for servo (recommended)
- Status LED (optional - built-in LED used)
ESP32 GPIO18 → Servo Signal (Orange/Yellow)
External 5V → Servo VCC (Red)
ESP32 GND + 5V GND → Servo GND (Brown/Black)
ESP32 GPIO2 → Status LED (built-in)
ESP32 GPIO0 → BOOT button (built-in)
Important: Servos can draw significant current. Use an external 5V power supply for the servo, not the ESP32's 3.3V pin.
- Lock/unlock control via voice
- Servo motor for physical lock mechanism
- Manual button control
- Status LED (on=unlocked, off=locked)
- Event reporting to SinricPro
- "Alexa, lock the door"
- "Alexa, unlock the door"
- "Alexa, is the door locked?"
cd examples/lock
idf.py build flash monitorEdit main/lock_example.c - update WiFi and SinricPro credentials.
For different GPIO pins or servo angles, modify:
#define SERVO_GPIO (18)
#define STATUS_LED_GPIO (2)
#define BUTTON_GPIO (0)
#define SERVO_LOCKED_ANGLE (0) /* Adjust for your lock */
#define SERVO_UNLOCKED_ANGLE (90) /* Adjust for your lock */Different servos may require different angles. Test your servo:
- Set
SERVO_LOCKED_ANGLEto the angle where lock bolt is fully extended - Set
SERVO_UNLOCKED_ANGLEto the angle where lock bolt is fully retracted - Typical ranges: 0-90° or 0-180° depending on your mechanism
Press the BOOT button (GPIO0) to manually toggle lock state. The new state is sent to SinricPro.
This is a demonstration example. For production smart locks:
- Add tamper detection
- Add battery backup
- Add manual override mechanism
- Add audit logging
- Consider fail-secure vs fail-safe requirements