PIR Sensor for RV/Motorhome Security System

Project Overview

This project creates a low-power security system specifically designed for RVs, motorhomes, and campers. When motion is detected inside or around your vehicle, the system sends an SMS alert to your phone and can trigger an alarm. The system is designed for low power consumption to preserve battery when off-grid.

Difficulty: Intermediate
Estimated time: 2-3 hours
Estimated cost: $35-50

How It Works

One or more PIR sensors monitor entry points and interior of the RV. When motion is detected, the ESP32 wakes from deep sleep, sends an SMS via GSM module, sounds a siren (if enabled), and logs the event. The system uses deep sleep to conserve battery when not active, waking only when motion is detected.

Materials Needed

  • ESP32 (1)
  • HC-SR501 PIR sensors (2-3) – interior and exterior
  • SIM800L GSM module (1)
  • SIM card (with SMS capability)
  • Buzzer or small siren (optional)
  • 12V to 5V converter (for RV power)
  • Battery pack (3×18650) for off-grid operation
  • TP4056 charging module (if using rechargeable batteries)
  • Jumper wires
  • Waterproof enclosure (for exterior sensor)

Circuit Diagram

Connection Table

Arduino Code

// RV Security System with SMS Alerts
#include <WiFi.h>
#include <SoftwareSerial.h>

// Pin definitions
const int interiorPirPin = 4;
const int exteriorPirPin = 5;
const int sirenPin = 2;
const int ledPin = 15;

// GSM module
SoftwareSerial gsm(16, 17); // RX, TX

// Configuration
const char* phoneNumber = "+1234567890"; // Emergency contact
bool armed = true;
unsigned long lastAlertTime = 0;
const unsigned long alertCooldown = 600000; // 10 minutes between SMS

void setup() {
  Serial.begin(115200);
  gsm.begin(9600);
  
  pinMode(interiorPirPin, INPUT);
  pinMode(exteriorPirPin, INPUT);
  pinMode(sirenPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  
  digitalWrite(sirenPin, LOW);
  digitalWrite(ledPin, LOW);
  
  Serial.println("RV Security System Starting...");
  
  // Initialize GSM
  sendATCommand("AT", 1000);
  sendATCommand("AT+CMGF=1", 1000);
  sendATCommand("AT+CNMI=2,2,0,0,0", 1000);
  
  Serial.println("System Ready");
  Serial.println("Waiting 60 seconds for PIR warm-up...");
  delay(60000);
  
  // Send startup notification
  sendSMS("RV Security System ONLINE");
}

void sendATCommand(String cmd, int timeout) {
  gsm.println(cmd);
  delay(timeout);
  while (gsm.available()) {
    Serial.write(gsm.read());
  }
}

void sendSMS(String message) {
  gsm.print("AT+CMGS=\"");
  gsm.print(phoneNumber);
  gsm.println("\"");
  delay(500);
  gsm.print(message);
  delay(500);
  gsm.write(26);
  delay(3000);
  Serial.println("SMS sent");
}

void activateAlarm(String location) {
  if (millis() - lastAlertTime > alertCooldown) {
    lastAlertTime = millis();
    
    Serial.printf("ALARM: Motion detected at %s!\n", location.c_str());
    
    // Send SMS
    String msg = "ALERT: Motion detected at " + location + " in your RV!";
    sendSMS(msg);
    
    // Sound siren (if armed)
    if (armed) {
      for (int i = 0; i < 10; i++) {
        digitalWrite(sirenPin, HIGH);
        digitalWrite(ledPin, HIGH);
        delay(200);
        digitalWrite(sirenPin, LOW);
        digitalWrite(ledPin, LOW);
        delay(200);
      }
    }
  }
}

void loop() {
  bool interiorMotion = digitalRead(interiorPirPin) == HIGH;
  bool exteriorMotion = digitalRead(exteriorPirPin) == HIGH;
  
  if (armed) {
    if (interiorMotion) {
      activateAlarm("Interior");
    }
    if (exteriorMotion) {
      activateAlarm("Exterior");
    }
  }
  
  delay(100);
}

Low-Power Battery Version with Deep Sleep

#include <esp_sleep.h>

RTC_DATA_ATTR bool alarmSent = false;
RTC_DATA_ATTR unsigned long lastWakeTime = 0;

void setup() {
  Serial.begin(115200);
  
  pinMode(interiorPirPin, INPUT);
  pinMode(exteriorPirPin, INPUT);
  pinMode(sirenPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  
  esp_sleep_enable_ext0_wakeup((gpio_num_t)interiorPirPin, 1);
  esp_sleep_enable_ext1_wakeup((1ULL << exteriorPirPin), ESP_EXT1_WAKEUP_ANY_HIGH);
  
  if (esp_sleep_get_wakeup_cause() != ESP_SLEEP_WAKEUP_UNDEFINED) {
    // Woken by motion
    bool interior = digitalRead(interiorPirPin) == HIGH;
    bool exterior = digitalRead(exteriorPirPin) == HIGH;
    
    if (!alarmSent) {
      // Initialize GSM
      gsm.begin(9600);
      sendATCommand("AT", 1000);
      sendATCommand("AT+CMGF=1", 1000);
      
      String location = interior ? "Interior" : "Exterior";
      sendSMS("ALERT: Motion detected at " + location + " in RV!");
      
      alarmSent = true;
      
      // Flash LED for 5 seconds
      for (int i = 0; i < 10; i++) {
        digitalWrite(ledPin, HIGH);
        delay(250);
        digitalWrite(ledPin, LOW);
        delay(250);
      }
    }
  }
  
  // Reset alarm flag after 1 hour
  if (millis() - lastWakeTime > 3600000) {
    alarmSent = false;
  }
  lastWakeTime = millis();
  
  esp_deep_sleep_start();
}

Installation Steps

  1. Mount interior sensor: Place near main entry door, covering interior.
  2. Mount exterior sensor: Install in weatherproof enclosure on outside, covering entry area.
  3. Install GSM module: Place with antenna for good cellular reception.
  4. Power system: Connect to RV 12V system or battery pack.
  5. Test sensors: Trigger each sensor and verify SMS is received.
  6. Adjust sensitivity: Fine-tune to avoid false triggers from pets or passing people.

Project Extensions

  • GPS tracking: Add GPS module to report vehicle location in alerts.
  • Camera capture: Add ESP32-CAM to capture images when alarm triggers.
  • Remote arming: Control arming via SMS commands.
  • Temperature monitoring: Add temperature sensor to alert if RV gets too hot/cold.
  • Propane sensor: Add gas leak detection for safety.
  • Solar charging: Add solar panel for off-grid charging.

Troubleshooting

  • No SMS received: Check SIM card credit. Verify GSM module antenna. Ensure cellular coverage at location.
  • False triggers: Adjust PIR sensitivity. Check for pets or moving curtains.
  • Battery drains quickly: Ensure deep sleep is working. Verify standby current (should be <50µA).
  • GSM not connecting: Check power supply (SIM800L needs 2A peak). Use external 5V supply.

Conclusion

This RV security system provides peace of mind when camping or storing your vehicle. With SMS alerts, you'll know immediately if someone enters your RV.

Leave a Reply

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

Component Pin ESP32 Pin
Interior PIR OUT GPIO 4 Exterior PIR OUT GPIO 5 SIM800L TX GPIO 16 SIM800L RX GPIO 17 Buzzer/Siren Positive GPIO 2 Status LED Anode GPIO 15