This repository contains the code for a home automation system designed to control the lighting based on environmental input using a Raspberry Pi. The system interfaces with an LDR (Light Dependent Resistor) to detect ambient light levels and controls an LED as an output device.
lightcontrol/: The Django app that manages the lighting system.models.py: Defines the data model for system settings.urls.py: URL declarations for the application.views.py: Handles requests and renders responses to the web interface.gpio_control.py: Functions for interacting with GPIO pins (for LED and LDR).templates/dashboard.html: HTML templates for the web interface.static/js/lightcontrol.js: Static files like CSS and JavaScript for frontend interactivity.
myhomeautomation/: The main project directory with settings and root configurations.settings.py: Settings/configuration for the Django project.urls.py: URL declarations for the entire Django project.
db.sqlite3: The SQLite database file containing the application's persistent data.manage.py: The Django command-line utility for administrative tasks.
To use the home automation system, you'll need to connect the LED and LDR (Light Dependent Resistor) to your Raspberry Pi's GPIO pins. Follow these instructions to properly wire your components:
-
Connect the longer lead (anode) of the LED to GPIO pin 17 (physical pin 11) on the Raspberry Pi.
-
Connect the shorter lead (cathode) of the LED to a current-limiting resistor.
-
Connect the other end of the resistor to one of the ground (GND) pins on the Raspberry Pi.
- Note: Ensure that the LED is connected with the correct polarity (anode to GPIO 17 and cathode to GND) to avoid damaging the LED.
-
Connect one leg of the LDR to GPIO pin 4 (physical pin 7) on the Raspberry Pi.
-
Connect the other leg of the LDR to one of the 3.3V pins on the Raspberry Pi.
-
Place a pull-down resistor (10k ohms) between the same leg connected to GPIO 4 and a ground (GND) pin on the Raspberry Pi.
- Note: The LDR is used to detect ambient light levels. The pull-down resistor ensures stable readings when the LDR is not exposed to light.
After completing these wiring connections, you can proceed with setting up and running the home automation system as described below.
- Python 3.7 or higher
- Django 1.11.29 or higher
- Raspberry Pi with GPIO access
- An LED and LDR correctly wired to the Raspberry Pi
-
Clone the repository:
git clone https://github.com/ahmaad-ansari/SOFE4610U-Assignment-3.git cd SOFE4610U-Assignment-3 -
Run database migrations:
python3 manage.py makemigrations lightcontrol python3 manage.py migrate
-
To start the server:
python manage.py runserver 0.0.0.0:8000
-
Open a web browser and navigate to:
http://<Raspberry_Pi_IP>:8000
- Use the web interface to toggle the LED state or switch Auto Mode on/off.
- When Auto Mode is active, the LED is controlled automatically based on LDR input.
Here you can provide screenshots of your web interface for the light control dashboard. This can help users to understand what the interface looks like and how it operates.
Here is the sequence diagram illustrating the flow of operations from the user interaction to the database update and response back to the user for a simple LED toggle:
IoT.Demo.mp4
- The GPIO control code is tailored for the Raspberry Pi. Adaptations may be required for other platforms.
- This system is designed for demonstration purposes and is not production-ready.