Report Kampus Tugas

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

INTERNET OF THINGS COURSE

Home Safety System


(FINAL REPORT)

Submitted by:
GROUP IT CLASS 2
Elza Muhamad Qaynan 00120210006
8
Gilang P Nurdiansyah 00120210010
Hadi Aflaha S 0
00120210000
3
Muhammad Nafiis Adi N 00120210010
7
Muhammad Parvez 00120210001
Pasha 5
Muhammad Rayyis A F 00120210003
8

1
Zaydan Taqiyyuddin A 00120210002
0

MAY 2023
PRESIDENT UNIVERSITY
I. Project Description

A. Project Title

The title of our project is Home Safety System.

B. How the Project Works

The NodeMCU board connects to the WiFi that is set


within the code. After it’s connected to the WiFi, the MQ-5
gas sensor and PIR sensor is ready to get and send data
through internet.

We’re using a web based app called Blynk.io to monitor


and receive data from both the MQ-5 Gas sensor and PIR
sensor. The app can be used by both PC and Mobile Phones.

The MQ-5 gas sensor will detect any gas that is


present and write it as value then the data is sent to Blynk, if
the detected value is > 500, the piezo buzzer will sound and
there will be a notification from Blynk. If the value goes < 500
then the buzzer will stop sounding.

The PIR sensor will capture any movement that is


detected by the sensor then send the state to Blynk, if the
PIR sensor detects a movement, then the piezo buzzer will
sound and there will be a notification from Blynk.

C. Component that listed in the project:

2
● ESP8266 NodeMCU board
● PIR sensor (e.g., HC-SR501)
● MQ-5 gas sensor
● Jumper wires
● Breadboard
● Piezo Buzzer

II. Circuit Diagram

A. Circuit Diagram

3
III. Sketch

● Code
● #include <ESP8266WiFi.h>
● #include <BlynkSimpleEsp8266.h> // for connect to blynk and get information from
sensor

● #define PIR_PIN D2 // PIR sensor connected to D2 pin
● #define GAS_PIN A0 // MQ-5 gas sensor connected to analog pin A0
● #define BUZZER_PIN D4 // Buzzer connected to D4 pin

● char auth[] = "mEYDW8-Em5cOsClMXxckeGpFBNQGUiE7";
● char ssid[] = "Redmi Note 8";
● char password[] = "11111111";

● BlynkTimer timer;
● int readings[2]; // Array is used to store the readings from the PIR sensor and the gas
sensor

● void setup() {
● Serial.begin(115200);
● pinMode(PIR_PIN, INPUT);
● pinMode(GAS_PIN, INPUT);
● pinMode(BUZZER_PIN, OUTPUT);

● connectToWiFi();
● Blynk.config(auth);
● timer.setInterval(1000L, sensorReading);
● }

● void loop() {

4
● Blynk.run(); // This function is responsible for communication the ESP8266 board and
the Blynk server
● timer.run();
● }

● void sensorReading() {
● int pirState = digitalRead(PIR_PIN);
● int gasValue = analogRead(GAS_PIN);

● readings[0] = pirState; // represents the PIR sensor state
● readings[1] = gasValue;// represents the gas sensor

● Blynk.virtualWrite(V1, readings[0]); // V1 is for connect datastream in blynk
● Blynk.virtualWrite(V2, readings[1]);

● if (pirState == HIGH || gasValue > 500) {
● digitalWrite(BUZZER_PIN, HIGH); // Turn on the buzzer
● Blynk.logEvent("Motion detected or gas detected!");
● } else { //if pirState == low || gasvalue < 500
● digitalWrite(BUZZER_PIN, LOW); // Turn off the buzzer
● }
● }

● void connectToWiFi() {
● WiFi.begin(ssid, password);
● Serial.print("Connecting to WiFi...");

● while (WiFi.status() != WL_CONNECTED) {
● delay(1000);
● Serial.print(".");
● }

● Serial.println();
● Serial.println("Connected to WiFi");
● }

You might also like