PIR Sensor for Driveway Alert System

Project Overview

This project creates a driveway alert system that detects vehicles or people approaching your property and sends a notification to a receiver inside your home. It is perfect for long driveways, rural properties, or anywhere you want to know when someone arrives.

Difficulty: Intermediate
Estimated time: 2-3 hours
Estimated cost: $40-60

How It Works

A weatherproof PIR sensor is placed at the driveway entrance. When a vehicle or person passes by, it sends a wireless signal to a receiver unit inside the house. The receiver can play a chime, flash an LED, or send a notification to your phone. For long driveways (up to 100m), LoRa or ESP-NOW is used.

Materials Needed

  • ESP32 (2) – one for transmitter, one for receiver
  • HC-SR501 PIR sensor (1) – outdoor version or weatherproof enclosure
  • LoRa modules (RAK811, Heltec) or NRF24L01 for wireless
  • Buzzer or speaker for audible alert
  • LEDs for visual alert
  • Battery pack for remote transmitter
  • Solar panel and charger (optional, for long-term deployment)
  • Weatherproof enclosure for transmitter
  • Jumper wires

Transmitter Code (LoRa)

// Driveway Alert Transmitter
#include <SPI.h>
#include <LoRa.h>

const int pirPin = 2;
const int csPin = 5;
const int rstPin = 14;
const int dio0Pin = 2;

unsigned long lastSendTime = 0;
const unsigned long sendCooldown = 30000;

void setup() {
  Serial.begin(115200);
  pinMode(pirPin, INPUT);
  
  LoRa.setPins(csPin, rstPin, dio0Pin);
  LoRa.begin(915E6);
  
  delay(60000);
}

void sendAlert() {
  LoRa.beginPacket();
  LoRa.print("MOTION");
  LoRa.print(",");
  LoRa.print(millis());
  LoRa.endPacket();
}

void loop() {
  bool motion = digitalRead(pirPin) == HIGH;
  
  if (motion && (millis() - lastSendTime > sendCooldown)) {
    lastSendTime = millis();
    sendAlert();
    delay(2000);
  }
  
  delay(100);
}

Receiver Code (LoRa with Display)

// Driveway Alert Receiver
#include <SPI.h>
#include <LoRa.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);

const int csPin = 5;
const int rstPin = 14;
const int dio0Pin = 2;
const int buzzerPin = 4;
const int ledPin = 13;

int alertCount = 0;
unsigned long lastAlertTime = 0;
const unsigned long alertDuration = 5000;

void setup() {
  Serial.begin(115200);
  pinMode(buzzerPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  digitalWrite(buzzerPin, LOW);
  digitalWrite(ledPin, LOW);
  
  lcd.init();
  lcd.backlight();
  lcd.print("Driveway Monitor");
  lcd.setCursor(0, 1);
  lcd.print("Ready");
  
  LoRa.setPins(csPin, rstPin, dio0Pin);
  LoRa.begin(915E6);
}

void triggerAlert() {
  alertCount++;
  lastAlertTime = millis();
  
  digitalWrite(ledPin, HIGH);
  tone(buzzerPin, 2000, 500);
  
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Vehicle detected!");
  lcd.setCursor(0, 1);
  lcd.print("Count: ");
  lcd.print(alertCount);
}

void loop() {
  int packetSize = LoRa.parsePacket();
  if (packetSize) {
    String message = "";
    while (LoRa.available()) message += (char)LoRa.read();
    if (message.startsWith("MOTION")) triggerAlert();
  }
  
  if (millis() - lastAlertTime > alertDuration && digitalRead(ledPin) == HIGH) {
    digitalWrite(ledPin, LOW);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("System Ready");
    lcd.setCursor(0, 1);
    lcd.print("Total: ");
    lcd.print(alertCount);
  }
  
  delay(100);
}

Installation Steps

  1. Assemble transmitter in weatherproof enclosure
  2. Position PIR sensor at driveway entrance, 1.5-2m high
  3. Test wireless range between transmitter and receiver
  4. Assemble receiver unit inside house with buzzer/LED visible
  5. Connect batteries or solar panel to transmitter
  6. Drive vehicle up driveway to test alert

Project Extensions

  • Add second sensor for direction detection
  • Add ESP32-CAM to capture images when motion detected
  • Add GSM module for SMS alerts
  • Add relay to automatically open gate

Conclusion

This driveway alert system provides early warning of visitors, packages, or intruders, easy to install even on long driveways.

Leave a Reply

Your email address will not be published. Required fields are marked *