Arduino Nano-Based Home Security System with LCD Display and GSM Alerts
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is a home protection system that integrates various sensors and modules to monitor environmental conditions and send alerts. The system uses an Arduino Nano microcontroller to interface with a 16x2 LCD display, an MQ-2 gas sensor, an HC-SR04 ultrasonic sensor, an LM35 temperature sensor, and a SIM800L GSM module. The system is powered by a 18650 Li-ion battery and includes a TP5100 battery charger and an XL4015 DC-DC buck converter for power management. The Arduino Nano runs embedded code to read sensor data, display information on the LCD, and send SMS alerts via the GSM module.
Component List
16X2 LCD
- Description: A 16x2 character LCD display.
- Pins: VSS, VDD, V0, RS, RW, E, D1, D0, D2, D3, D4, D6, D5, D7, A, K
Arduino Nano
- Description: A small, complete, and breadboard-friendly board based on the ATmega328P.
- Pins: D1/TX, D0/RX, RESET, GND, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11/MOSI, D12/MISO, VIN, 5V, A7, A6, A5, A4, A3, A2, A1, A0, AREF, 3V3, D13/SCK
MQ-2
- Description: A gas sensor for detecting smoke, propane, methane, and other combustible gases.
- Pins: GND, VCC, ANALOG, Digital
SIM800L
- Description: A GSM module for sending SMS and making calls.
- Pins: NFT, RING, VCC, DTR, RST, MIC +, RXD, MIC-, TXD, SPK+, GND, SPK-
HC-SR04 Ultrasonic Sensor
- Description: An ultrasonic sensor for distance measurement.
- Pins: VCC, TRIG, ECHO, GND
Temperature Sensor (LM35)
- Description: A temperature sensor that outputs an analog voltage proportional to the temperature.
- Pins: +Vs, Vout, GND
18650 Li-ion Battery
- Description: A rechargeable lithium-ion battery.
- Pins: -, +
Potentiometer
- Description: A variable resistor used to adjust the contrast of the LCD.
- Pins: GND, Output, VCC
TP5100
- Description: A battery charger module for 18650 Li-ion batteries.
- Pins: B-, B+, IN-, IN+
XL4015 5A DC Buck Step-down
- Description: A DC-DC buck converter for stepping down voltage.
- Pins: Output +, Output -, Input +, Input -
DC Power Source
- Description: A power source for the circuit.
- Pins: Ground, Positive
Rocker Switch (SPST)
- Description: A single-pole single-throw switch for turning the circuit on and off.
- Pins: 1, 2
Wiring Details
16X2 LCD
- VSS: Connected to GND
- VDD: Connected to VCC
- V0: Connected to Potentiometer Output
- RS: Connected to Arduino Nano D12/MISO
- RW: Not connected
- E: Connected to Arduino Nano D11/MOSI
- D4: Connected to Arduino Nano D5
- D5: Connected to Arduino Nano D4
- D6: Connected to Arduino Nano D3
- D7: Connected to Arduino Nano D2
- A: Not connected
- K: Not connected
Arduino Nano
- D2: Connected to 16X2 LCD D7
- D3: Connected to 16X2 LCD D6
- D4: Connected to 16X2 LCD D5
- D5: Connected to 16X2 LCD D4
- D7: Connected to SIM800L RXD
- D8: Connected to SIM800L TXD
- D9: Connected to HC-SR04 TRIG
- D10: Connected to HC-SR04 ECHO
- A0: Connected to LM35 Vout
- A1: Connected to MQ-2 ANALOG
- VIN: Connected to Rocker Switch (SPST) Pin 2 and XL4015 Input +
- GND: Connected to TP5100 B-, 18650 Li-ion Battery -, and XL4015 Input -
MQ-2
- GND: Connected to GND
- VCC: Connected to VCC
- ANALOG: Connected to Arduino Nano A1
SIM800L
- GND: Connected to GND
- VCC: Connected to VCC
- RXD: Connected to Arduino Nano D7
- TXD: Connected to Arduino Nano D8
HC-SR04 Ultrasonic Sensor
- VCC: Connected to VCC
- TRIG: Connected to Arduino Nano D9
- ECHO: Connected to Arduino Nano D10
- GND: Connected to GND
Temperature Sensor (LM35)
- +Vs: Connected to VCC
- Vout: Connected to Arduino Nano A0
- GND: Connected to GND
18650 Li-ion Battery
- -: Connected to TP5100 B- and another 18650 Li-ion Battery +
- +: Connected to Rocker Switch (SPST) Pin 1 and TP5100 B+
Potentiometer
- GND: Connected to GND
- Output: Connected to 16X2 LCD V0
- VCC: Connected to VCC
TP5100
- B-: Connected to 18650 Li-ion Battery -
- B+: Connected to 18650 Li-ion Battery +
- IN-: Connected to DC Power Source Ground
- IN+: Connected to DC Power Source Positive
XL4015 5A DC Buck Step-down
- Output +: Connected to VCC
- Output -: Connected to GND
- Input +: Connected to Arduino Nano VIN and Rocker Switch (SPST) Pin 2
- Input -: Connected to Arduino Nano GND, TP5100 B-, and 18650 Li-ion Battery -
DC Power Source
- Ground: Connected to TP5100 IN-
- Positive: Connected to TP5100 IN+
Rocker Switch (SPST)
- Pin 1: Connected to 18650 Li-ion Battery +
- Pin 2: Connected to Arduino Nano VIN and XL4015 Input +
Documented Code
Arduino Nano Code
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>
#include <NewPing.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
SoftwareSerial gsm(7, 8); // RX, TX
const int trigPin = 9;
const int echoPin = 10;
const int lm35Pin = A0;
const int mq2Pin = A1;
const unsigned long cooldownPeriod = 60000; // Cooldown period in milliseconds
unsigned long lastMovementAlertTime = 0;
unsigned long lastTemperatureAlertTime = 0;
unsigned long lastGasAlertTime = 0;
const int movementThreshold = 30; // cm
const float temperatureThreshold = 40.0; // Celsius
const int gasThreshold = 250; // MQ-2 value
// SMS Messages
const char* movementAlertMsg = "Alert Movement Detected!";
const char* temperatureAlertMsg = "Alert Temperature Detected!";
const char* gasAlertMsg = "Alert Gas Leakage/Smoke Detected!";
void setup() {
lcd.begin(16, 2);
gsm.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
lcd.print("Home Protect v3.0");
delay(2000);
lcd.clear();
}
void loop() {
long distance = detectMovement();
float temperature = detectTemperature();
int gasValue = detectGas();
checkAlerts(distance, temperature, gasValue);
updateDisplay(distance, temperature, gasValue);
delay(1000); // Delay for stability
}
long detectMovement() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
long duration = pulseIn(echoPin, HIGH);
return (duration * 0.034) / 2; // Distance in cm
}
float detectTemperature() {
return analogRead(lm35Pin) * (5.0 / 1023.0) * 100.0; // Convert to Celsius
}
int detectGas() {
return analogRead(mq2Pin);
}
void checkAlerts(long distance, float temperature, int gasValue) {
if (distance < movementThreshold