PIR Sensor for RV 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 p, sends an SMS via GSM module, sounds a siren, and logs the event. The system uses p to conserve battery.

Materials Needed

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

Circuit Diagram

Connection Table

OUT

GPIO 4

OUT

GPIO 5

GPIO 16

GPIO 17

Positive

GPIO 2

Anode

GPIO 15

Arduino Code

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

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

SoftwareSerial gsm(16, 17);

const char* phoneNumber = "+1234567890";
bool armed = true;
unsigned long lastAlertTime = 0;
const unsigned long alertCooldown = 600000;

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);
  
  sendATCommand("AT", 1000);
  sendATCommand("AT+CMGF=1", 1000);
  sendATCommand("AT+CNMI=2,2,0,0,0", 1000);
  
  delay(60000);
  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);
}

void activateAlarm(String location) {
  if (millis() - lastAlertTime > alertCooldown) {
    lastAlertTime = millis();
    
    String msg = "ALERT: Motion detected at " + location + " in your RV!";
    sendSMS(msg);
    
    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 p Version

#include <esp_sleep.h>

RTC_DATA_ATTR bool alarmSent = false;

void setup() {
  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) {
    bool interior = digitalRead(interiorPirPin) == HIGH;
    bool exterior = digitalRead(exteriorPirPin) == HIGH;
    
    if (!alarmSent) {
      gsm.begin(9600);
      sendATCommand("AT", 1000);
      sendATCommand("AT+CMGF=1", 1000);
      
      String location = interior ? "Interior" : "Exterior";
      sendSMS("ALERT: Motion at " + location + " in RV!");
      alarmSent = true;
      
      for (int i = 0; i < 10; i++) {
        digitalWrite(ledPin, HIGH);
        delay(250);
        digitalWrite(ledPin, LOW);
        delay(250);
      }
    }
  }
  
  if (millis() > 3600000) alarmSent = false;
  esp_deep_sleep_start();
}

Installation Steps

  1. Mount interior sensor near main entry door
  2. Mount exterior sensor in weatherproof enclosure outside
  3. Install GSM module with antenna for good reception
  4. Connect to RV 12V system or battery pack
  5. Test each sensor to verify SMS is received
  6. Adjust sensitivity to avoid false triggers

Project Extensions

  • Add GPS module to report vehicle location
  • Add ESP32-CAM to capture images
  • Control arming via SMS commands
  • Add temperature sensor for hot/cold alerts
  • Add gas leak detection for safety
  • Add solar panel for off-grid charging

Conclusion

This RV security system provides peace of mind when camping or storing your vehicle with SMS alerts.

Leave a Reply

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

Component Pin ESP32 Pin
Interior PIR Exterior PIR SIM800L TX SIM800L RX Buzzer/Siren Status LED