0% found this document useful (0 votes)
48 views

IOT Manual Final

Uploaded by

Priya Mohana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

IOT Manual Final

Uploaded by

Priya Mohana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 39

EX.

NO:1
DEVELOP AN APPLICATION FOR LED BLINK AND
PATTERN USING ARDUINO
DATE:

AIM
To Develop an application for LED Blink and Pattern using Arduino.

REQUIREMENTS:

Hardware Requirements:

 Arduino board (e.g., Arduino Uno)


 LEDs
 Resistors
 Breadboard
 Jumper wires

Software Requirements:

 Arduino IDE (Integrated Development Environment)


 USB cable to connect the Arduino board to your computer

ALGORITHM

Step 1:

Set up the hardware

 Connect the positive leg of each LED to a digital pin on the Arduino
board through a current-limiting resistor (usually 220-470 Ohms).
 Connect the negative leg of each LED to the ground (GND) pin on the
Arduino board.
Step 2:

Install the Arduino IDE

 Download and install the Arduino IDE from the official Arduino website
(https://www.arduino.cc/en/software).
1
 Connect the Arduino board to your computer using the USB cable.

Step 3:

Open the Arduino IDE and create a new sketch Launch the Arduino IDE.

 Click on "File" > "New" to create a new sketch.

Step 4:

Write the code

Step 5:

Upload the code to the Arduino board

 Click on "Sketch" > "Upload" to compile and upload the code to the
Arduino board.
 Ensure that the correct board and port are selected under the "Tools" menu.
Step 6:

Test the LED blink and pattern

PROGRAM

// Pin numbers for LEDs

const int ledPin1 = 2;

const int ledPin2 = 3;

const int ledPin3 = 4;

void setup() {

pinMode(ledPin1, OUTPUT);

pinMode(ledPin2, OUTPUT);

pinMode(ledPin3, OUTPUT);

2
}

void loop() {

// Blink LED 1

digitalWrite(ledPin1, HIGH);

delay(500);

digitalWrite(ledPin1, LOW);

delay(500);

// Blink LED 2

digitalWrite(ledPin2, HIGH);

delay(1000);

digitalWrite(ledPin2, LOW);

delay(1000);

// Pattern for LED 3

for (int i = 0; i < 3; i++) {

digitalWrite(ledPin3, HIGH);

delay(200);

digitalWrite(ledPin3, LOW);

delay(200);

delay(1000);

3
OUTPUT

RESULT

Thus, the application for led blink and pattern using arduino developed
successfully.

4
EX.NO:2
DEVELOP AN APPLICATION FOR LED PATTERN WITH
DATE: PUSH BUTTON CONTROL USING ARDUINO

AIM

To Develop an application for LED Pattern with Push Button control using
Arduino.

REQUIREMENTS:

Hardware Requirements:

 Arduino board (e.g., Arduino Uno)


 LEDs
 Push button
 Resistors
 Breadboard
 Jumper wires

Software Requirements:

 Arduino IDE
 USB cable to connect the Arduino board to your computer

ALGORITHM

Step 1:

Set up the hardware

 Connect the positive leg of each LED to digital pins on the Arduino board
through current-limiting resistors (e.g., 220-470 Ohms).
 Connect the negative leg of each LED to the ground (GND) pin on the
Arduino board.

5
 Connect one end of the push button to a digital pin on the Arduino board
and the other end to the ground (GND) pin.

Step 2:

Install the Arduino IDE

 Download and install the Arduino IDE from the official Arduino website
(https://www.arduino.cc/en/software).
 Connect the Arduino board to your computer using the USB cable.

Step 3:

 Open the Arduino IDE and create a new sketch

 Launch the Arduino IDE.

 Click on "File" > "New" to create a new sketch.

Step 4:

Write the code

Step 5:

 Upload the code to the Arduino board


 Click on "Sketch" > "Upload" to compile and upload the code to the
Arduino board.
 Ensure that the correct board and port are selected under the "Tools" menu.

Step 6:

 Test the LED pattern with push button control

6
PROGRAM

// Pin numbers for LEDs and push button

const int ledPin1 = 2;

const int ledPin2 = 3;

const int ledPin3 = 4;

const int buttonPin = 5;

// Variables to store LED states

bool ledState1 = LOW;

bool ledState2 = LOW;

bool ledState3 = LOW;

// Variable to store previous button state

int prevButtonState = HIGH;

void setup() {

pinMode(ledPin1, OUTPUT);

pinMode(ledPin2, OUTPUT);

pinMode(ledPin3, OUTPUT);

pinMode(buttonPin, INPUT_PULLUP);

void loop() {

// Read the current state of the button

int buttonState = digitalRead(buttonPin);

7
// Check if the button is pressed

if (buttonState == LOW && prevButtonState == HIGH) {

// Toggle LED states

ledState1 = !ledState1;

ledState2 = !ledState2;

ledState3 = !ledState3;

// Update LED states

digitalWrite(ledPin1, ledState1);

digitalWrite(ledPin2, ledState2);

digitalWrite(ledPin3, ledState3);

// Update previous button state

prevButtonState = buttonState;

8
OUTPUT

RESULT
Thus the application for LED patterns with push button control using Arduino
developed successfully.

9
EX.NO:3
DEVELOP AN APPLICATION FOR LED PATTERN WITH
DATE: PUSH BUTTON CONTROL USING ARDUINO

AIM

To Develop an application for display temperature values using the LM35


temperature sensor with Arduino

REQUIREMENTS:

Hardware Requirements:

 Arduino board (e.g., Arduino Uno)


 LM35 temperature sensor
 Breadboard
 Jumper wires

Software Requirements:

 Arduino IDE
 USB cable to connect the Arduino board to your computer

ALGORITHM

Step 1:

Set up the hardware

 Connect the LM35 temperature sensor to the Arduino board as follows:


 Connect the LM35's VCC pin to the 5V pin on the Arduino.
 Connect the LM35's GND pin to the GND pin on the Arduino.
 Connect the LM35's OUT pin to an analog input pin on the Arduino (e.g., A0).

Step 2:

Install the Arduino IDE

10
 Download and install the Arduino IDE from the official Arduino website
(https://www.arduino.cc/en/software).
 Connect the Arduino board to your computer using the USB cable.

Step 3:

Open the Arduino IDE and create a new sketch

 Launch the Arduino IDE.


 Click on "File" > "New" to create a new sketch.

Step 4:

Write the code

Step 5:

Upload the code to the Arduino board

 Click on "Sketch" > "Upload" to compile and upload the code to the Arduino
board.
 Ensure that the correct board and port are selected under the "Tools" menu.

Step 6:

View the temperature values

PROGRAM

// Pin number for the LM35 sensor

const int lm35Pin = A0;

void setup() {

Serial.begin(9600); // Initialize serial communication at 9600 bps

void loop() {

// Read the analog value from the LM35 sensor


11
int sensorValue = analogRead(lm35Pin);

// Convert the sensor value to temperature in degrees Celsius

float temperature = (sensorValue * 5.0) / 1024.0 * 100.0;

// Print the temperature value to the serial monitor

Serial.print("Temperature: ");

Serial.print(temperature);

Serial.println(" °C");

delay(1000); // Wait for 1 second

OUTPUT

RESULT
Thus the application to display temperature values using the LM35 temperature
sensor with Arduino is developed successfully.

12
EX.NO:4
DEVELOPAN AN APPLICATION FOR FORESR FIRE
DETECTION END NODE USING RASBERRY PI DEVICE
DATE:
AND SENSOR

AIM

To Develop an application for forest fire detection using a Raspberry Pi device


and a sensor.

REQUIREMENTS:

Hardware Requirements:

 Raspberry Pi (e.g., Raspberry Pi 4)

 Fire detection sensor (e.g., flame sensor or temperature sensor)

 Breadboard

 Jumper wires

Software Requirements:

 Raspbian OS (or any other suitable operating system for Raspberry Pi)

 Python (pre-installed on Raspbian)

 GPIO library for Python (usually pre-installed on Raspbian)

ALGORITHM

Step 1:

Set up the hardware

 Connect the fire detection sensor to the Raspberry Pi's GPIO pins. Refer to

the sensor's datasheet or documentation for pin connection details.

13
Step 2:

Install necessary libraries

 Ensure that you have the necessary libraries installed to control the
Raspberry Pi's GPIO pins. Most Raspbian installations include the GPIO
library by default.

Step 3:

Write the code

Step 4:

Run the code

 Save the code to a file with a .py extension (e.g., fire_detection.py).


 Open the terminal on the Raspberry Pi or connect to it remotely.
 Navigate to the directory where the code file is saved.
 Run the code using the following command: python fire_detection.py
 The code continuously reads the value from the fire detection sensor
connected to the specified GPIO pin.

PROGRAM

import RPi.GPIO as GPIO

import time

# Set the GPIO mode and pins

GPIO.setmode(GPIO.BCM)

flame_pin = 17 # Adjust the pin number as per your setup

# Set up the flame sensor pin as input

GPIO.setup(flame_pin, GPIO.IN)

try:

while True:
14
# Read the flame sensor value

flame_value = GPIO.input(flame_pin)

# Check if fire is detected

if flame_value == GPIO.LOW:

print("Fire detected!")

# Add your actions here, such as sending notifications or activating alarms

time.sleep(0.5)

except KeyboardInterrupt:

GPIO.cleanup()

OUTPUT

RESULT
Thus the application for Forest fire detection end node using Raspberry Pi device
and sensor developed successfully.

15
EX.NO:5
DEVELOP AN APPLICATION FOR HOME INTRUSION
DATE: DETECTION WEB APPLICATION

AIM

To Develop an application for home intrusion detection web application you will
need to combine hardware components such as sensors and a microcontroller with
software development for the web application interface.

REQUIREMENTS:

Hardware Requirements:

 Microcontroller (e.g., Arduino or Raspberry Pi)


 Sensors for intrusion detection (e.g., PIR motion sensors, door/window sensors)
 Optional: Siren or alarm system for alerts

Software Requirements:

 Web development framework (e.g., Django, Flask, Express.js, or any other


framework of your choice)
 HTML, CSS, and JavaScript for the frontend
 Backend programming language (e.g., Python, Node.js) for handling sensor data
and communication with the frontend
 Database (e.g., SQLite, MySQL, or MongoDB) to store sensor data and user
information
DEVELOPMENT PROCESS:

Design the user interface:

 Create wireframes or mockups to plan the layout and design of the web application.
 Determine the features and functionality you want to include, such as a dashboard
to view sensor statuses, user authentication, and alarm controls.

16
Set up the hardware:

 Connect the intrusion detection sensors (e.g., PIR motion sensors, door/window
sensors) to the microcontroller (e.g., Arduino or Raspberry Pi) following the
sensor's specifications.
 Set up any additional components, such as a siren or alarm system, and connect
them to the microcontroller.

Write the microcontroller code:

 Program the microcontroller to read data from the sensors and send the data to the
web application.
 Depending on the microcontroller used, you may need to install libraries or write
code to handle sensor inputs and communicate with the web application.

Set up the backend:

 Choose a web development framework and set up the backend environment.


 Create routes or APIs to handle data sent from the microcontroller.
 Implement user authentication and authorization to secure access to the web
application.

Develop the frontend:

 Create HTML, CSS, and JavaScript files to build the user interface.
 Implement the desired features, such as real-time sensor status updates, alarm
controls, and user authentication forms.
 Connect the frontend to the backend APIs for data retrieval and manipulation.

Store and retrieve data:


 Set up a database to store sensor data and user information.
 Implement database models and queries to store and retrieve data as needed.

17
Test and debug:

 Test the web application to ensure that the sensor data is received correctly, user
authentication works as expected, and other functionalities are functioning
properly.
 Debug any issues or errors that arise during testing.

Deploy the web application:


 Choose a hosting service or server to deploy the web application.
 Configure the necessary settings for deployment, such as database connections and
server configurations.

Monitor and maintain:

 Regularly monitor the web application and sensors to ensure proper functioning.
 Perform updates or modifications as needed to improve functionality or address
security concerns.
 Please note that the steps outlined above provide a general overview, and the
specific implementation may vary depending on your chosen hardware and
software components.
PROGRAM

Microcontroller code:

#include <ESP8266WiFi.h>

#include <ESP8266HTTPClient.h>

// WiFi credentials

const char* ssid = "YourWiFiSSID";

const char* password = "YourWiFiPassword";

// Web application endpoint

const char* endpoint = "http://yourwebapplication.com/endpoint";


18
// Pin number for the PIR motion sensor

const int pirPin = D2;

void setup() {

// Initialize serial communication

Serial.begin(9600);

// Connect to WiFi

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {

delay(1000);

Serial.println("Connecting to WiFi...");

Serial.println("Connected to WiFi!");

void loop() {

// Read the motion sensor value

int motionValue = digitalRead(pirPin);

if (motionValue == HIGH) {

// Motion detected, send data to the web application

sendMotionData(); }

delay(200); // Adjust delay as per your requirements

19
Set up the backend:

void sendMotionData() {

// Create an HTTP client object

HTTPClient http;

// Prepare the data to send

String data = "motion=detected"; // Customize the data format based on your web
application's requirements

// Send a POST request to the web application

http.begin(endpoint);

http.addHeader("Content-Type", "application/x-www-form-urlencoded");

int httpResponseCode = http.POST(data);

if (httpResponseCode > 0) {

Serial.print("HTTP response code: ");

Serial.println(httpResponseCode);

else {

Serial.println("Error sending request!");

// Close the connection

http.end();

20
Front end Html:

index.html:

<html>

<head>

<title>Home Intrusion Detection</title>

<link rel="stylesheet" type="text/css" href="styles.css">

</head>

<body>

<h1>Home Intrusion Detection</h1>

<div id="sensor-status">

<h2>Sensor Status</h2>

<table id="sensor-table">

<tr>

<th>Sensor</th>

<th>Status</th>

<th>Last Updated</th>

</tr>

</table>

</div>

<div id="alarm-controls">

<h2>Alarm Controls</h2>

<button id="activate-alarm">Activate Alarm</button>

<button id="deactivate-alarm">Deactivate Alarm</button>

</div>

<script src="script.js"></script>

</body>
21
</html>

styles.css:

body {

font-family: Arial, sans-serif;

h1 {

text-align: center;

#sensor-status {

margin-bottom: 20px;

#sensor-table {

width: 100%;

border-collapse: collapse;

#sensor-table th, #sensor-table td {

padding: 5px;

text-align: center;

border: 1px solid black;

#alarm-controls {

text-align: center;

margin-top: 20px;

#activate-alarm, #deactivate-alarm {

margin: 5px;
22
}

script.js: javascript

document.addEventListener("DOMContentLoaded", () => {

// Function to update sensor status

function updateSensorStatus(sensor, status, lastUpdated) {

const table = document.getElementById("sensor-table");

const newRow = table.insertRow(-1);

newRow.innerHTML =

`<td>${sensor}</td><td>${status}</td><td>${lastUpdated}</td>`;

// Function to update alarm status

function updateAlarmStatus(activated) {

const activateButton = document.getElementById("activate-alarm");

const deactivateButton = document.getElementById("deactivate-alarm");

if (activated) {

activateButton.disabled = true;

deactivateButton.disabled = false;

} else {

activateButton.disabled = false;

deactivateButton.disabled = true;

// Example data received from backend

const sensorData = [

23
{ sensor: "Motion Sensor 1", status: "Detected", lastUpdated: "2023-07-04" },

{ sensor: "Door Sensor 1", status: "Closed", lastUpdated: "2023-07-04" },

{ sensor: "Window Sensor 1", status: "Open", lastUpdated: "2023-07-04" },

];

const alarmActivated = true;

// Update sensor status table

sensorData.forEach(data => {

updateSensorStatus(data.sensor, data.status, data.lastUpdated);

});

// Update alarm status

updateAlarmStatus(alarmActivated);

// Event listener for activate alarm button

document.getElementById("activate-alarm").addEventListener("click", () => {

// Send request to backend API to activate the alarm

console.log("Activating alarm...");

});

// Event listener for deactivate alarm button

document.getElementById("deactivate-alarm").addEventListener("click", () => {

// Send request to backend API to deactivate the alarm

console.log("Deactivating alarm...");

});

});

24
OUTPUT

RESULT
Thus, the application for Forest fire detection end node using Raspberry Pi device
and sensor developed successfully.

25
EX.NO:6 DEVELOP AN APPLICATION FOR FOREST FIRE
DETECTION END NODE USING RASPBERRY PI
DATE: DEVICE AND SENSOR

AIM

To develop a Smart Parking application using Python and Django.

PROCEDURE:

Step 1:

 Set up Django Project


 Install Django: Run pip install django in your command line.
 Create a new Django project: Run django-admin startproject smartparking in
your desired directory.
 Change directory to the project: Run cd smartparking.
 Create a new Django app: Run python manage.py startapp parking.

Step 2:

Define Models

 In the parking app directory, open models.py and define your models for the
application. For example, you may have models for ParkingLot, ParkingSpace,
and Booking.

Step 3:

Create Views

 In the parking app directory, open views.py and define views for your
application. These views handle requests and render templates.
 Implement views to handle actions such as displaying available parking spaces,
booking a space, canceling a booking, etc.

26
Step 4:

Configure URLs

 In the project's urls.py file, include the URLs for your app.

 In the parking app directory, create a new file called urls.py and define the URLs

specific to your app.

Step 5:

Create Templates

 Create a templates directory inside the parking app directory.

 Create HTML templates for each view in the templates directory.

Step 6:

Implement Business Logic

 Add necessary business logic in your views to handle parking space availability,
booking validations, payment processing, etc.

Step 7:

Set Up Database

 Configure your database settings in the project's settings.py file.


 Apply migrations to create the necessary database tables: Run python manage.py
make migrations followed by python manage.py migrate.

Step 8:

Run the Application

 Start the development server: Run python manage.py runserver in the project
directory.

27
 Access the application in your browser at http://localhost:8000 or the address

provided by the development server.

 These are the basic steps to set up a Smart Parking application using Python and

Django

PROGRAM

Ensure that you have Python installed on your system. Then, open your command line
interface and run the following command to

Step 1: install Django:

pip install django

Step 2: Create a new Django project

Navigate to the directory where you want to create your Django project. In the
command line, run the following command:

django-admin startproject smartparking

Step 3: Change directory to the project

Move into the project directory by running the following command:

bash

cd smartparking

Step 4: Create a new Django app

Create a new Django app named "parking" by running the following command:

python manage.py startapp parking

Now you have successfully set up your Django project for the Smart Parking
application.

Python from django.db import models

class ParkingLot(models.Model):

name = models.CharField(max_length=100)
28
address = models.CharField(max_length=200)

class ParkingSpace(models.Model):

lot = models.ForeignKey(ParkingLot, on_delete=models.CASCADE)

number = models.IntegerField()

is_available = models.BooleanField(default=True)

class Booking(models.Model):

space = models.ForeignKey(ParkingSpace, on_delete=models.CASCADE)

user = models.ForeignKey(User, on_delete=models.CASCADE)

start_time = models.DateTimeField(auto_now_add=True)

end_time = models.DateTimeField()

In the parking app directory, open views.py and define your views.

Create a templates directory inside the parking app directory. In the templates
directory, create HTML templates for each view. For example, create a file
spaces.html:

html

<h1>Parking Spaces</h1>

<ul>

{% for space in spaces %}

<li> {{ space.number }} - {% if space.is_available %}Available{% else

%}Occupied{% endif %}</li>

{% endfor %}

</ul>

29
Define Models:
from django.db import models

from django.contrib.auth.models import User

class ParkingLot(models.Model):

name = models.CharField(max_length=100)

address = models.CharField(max_length=200)

def str (self):

return self.name

class ParkingSpace(models.Model):

lot = models.ForeignKey(ParkingLot, on_delete=models.CASCADE)

number = models.IntegerField()

is_available = models.BooleanField(default=True)

def str (self):

return f"Space {self.number} ({self.lot.name})"

class Booking(models.Model):

space = models.ForeignKey(ParkingSpace, on_delete=models.CASCADE)

user = models.ForeignKey(User, on_delete=models.CASCADE)

start_time = models.DateTimeField()

end_time = models.DateTimeField()

def str (self):

return f"{self.space} - {self.user.username}"

Create Views:

from django.db import models

from django.contrib.auth.models import User

class ParkingLot(models.Model):

name = models.CharField(max_length=100)
30
address = models.CharField(max_length=200)

def str (self):

return self.name

class ParkingSpace(models.Model):

lot = models.ForeignKey(ParkingLot, on_delete=models.CASCADE)

number = models.IntegerField()

is_available = models.BooleanField(default=True)

dfrom django.shortcuts import render, redirect

from .models import ParkingLot, ParkingSpace, Booking

def parking_lot_status(request):

parking_lots = ParkingLot.objects.all()

return render(request, 'parking_status.html', {'parking_lots': parking_lots})

def book_parking_space(request):

if request.method == 'POST':

parking_lot_id = request.POST.get('parking_lot')

start_time = request.POST.get('start_time')

duration = int(request.POST.get('duration'))

parking_lot = ParkingLot.objects.get(id=parking_lot_id)

available_spaces = ParkingSpace.objects.filter(lot=parking_lot,
is_available=True)

if available_spaces:

space = available_spaces.first()

space.is_available = False

space.save()

end_time = calculate_end_time(start_time, duration)

31
user = request.user

booking = Booking(space=space, user=user, start_time=start_time,


end_time=end_time)booking.save()

return redirect('booking_success')

else:

returnrender(request,'booking.html',{'parking_lots':
ParkingLot.objects.all(), 'error_message': 'No available spaces.'})

else:

returnrender(request,'booking.html',{'parking_lots':
ParkingLot.objects.all()})

def booking_success(request):

return render(request, 'booking_success.html')

Configure URLs :
from django.urls import include

urlpatterns = [

# Other URL patterns for your project

path('parking/', include('parking.urls')),

In the parking app directory, create a new file called urls.py and define the URLs specific
to your app. Open the urls.py file in the parking app directory and add the following
code:

from django.urls import path

from . import views

urlpatterns = [

path('status/', views.parking_lot_status, name='parking_lot_status'),

path('book/', views.book_parking_space, name='book_parking_space'),

path('booking_success/', views.booking_success, name='booking_success'),


32
]

html

<html>

<head>

<title>Parking Lot Status</title>

</head>

<body>

<h1>Parking Lot Status</h1>

<ul>

{% for parking_lot in parking_lots %}

<li>

<h2>{{ parking_lot.name }}</h2>

<ul>

{% for space in parking_lot.parkingspace_set.all %}

<li>Space {{ space.number }}: {% if space.is_available %}Available{%


else %}Occupied{% endif %}</li>

{% endfor %}

</ul>

</li>

{% endfor %}

</ul>

</body>

</html>

33
Create an HTML template for the book_parking_space view. Inside the templates
directory, create a file called booking.html and add the following code:

html

<html>

<head>

<title>Book Parking Space</title>

</head>

<body>

<h1>Book Parking Space</h1>

{% if error_message %}

<p>{{ error_message }}</p>

{% endif %}

<form method="POST" action="{% url 'book_parking_space' %}">

{% csrf_token %}

<label for="parking_lot">Select Parking Lot:</label>

<select id="parking_lot" name="parking_lot">

{% for parking_lot in parking_lots %}

<option value="{{ parking_lot.id }}">{{ parking_lot.name }}</option>

{% endfor %}

</select>

<br>

<label for="start_time">Start Time:</label>

<input type="datetime-local" id="start_time" name="start_time" required>

<br>

<label for="duration">Duration (in hours):</label>

<input type="number" id="duration" name="duration" required>


34
<br>

<input type="submit" value="Book">

</form>

</body>

</html>

Create an HTML template for the booking_success view. Inside the templates
directory, create a file called booking_success.html and add the following code:

html

<html>

<head>

<title>Booking Success</title>

</head>

<body>

<h1>Booking Successful!</h1>

<p>Your parking space has been booked successfully.</p>

</body>

</html>

Implement business logic:

from django.shortcuts import render, redirect

from .models import ParkingLot, ParkingSpace, Booking

def parking_lot_status(request):

parking_lots = ParkingLot.objects.all()

return render(request, 'parking_status.html', {'parking_lots': parking_lots})

def book_parking_space(request):

if request.method == 'POST':

35
parking_lot_id = request.POST.get('parking_lot')

start_time = request.POST.get('start_time')

duration = int(request.POST.get('duration'))

parking_lot = ParkingLot.objects.get(id=parking_lot_id)

available_spaces = ParkingSpace.objects.filter(lot=parking_lot,
is_available=True)

if available_spaces:

space = available_spaces.first()

space.is_available = False

space.save()

end_time = calculate_end_time(start_time, duration)

user = request.user

booking = Booking(space=space, user=user, start_time=start_time,


end_time=end_time)

booking.save()

# Additional business logic such as payment processing can be added here


return redirect('booking_success')

else:

return render(request, 'booking.html', {'parking_lots': ParkingLot.objects.all(),


'error_message': 'No available spaces.'})

else:

return render(request, 'booking.html', {'parking_lots': ParkingLot.objects.all()})

def booking_success(request):

return render(request, 'booking_success.html')

36
SETUP DATABASE:
 Open the settings.py file in your project's directory.

 Locate the DATABASES configuration section and update it with your database
settings. Here's an example configuration for a SQLite database:

DATABASES = {

'default': {

'ENGINE': 'django.db.backends.sqlite3',

'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),

Replace 'db.sqlite3' with the desired path and name for your SQLite database file.
Alternatively, you can use other database engines such as MySQL or PostgreSQL by
modifying the 'ENGINE' and other relevant settings accordingly.

Save the settings.py file.

Apply migrations to create the necessary database tables. Open the terminal or
command prompt, navigate to your project's directory, and run the following commands:

python manage.py makemigrations

python manage.py migrate

The make migrations command will generate migration files based on the changes
in your models, and the migrate command will apply those migrations to create the
corresponding database tables.

Make sure you have the necessary database engine installed and configured
properly before running the migration commands.

Once the migrations are applied successfully, your database will be set up with
the required tables to store the data defined in your models.

37
RUN THE APPLICATION:

 Open the terminal or command prompt.

 Navigate to your project directory where the manage.py file is located.


START THE DEVELOPMENT SERVER BY RUNNING THE FOLLOWING COMMAND:

python manage.py runserver


The development server will start running, and you should see output similar to
the following:

Starting development server at http://127.0.0.1:8000/

Quit the server with CONTROL-C.

Open your web browser and access the application by entering the following URL:

http://localhost:8000

 Alternatively, you can use the address provided by the development server (e.g.,
http://127.0.0.1:8000/).

 The Smart Parking application should now be accessible in your browser, and you
can interact with the different views and functionalities you have implemented.

 Ensure that you have the necessary dependencies installed and the database is
properly configured as mentioned earlier.

 You can now test and explore the Smart Parking application, book parking spaces,
view the parking lot status, and perform other actions as defined in your views
and templates.

 Remember to handle any errors or exceptions that may occur during the execution
of the application and provide appropriate feedback to the users.

38
OUTPUT

RESULT
Thus the application for Forest fire detection end node using Raspberry Pi device
and sensor developed successfully.

39

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy