Professional Documents
Culture Documents
Report Kampus Tugas
Report Kampus Tugas
Report Kampus Tugas
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
2
● ESP8266 NodeMCU board
● PIR sensor (e.g., HC-SR501)
● MQ-5 gas sensor
● Jumper wires
● Breadboard
● Piezo Buzzer
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");
● }
●
●