Project Overview
This project creates a hands-free garage door opener that detects when your car approaches and automatically opens the door. Using a PIR sensor mounted near the driveway, the system detects your vehicle’s heat signature and triggers a relay that simulates pressing the garage door opener button.
Difficulty: Intermediate
Estimated time: 2-3 hours
Estimated cost: $25-35
How It Works
A PIR sensor placed at the driveway entrance detects the heat signature of your approaching car. When a vehicle is detected (after a short delay), the system activates a relay that connects across the garage door opener’s wall button terminals, simulating a button press. An optional reed switch on the garage door can detect whether the door is already open.
Materials Needed
- ESP32 or Arduino Uno (1)
- HC-SR501 PIR sensor (1) or AM312 for lower power
- Relay module (5V, single channel)
- Reed switch (normally open) for door position detection (optional)
- Magnet for reed switch
- 12V to 5V converter (if using 12V garage door supply)
- Waterproof enclosure (for outdoor PIR sensor)
- Jumper wires
Understanding Your Garage Door Opener
Most garage door openers have a wall button that simply shorts two wires together to trigger the door. You can connect a relay across these terminals to simulate a button press. The wires are low voltage (usually 12-24V DC), so it is safe to interface with.
Important: Identify the correct wires before connecting. Use a multimeter to find the pair that shows continuity when the wall button is pressed.
Circuit Diagram
Connection Table
| Component |
Pin |
ESP32 Pin |
PIR Sensor |
VCC
3.3V or VIN
PIR Sensor |
GND
GND
PIR Sensor |
OUT
GPIO 4
Relay Module |
IN
GPIO 5
Reed Switch |
One side
GPIO 12 (with 10k pull-up)
Reed Switch |
Other side
GND
表
Arduino Code
// Automatic Garage Door Opener with PIR
#include <WiFi.h>
#include <WebServer.h>
const int pirPin = 4;
const int relayPin = 5;
const int doorSensorPin = 12;
WebServer server(80);
unsigned long lastTriggerTime = 0;
const unsigned long triggerDelay = 1000;
const unsigned long relayDuration = 500;
const unsigned long cooldownPeriod = 30000;
bool motionDetected = false;
bool doorOpen = false;
unsigned long motionStartTime = 0;
void setup() {
Serial.begin(115200);
pinMode(pirPin, INPUT);
pinMode(relayPin, OUTPUT);
pinMode(doorSensorPin, INPUT_PULLUP);
digitalWrite(relayPin, LOW);
WiFi.begin("YourSSID", "YourPassword");
while (WiFi.status() != WL_CONNECTED) delay(500);
server.on("/", []() {
String html = "<html><body><h1>Garage Door</h1><p>Status: ";
html += doorOpen ? "OPEN" : "CLOSED";
html += "</p><a href='/open'><button>Open</button></a></body></html>";
server.send(200, "text/html", html);
});
server.on("/open", []() {
triggerDoor();
server.sendHeader("Location", "/");
server.send(303);
});
server.begin();
doorOpen = digitalRead(doorSensorPin) == LOW;
delay(60000);
}
void triggerDoor() {
digitalWrite(relayPin, HIGH);
delay(relayDuration);
digitalWrite(relayPin, LOW);
delay(2000);
doorOpen = digitalRead(doorSensorPin) == LOW;
lastTriggerTime = millis();
}
void loop() {
server.handleClient();
bool pirState = digitalRead(pirPin) == HIGH;
if (pirState && !motionDetected) {
motionDetected = true;
motionStartTime = millis();
}
if (motionDetected && (millis() - motionStartTime > triggerDelay)) {
if (!doorOpen && (millis() - lastTriggerTime > cooldownPeriod)) {
triggerDoor();
}
motionDetected = false;
}
if (motionDetected && !pirState && (millis() - motionStartTime < triggerDelay)) {
motionDetected = false;
}
bool newDoorState = digitalRead(doorSensorPin) == LOW;
if (newDoorState != doorOpen) {
doorOpen = newDoorState;
}
delay(100);
}
Installation Steps
- Identify the wall button terminals on your garage door opener
- Wire the relay COM and NO terminals across those terminals
- Mount PIR sensor at driveway entrance, 1.5-2m high, angled to detect vehicle approach
- Mount reed switch on door frame and magnet on door
- Place ESP32 and relay in waterproof enclosure near the garage door opener
- Test by driving vehicle toward garage and verifying door opens automatically
Project Extensions
- Add Wi-Fi dashboard to monitor door status and manually control
- Integrate with Home Assistant via ESPHome
- Add ESP32-CAM to capture images when door opens
- Add RFID for vehicle-specific control
- Add timer to automatically close door if left open
Conclusion
This automatic garage door opener adds convenience and a modern touch to your home. With proper installation, it will reliably open your garage door as you arrive.