Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

🛡️ PiGuardian — IoT Home Automation & Security System

Raspberry Pi • Flask • Chart.js • Adafruit IO • Neon DB

Team Members:

  • Ilian Adeleke 2330261
  • Cedric Augustin 2233427

📌 Project Overview

PiGuardian is a smart IoT security and automation system built on Raspberry Pi OS.
It collects environmental data, detects motion intrusions, controls three IoT devices,
and displays everything through a cloud-deployed Flask dashboard (Render.com).

The system communicates using:


🏗️ System Architecture (Required in Milestone 3)

📌 image


🧰 Hardware Used (Bill of Materials)

Component Purpose
Raspberry Pi 4B Main controller
DHT11 Sensor Temperature + humidity
PIR Motion Sensor Detects motion
I2C LCD 16×2 Displays local system messages
LEDs (Red/Yellow/Green) Device feedback
Buzzer (PWM) Audible alerts
Breadboard + Wires Circuit foundation
Pi Camera (optional) Intrusion snapshots

📌 INSERT REAL-WORLD WIRING PHOTO HERE
image image image


🔌 Wiring Diagram

Component GPIO Pin Notes
DHT11 GPIO 19 Data
PIR Sensor GPIO 6 Motion
LCD SDA GPIO 2 I²C
LCD SCL GPIO 3 I²C
Buzzer GPIO 18 PWM
LED Red GPIO 20 Output
LED Yellow GPIO 16 Output
LED Green GPIO 21 Output

🧪 Raspberry Pi Software Modules

File Description
environmental_module.py Reads DHT11, sends to Adafruit + Neon
security_module.py PIR detection, intrusion logging
device_control_module.py Sends device commands to Adafruit IO
milestoneLastTry.py Main controller orchestrator
MQTT_communicator.py Handles MQTT connection & publishing
lcd.py, buzzer.py Local feedback via LCD + buzzer

☁️ Cloud Components

🌩️ Adafruit IO Dashboard (Live Data + Device Control)

📌 image


🗄️ Neon PostgreSQL Database (Historical Storage)

Stores:

  • environmental_readings
  • security_events

📌 INSERT TABLE STRUCTURE SCREENSHOT HERE
image

📌 INSERT LIVE DATA INSERT SCREENSHOT HERE
image image


🌐 Flask Web Application (Deployed on Render)

✔️ Home Page

  • Animated banner
  • Live system summary
    📌 image

✔️ Environment Page

  • Date selector
  • Historical data loaded from Neon
  • Chart.js graphs
    📌 image

VERSION 2 with timestamp updated image


✔️ Device Control Page

  • Buttons controlling 3 devices
  • Direct API calls to Adafruit IO
    📌 image

✔️ Security Page

  • Arm/disarm system
  • Logs per selected date
  • Motion graph (24h)
    📌 image image

VERSION 2 with timestamp updated image


✔️ About Page

  • Team information
  • Project description
    📌 image image

🗄️ Local & Cloud Data Storage

  • Automatically writes to local SQLite if offline
  • Sends data to Neon PostgreSQL when online

(We didnt implement offline sync )


▶️ Running the System

🎛️ Running on Raspberry Pi:

sudo apt update && sudo apt upgrade -y
python3 milestoneLastTry.py

## Setup Instructions

### 1. OS Preparation
- Install Raspberry Pi OS (Bookworm or Bullseye).  
- Enable I²C, Camera, and SSH using:
  ```bash
  sudo raspi-config
  sudo apt update && sudo apt upgrade -y

### 2. Install Dependencies
  ```bash
  sudo apt install python3-pip python3-smbus i2c-tools -y
  pip3 install paho-mqtt adafruit-circuitpython-dht adafruit-blinka

3. Environment Variables / Config

  • Edit your config.json and fill in your Adafruit credentials:
    {
      "ADAFRUIT_IO_USERNAME": "YourUser",
      "ADAFRUIT_IO_KEY": "YourKey"
    }

How to Run

Run the main controller program:

  python3 milestoneLastTry.py

Environmental Feed

Field Type Unit Example
timestamp string ISO8601 "2025-11-04T16:22:15"
temperature float °C 22.7
humidity float % 55.2

Security Feed

Field Type Description
motion_detected bool true when PIR triggered
smoke_detected bool not yet implemented
image_path string Local image or .txt fallback file

File Rotation Policy

Each day the system creates new files:

  pip install -r requirements.txt
  flask run

📊 Data Formats

Environmental Readings:

Field Type Example
timestamp ISO8601 "2025-11-27T16:22:15"
temperature float 24.6
humidity float 45.1

Security Events:

Field Description
event_type "motion" or "smoke"
raw_timestamp ISO timestamp
image_path optional camera capture
🗂️ Daily Log Files (Auto Rotated)
YYYYMMDD_environmental_data.txt
YYYYMMDD_security_data.txt
YYYYMMDD_device_status.txt

🌟 Future Work

  • Add more sensors (CO₂, VOC, MQ-135)
  • Real-time SMS or email alerts
  • Face recognition
  • Voice assistant control
  • Advanced UI with animations

📝 Reflection

This project presented several challenges that required persistence and problem-solving. At the beginning, we were two weeks behind on Milestone 2 because our Raspberry Pi had not yet arrived, which created significant pressure on our schedule. Despite the delay, we managed to catch up by organizing our work efficiently and splitting tasks strategically between team members. Another major obstacle was dealing with Adafruit IO keys, which caused frequent issues with authentication and API access. At times, the keys would stop working unexpectedly, leaving us unable to push data or control devices until we regenerated credentials. We also ran into GitHub’s push-protection system, which blocked our commits because the configuration file accidentally contained sensitive keys. This forced us to redo commits, rewrite history, and re-structure our environment handling to protect the project. In the end, these difficulties helped us better understand secure development practices and made our system more robust and professional.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages