Lab Ex 3a 450
Lab Ex 3a 450
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
Aim:
To use Gas sensor to detect smoke in Fire alarms .to turn ON/OFF the lights using motion detection,count
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>
Servo servo;
void setup() {
Serial.begin(9600);
servo.attach(SERVO_PIN);
pinMode(PIR_PIN, INPUT);
Reg.No:22IT064
}
void loop() {
if (motion == HIGH) {
Serial.println(gasValue);
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 sensor = 2;
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){
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 EN = 3, RS = 2, D4 = 4, D5 = 5, D6 = 6, D7 = 7;
void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
pinMode(PIR_PIN, INPUT);
void loop() {
freeSeats--;
delay(500);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" ");
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)
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) {
myservo.write(pos);
delay(15);}}
else {
digitalWrite(ledPin, LOW); }
Value = analogRead(A0);
Serial.println(Value);
delay(1000);
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.