0% found this document useful (0 votes)
29 views8 pages

Lab Ex 3a 450

Uploaded by

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

Lab Ex 3a 450

Uploaded by

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

Reg.

No:22IT064
Ex No : 3 Home Automation Sensors - Gas Sensor, Servo motor, PIR Sensor
Date : 15/02/2024

Questions

1. Use Gas sensor to detect smoke in Fire alarms – Turn on the sprinklers using Servo and sound
an Alarm.(Tinkercad)
2. For a Mall’s restroom, use PIR sensor to turn ON/OFF the lights in their restrooms.(Hardware)
3. Count the number of students entering the KS Auditorium using PIR sensor and display free
seats according to the entry.(Tinkercad)
4. Assume your home Garage that opens the gate using servo based on the presence of the car
using PIR sensor.(Hardware)
5. Use Gas Sensor to show the Quality of Air in the environment used by people for
Walking(Hardware)
6. Apply the PIR sensor,Gas sensor and Servo motor to any use case on your own (Tinkercad)

Kit Required

Arduino Uno,Cable,Gas Sensor,Servo Motor, PIR Sensor,LED, M-F(5), M-M(3),

Aim:

To use Gas sensor to detect smoke in Fire alarms .to turn ON/OFF the lights using motion detection,count

entries in an auditorium ,servo based home garage automatic door

1. .Use Gas sensor to detect smoke in Fire alarms – Turn on the sprinklers using Servo and sound an Alarm.
(Tinkercad)

Code

#include <Servo.h>

const int PIR_PIN = 2;

const int GAS_SENSOR_PIN = A0;

const int SERVO_PIN = 9;

Servo servo;

void setup() {

Serial.begin(9600);

servo.attach(SERVO_PIN);

pinMode(PIR_PIN, INPUT);
Reg.No:22IT064
}

void loop() {

int motion = digitalRead(PIR_PIN);

if (motion == HIGH) {

int gasValue = analogRead(GAS_SENSOR_PIN);

Serial.print("Gas Value: ");

Serial.println(gasValue);

if (gasValue > 500) {

closeGasValve();}}}

void closeGasValve() {

servo.write(180); }

2. For a Mall’s restroom, use PIR sensor to turn ON/OFF the lights in their restrooms .(Hardware)

Code:

int led = 13;

int sensor = 2;

int state = LOW;

int val = 0;
Reg.No:22IT064
void setup() {

pinMode(led, OUTPUT);

pinMode(sensor, INPUT);

Serial.begin(9600);

void loop(){

val = digitalRead(sensor);

if (val == HIGH) {

digitalWrite(led, HIGH);

delay(100);

if (state == LOW) {

state = HIGH;

}} else {

digitalWrite(led, LOW);

delay(200);

if (state == HIGH){

state = LOW; }}}

3. Count the number of students entering the KS Auditorium using PIR sensor and display free seats according
to the entry.(Tinkercad)
Reg.No:22IT064
Code:

#include <LiquidCrystal.h>

const int PIR_PIN = 8;

const int EN = 3, RS = 2, D4 = 4, D5 = 5, D6 = 6, D7 = 7;

LiquidCrystal lcd(RS, EN, D4, D5, D6, D7);

int totalSeats = 100;

int freeSeats = 100;

void setup() {

Serial.begin(9600);

lcd.begin(16, 2);

pinMode(PIR_PIN, INPUT);

void loop() {

int PIR_state = digitalRead(PIR_PIN);

if (PIR_state == HIGH && freeSeats > 0) {

freeSeats--;

delay(500);

int occupiedSeats = totalSeats - freeSeats;

lcd.clear();

lcd.setCursor(0, 0);

lcd.print("Free Seats: ");

if (freeSeats < 100) {

lcd.print(" ");

if (freeSeats < 10) {

lcd.print(" ");

lcd.print(freeSeats);
Reg.No:22IT064
lcd.setCursor(0, 1);

lcd.print("OccupiedSeats:");

lcd.print(100-freeSeats);

delay(1000);

Circuit Diagram

4. Assume your home Garage that opens the gate using servo based on the presence of the car using PIR sensor.
(Hardware)

Code:

#include<Servo.h>

Servo servo1;

void setup()

pinMode(7, INPUT);

servo1.attach(11);

servo1.write(0);

void loop()

{ if(digitalRead(7)==HIGH)

{servo1.write(90);

delay(10);
Reg.No:22IT064
servo1.write(180);

delay(10); } }

Output:

5.Use Gas Sensor to show the Quality of Air in the environment used by people for Walking(Hardware)

Code:

void setup()

{ Serial.begin(9600); }

void loop(){

int val=analogRead(A0);

Serial.println(val);

delay(100);

analogWrite(6,val);}

Output:
Reg.No:22IT064

6.Apply the PIR sensor,Gas sensor and Servo motor to any use case on your own (Tinkercad)

Kitchen Safety System

Code:

#include <Servo.h>

Servo myservo;

int Value;

int pirPin = 2;

int pirStat = 0;

int pos = 0;

void setup() {

pinMode(pirPin, INPUT);

myservo.attach(9);

Serial.begin(9600);

pinMode(3, OUTPUT);

pinMode(A0, INPUT_PULLUP);

void loop(){

pirStat = digitalRead(pirPin);

if (pirStat == HIGH) {

for (pos = 0; pos <= 180; pos += 1) {

myservo.write(pos);

delay(15);}}

else {

digitalWrite(ledPin, LOW); }

Value = analogRead(A0);

Serial.println(Value);

delay(1000);

if(Value > 300)


Reg.No:22IT064
{analogWrite(3,500);

delay(1000);

}else

{analogWrite(3,0);}}

Result:

Thus,the given programs using gas sensor ,PIR sensor and Servo motor excuted in Tinkercad and using
hardware succuessfully.

You might also like