Smart Door Access Project In Django and Arduino

Introduction:

In a world where technology keeps getting better, even opening doors is getting a high-tech makeover. Picture this: you use your phone or computer to unlock doors, super safe and easy. Today, we’re talking about smart door access. Django, a powerful web tool, and Arduino, a tiny computer, team up to change how we open doors. Welcome to the Smart Door Access: Django & Arduino Project.

Smart Door Access: A Tale of Innovation
Gone are the days of juggling keys or fumbling with passcodes. Smart door access systems bring convenience and security to the forefront, offering remote management, real-time monitoring, and cutting-edge authentication features. But how do we bring this vision to life?

Introducing Django and Arduino Integration
Enter Django, the wizard behind the web, providing a robust platform for user authentication and access control. Paired with Arduino, the Swiss Army knife of hardware tinkering, we create a seamless connection between the digital and physical realms, making our smart door dreams a reality.

Peeking into the Toolbox: Key Components

  1. Django Web Application: Think of Django as the conductor of our smart door symphony. It orchestrates user authentication, access permissions, and system monitoring through a sleek web interface.
  2. Arduino Microcontroller: Meet Arduino, the magician behind the scenes. It translates Django’s commands into tangible actions, controlling the electronic door lock with finesse.
  3. Electronic Door Lock: Our door lock, wired to the Arduino, dances to Django’s tune, opening and closing with precision based on user permissions.

Unleashing the Power: Benefits Galore

  1. Fortified Security: Django’s robust authentication ensures only the right folks get in, while Arduino ensures the door obeys only the rightful commands.
  2. Anywhere, Anytime Access: With Django’s web interface, administrators manage access from their cozy office or the beach, thanks to Arduino’s real-time responsiveness.
  3. Peace of Mind: Real-time monitoring means knowing who’s coming and going, providing invaluable peace of mind for security-conscious minds.
  4. Tailored Solutions: The modular nature of Django and Arduino allows for custom solutions, whether it’s a cozy apartment or a bustling office complex.

Code:

Django Views (views.py):

from django.shortcuts import render, redirect
from django.contrib.auth import authenticate, login
from django.http import HttpResponse
import serial
from django.contrib.auth import logout

# Replace 'COM5' with the correct port where the Arduino is connected
ser = serial.Serial('COM5', 9600, timeout=1)

def login_view(request):
    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']
        user = authenticate(request, username=username, password=password)
        if user is not None:
            login(request, user)
            # Send 'O' command to open the door
            ser.write(b'O')
            return render(request, 'door_opened.html')
        else:
            return render(request, 'invalid.html')
    return render(request, 'login.html')


def logout_view(request):
    ser.write(b'C') # Send 'C' command to close the door
    logout(request)
    return redirect('login_view')

Arduino Code:

#include <Servo.h>

Servo myServo;  // Create a servo object

void setup() {
  myServo.attach(9);  // Attach the servo on pin 9 to the servo object
  Serial.begin(9600); // Begin serial communication at 9600 baud rate
  Serial.println("System ready. Send 'O' to open the door and 'C' to close the door.");
}

void loop() {
  if (Serial.available() > 0) {
    char command = Serial.read();
    if (command == 'O') {
      openDoor();
    } else if (command == 'C') {
      closeDoor();
    } else {
      Serial.println("Invalid command. Use 'O' to open and 'C' to close.");
    }
  }
}

// Function to open the door
void openDoor() {
  Serial.println("Opening door...");
  for (int pos = 0; pos <= 90; pos += 1) { // Move from 0 to 90 degrees
    myServo.write(pos);                    // Tell servo to go to position in variable 'pos'
    delay(10);                             // Wait 10 milliseconds between each degree
  }
  Serial.println("Door opened.");
}

// Function to close the door
void closeDoor() {
  Serial.println("Closing door...");
  for (int pos = 90; pos >= 0; pos -= 1) { // Move from 90 to 0 degrees
    myServo.write(pos);                    // Tell servo to go to position in variable 'pos'
    delay(10);                             // Wait 10 milliseconds between each degree
  }
  Serial.println("Door closed.");
}

door_opened.html:

Leave a Comment

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


Shopping Basket
Scroll to Top