You are on page 1of 5

EXPERIMENT NO : 13

Aim: Adafruit MQTT using the publisher method via MQ_2 sensor, Relay, NodeMcu and
Adafruit IO.

Apparatus:

I. 1x NodeMcu
II. 1x DHT11 Sensor
III. 1x BreadBoard
IV. 3x Male-Male Jumper Wires
V. Computer/Laptop with Internet Connectivity
VI. WiFi Connectivity/HotSpot.
VII. Relay Module

Theory:

MQ_2 has the following pin out as shown in the below Figure 1.

Fig 1.
MQ2 Gas sensor works on 5V DC and draws around 800mW. It can
detect LPG, Smoke, Alcohol, Propane, Hydrogen, Methane and Carbon Monoxide concentration
s anywhere from 200 to 10000ppm.

Specifications:

Schematic:

Fig 2.
Code:

#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>

#include <BlynkSimpleEsp8266.h>

BlynkTimer timer;

char auth[] = "ffSecIoBQ0qfef4NEvkD5HTnYaowwRMG";

char ssid[] = "TeamIOT";

char pass[] = "12345";

int n;

void setup()

Serial.begin(115200);

Blynk.begin(auth, ssid, pass);

pinMode(16,OUTPUT);

pinMode(5,OUTPUT);

timer.setInterval(1000L, sendUptime);

void sendUptime()

Blynk.virtualWrite(V1, n);

void loop()

Blynk.run();

timer.run();
n=analogRead(A0);

Serial.println(n);

if(n>550)

digitalWrite(16,HIGH);

digitalWrite(5,LOW);

delay(2000);

if(n<550)

digitalWrite(16,LOW);

digitalWrite(5,HIGH);

delay(2000);

}}

Hardware:

Fig 3.

Output:
The output is obtained on the Adafruit IO interface and Blynk App.

Fig 4.

Conclusion: From the above experiment we learnt to interface MQ_2 Gas sensor and Relay
with NodeMcu and create and application of it.

You might also like