0% found this document useful (0 votes)
24 views

Chapter 4

This document describes the implementation of a smoke detection monitoring system. It includes a schematic diagram and code for executing the system. The code connects to WiFi, displays system information on an OLED screen, reads gas sensor values, uploads data to ThingSpeak if the value is above a threshold, and triggers alarms by turning on an LED and relays.
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)
24 views

Chapter 4

This document describes the implementation of a smoke detection monitoring system. It includes a schematic diagram and code for executing the system. The code connects to WiFi, displays system information on an OLED screen, reads gas sensor values, uploads data to ThingSpeak if the value is above a threshold, and triggers alarms by turning on an LED and relays.
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/ 4

IMPLEMENTAION CHAPTER 4

CHAPTER 4
IMPLEMENTATION
4.1 SCHEMATIC DIAGRAM

Fig 4.1 Schematic diagram

Department of Electrical and Electronic Engineering Page | 56


IMPLEMENTAION December 30, 1899

4.3 CODE FOR EXECUTION

#include <Wire.h>
#include <ESP8266WiFi.h>
#include "ThingSpeak.h"
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
const int GAS = A0;
const int LED = 2;

const int V0 = 14;


const int V1 = 12;

const char* ssid = "project"; // your network SSID (name)


const char* password = "123456789"; // your network password

WiFiClient client;

unsigned long myChannelNumber = 1535033;


const char * myWriteAPIKey = "XQA97ZVFJMI2VBC1";

void setup() {
Serial.begin(9600);
pinMode(V0, OUTPUT);
pinMode(V1, OUTPUT);
pinMode(LED, OUTPUT);
delay(200);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
for (;;);
}
delay(1000);
display.clearDisplay();

Department of Electrical and Electronic Engineering Page | 57


IMPLEMENTAION December 30, 1899

display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.println("NO SMOKING ZONE MONITORING SYSTEM");
display.display();

display.setCursor(0, 30); // Start at top-left corner


display.setTextColor(WHITE, BLACK); // Draw white text
display.println(("Attempt to connect"));
display.display();
delay(1000);

// Connect or reconnect to WiFi


if (WiFi.status() != WL_CONNECTED) {
Serial.println("Attempting to connect");
delay(1000);
while (WiFi.status() != WL_CONNECTED) {
WiFi.begin(ssid, password);
delay(5000);
}
}
display.setCursor(0, 40); // Start at top-left corner
display.println(("WiFi connected..!"));
Serial.println("WiFi connected..!");
display.display();
delay(1000);

display.setCursor(0, 50); // Start at top-left corner


display.setTextColor(WHITE, BLACK);
display.print(("IP: "));
display.print(WiFi.localIP());
Serial.print("Got IP: ");
Serial.println(WiFi.localIP());
display.display();
delay(2000);

WiFi.mode(WIFI_STA);

Department of Electrical and Electronic Engineering Page | 58


IMPLEMENTAION December 30, 1899

ThingSpeak.begin(client);
digitalWrite(LED, LOW);
digitalWrite(V0, LOW);
digitalWrite(V1, LOW);
// digitalWrite(V0, HIGH);
// digitalWrite(V1, HIGH);
}

void loop() {
display.clearDisplay();
delay(500);
int sensorValue = analogRead(GAS);
display.setCursor(0, 10);
display.print("GAS : ");
display.print(sensorValue);
display.display();
delay(2000);
if (sensorValue >= 450)
{
display.setCursor(0, 30);
display.println("GAS Abnormal");
display.display();
delay(2000);
digitalWrite(V0, HIGH);
digitalWrite(LED, HIGH);
delay(5000);
digitalWrite(LED, LOW);
digitalWrite(V0, LOW);
delay(1000);
digitalWrite(V1, HIGH);
delay(6000);
digitalWrite(V1, LOW);
}
ThingSpeak.setField(1, sensorValue);
ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
}

Department of Electrical and Electronic Engineering Page | 59

You might also like