IOT Manual Final
IOT Manual Final
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:
Software Requirements:
ALGORITHM
Step 1:
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:
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.
Step 4:
Step 5:
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:
PROGRAM
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);
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:
Software Requirements:
Arduino IDE
USB cable to connect the Arduino board to your computer
ALGORITHM
Step 1:
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:
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:
Step 4:
Step 5:
Step 6:
6
PROGRAM
void setup() {
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
void loop() {
7
// Check if the button is pressed
ledState1 = !ledState1;
ledState2 = !ledState2;
ledState3 = !ledState3;
digitalWrite(ledPin1, ledState1);
digitalWrite(ledPin2, ledState2);
digitalWrite(ledPin3, ledState3);
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
REQUIREMENTS:
Hardware Requirements:
Software Requirements:
Arduino IDE
USB cable to connect the Arduino board to your computer
ALGORITHM
Step 1:
Step 2:
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:
Step 4:
Step 5:
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:
PROGRAM
void setup() {
void loop() {
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
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
REQUIREMENTS:
Hardware Requirements:
Breadboard
Jumper wires
Software Requirements:
Raspbian OS (or any other suitable operating system for Raspberry Pi)
ALGORITHM
Step 1:
Connect the fire detection sensor to the Raspberry Pi's GPIO pins. Refer to
13
Step 2:
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:
Step 4:
PROGRAM
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(flame_pin, GPIO.IN)
try:
while True:
14
# Read the flame sensor value
flame_value = GPIO.input(flame_pin)
if flame_value == GPIO.LOW:
print("Fire detected!")
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:
Software Requirements:
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.
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.
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.
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.
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
void setup() {
Serial.begin(9600);
// Connect to WiFi
WiFi.begin(ssid, password);
delay(1000);
Serial.println("Connecting to WiFi...");
Serial.println("Connected to WiFi!");
void loop() {
if (motionValue == HIGH) {
sendMotionData(); }
19
Set up the backend:
void sendMotionData() {
HTTPClient http;
String data = "motion=detected"; // Customize the data format based on your web
application's requirements
http.begin(endpoint);
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
if (httpResponseCode > 0) {
Serial.println(httpResponseCode);
else {
http.end();
20
Front end Html:
index.html:
<html>
<head>
</head>
<body>
<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>
</div>
<script src="script.js"></script>
</body>
21
</html>
styles.css:
body {
h1 {
text-align: center;
#sensor-status {
margin-bottom: 20px;
#sensor-table {
width: 100%;
border-collapse: collapse;
padding: 5px;
text-align: center;
#alarm-controls {
text-align: center;
margin-top: 20px;
#activate-alarm, #deactivate-alarm {
margin: 5px;
22
}
script.js: javascript
document.addEventListener("DOMContentLoaded", () => {
newRow.innerHTML =
`<td>${sensor}</td><td>${status}</td><td>${lastUpdated}</td>`;
function updateAlarmStatus(activated) {
if (activated) {
activateButton.disabled = true;
deactivateButton.disabled = false;
} else {
activateButton.disabled = false;
deactivateButton.disabled = true;
const sensorData = [
23
{ sensor: "Motion Sensor 1", status: "Detected", lastUpdated: "2023-07-04" },
];
sensorData.forEach(data => {
});
updateAlarmStatus(alarmActivated);
document.getElementById("activate-alarm").addEventListener("click", () => {
console.log("Activating alarm...");
});
document.getElementById("deactivate-alarm").addEventListener("click", () => {
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
PROCEDURE:
Step 1:
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
Step 5:
Create Templates
Step 6:
Add necessary business logic in your views to handle parking space availability,
booking validations, payment processing, etc.
Step 7:
Set Up Database
Step 8:
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
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
Navigate to the directory where you want to create your Django project. In the
command line, run the following command:
bash
cd smartparking
Create a new Django app named "parking" by running the following command:
Now you have successfully set up your Django project for the Smart Parking
application.
class ParkingLot(models.Model):
name = models.CharField(max_length=100)
28
address = models.CharField(max_length=200)
class ParkingSpace(models.Model):
number = models.IntegerField()
is_available = models.BooleanField(default=True)
class Booking(models.Model):
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>
{% endfor %}
</ul>
29
Define Models:
from django.db import models
class ParkingLot(models.Model):
name = models.CharField(max_length=100)
address = models.CharField(max_length=200)
return self.name
class ParkingSpace(models.Model):
number = models.IntegerField()
is_available = models.BooleanField(default=True)
class Booking(models.Model):
start_time = models.DateTimeField()
end_time = models.DateTimeField()
Create Views:
class ParkingLot(models.Model):
name = models.CharField(max_length=100)
30
address = models.CharField(max_length=200)
return self.name
class ParkingSpace(models.Model):
number = models.IntegerField()
is_available = models.BooleanField(default=True)
def parking_lot_status(request):
parking_lots = ParkingLot.objects.all()
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()
31
user = request.user
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):
Configure URLs :
from django.urls import include
urlpatterns = [
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:
urlpatterns = [
html
<html>
<head>
</head>
<body>
<ul>
<li>
<ul>
{% 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>
</head>
<body>
{% if error_message %}
{% endif %}
{% csrf_token %}
{% endfor %}
</select>
<br>
<br>
</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>
</body>
</html>
def parking_lot_status(request):
parking_lots = ParkingLot.objects.all()
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()
user = request.user
booking.save()
else:
else:
def booking_success(request):
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',
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.
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:
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 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