0% found this document useful (0 votes)
50 views8 pages

Experiment 5

The document describes an experiment interfacing DHT11 and MQ3 sensors with a Raspberry Pi to monitor temperature, humidity, and smoke levels and send the data to Thingspeak cloud. The DHT11 measures temperature and humidity, while the MQ3 detects smoke or gas. The circuit connects the sensors to the Raspberry Pi along with code to read the sensors, send the data to Thingspeak via an API key, and display the results on the cloud dashboard and Freeboard GUI. The goal is to store sensor information on the cloud for remote monitoring of environmental conditions.
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)
50 views8 pages

Experiment 5

The document describes an experiment interfacing DHT11 and MQ3 sensors with a Raspberry Pi to monitor temperature, humidity, and smoke levels and send the data to Thingspeak cloud. The DHT11 measures temperature and humidity, while the MQ3 detects smoke or gas. The circuit connects the sensors to the Raspberry Pi along with code to read the sensors, send the data to Thingspeak via an API key, and display the results on the cloud dashboard and Freeboard GUI. The goal is to store sensor information on the cloud for remote monitoring of environmental conditions.
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/ 8

MIOT- Lab Manual

Experiment No. – 5

Title: Introduction to MQTT/ CoAP and sending sensor data to cloud using Raspberry-
Pi/Beagle board/Arduino.

Aim: Interfacing of DHT11 (Humidity, Temperature) sensor and MQ3 Smoke Sensor with
Raspberry Pi board and store the information on thingspeak cloud.

Hardware Requirements: Raspberry Pi 3 B+, DHT11 Sensor, MQ3 Smoke Sensor


Software Requirements: Python 3 IDE
Theory:
DHT11 Sensor:

Fig: 1 DHT11 Sensor

The DHT11 is a basic, ultra low-cost digital temperature and humidity sensor. It uses a
capacitive humidity sensor and a thermistor to measure the surrounding air, and spits out a

Department of Electronics & Telecommunication Engineering (2023-24)


MIOT- Lab Manual

Department of Electronics & Telecommunication Engineering (2023-24)


MIOT- Lab Manual

digital signal on the data pin (no analog input pins needed). It’s fairly simple to use, but
requires careful timing to grab data. The only real downside of this sensor is you can only get
new data from it once every 2 seconds, so when using library, sensor readings can be up to 2
seconds old.

Specifications
 Low cost
 3 to 5V power and I/O
 2.5mA max current use during conversion (while requesting data)
 Good for 20-80% humidity readings with 5% accuracy
 Good for 0-50°C temperature readings ±2°C accuracy
 Body size 15.5mm x 12mm x 5.5mm
 4 pins with 0.1" spacing

Pin Configuration

Fig: 2 Pin description of DHT11

No: Pin Name Description


For Sensor
1 Vcc Power supply 3.5V to 5.5V
2 Data Outputs both Temperature and Humidity through serial Data
3 NC No Connection and hence not used
4 Ground Connected to the ground of the circuit
For module
1 Vcc Power supply 3.5V to 5.5V
2 Data Outputs both Temperature and Humidity through serial Data
3 Ground Connected to the ground of the circuit

Department of Electronics & Telecommunication Engineering (2023-24)


MIOT- Lab Manual

MQ3 Smoke Sensor:

Fig: 3 Pin description of MQ3 Sensor

The MQ3 Gas Sensor module detects gas leakage in home and industry. The MQ3 Gas
Sensor can detect Alcohol, Benzine, Methane, Hexane, LPG, CO. It can detect the presence
of alcohol gases at concentrations from 0.05 mg/L to 10 mg/L
The sensitive material used for this sensor is SnO2, whose conductivity is lower in clean air.
Its conductivity increases as the concentration of alcohol gases increases. It has high
sensitivity to alcohol and has a good resistance to disturbances due to smoke, vapor and
gasoline.
This module provides both digital and analog outputs. MQ3 gas sensor module can be easily
interfaced with Microcontrollers, Arduino Boards, Raspberry Pi etc. The MQ series of gas
sensors use a small heater inside with an electrochemical sensor. They are sensitive to a range
of gasses and are used indoors at room temperature.

Due to its fast response time and high sensitivity, measurements can be taken as soon as
possible. The sensor sensitivity can be adjusted by using the potentiometer.

Features:
High sensitivity and fast response
Wide detecting scope
stable and Long life
Simple drive circuit
Analog and Digital Outputs

Pinout:
Vcc – Power Supply (5V)
GND – Ground
AO – Analog Output

Department of Electronics & Telecommunication Engineering (2023-24)


MIOT- Lab Manual

DO – Digital Output

Raspberry pi 3:-
The Raspberry Pi is a low cost, credit-card sized computer that plugs into a computer
monitor or TV, and uses a standard keyboard and mouse. It is a capable little device that
enables people of all ages to explore computing, and to learn how to program in languages
like Scratch and Python. It’s capable of doing everything you’d expect a desktop computer to
do, from browsing the internet and playing high-definition video, to making spreadsheets,
word-processing, and playing games.
Raspberry Pi 3 Model B was released in February 2016 with a 64bit quad core processor, on-
board Wi-Fi, Bluetooth and USB boot capabilities. On Pi Day 2018 model 3B+ appeared
with a faster 1.4 GHz processor and a three times faster network based on gigabit
Ethernet (300 Mbit / s) or 2.4 / 5 GHz dual-band Wi-Fi (100 Mbit / s). Other options
are: Power over Ethernet (PoE), USB boot and network boot (an SD card is no longer
required). This allows the use of the Pi in hard-to-reach places (possibly without electricity).

Fig.4 Raspberry Pi 3 Model B+

Department of Electronics & Telecommunication Engineering (2023-24)


MIOT- Lab Manual

Circuit Diagram:

Fig. 5 Interfacing of DHT11 & MQ3 sensor with Raspberry Pi

Fig. 6 Data uploaded on Thingspeak Cloud

Department of Electronics & Telecommunication Engineering (2023-24)


MIOT- Lab Manual

Fig. 7 Data uploaded on Freeboard (GUI)

Procedure:
 Create a channel on the cloud (Thingspeak)
 Make the connection as per circuit diagram
 Open Python IDE
 Write code in Editor window and save file
 Compile the code
 Open thingspeak channel
 Observe the result

Conclusion:

Tinkercad Simulation Link:


https://www.tinkercad.com/dashboard?type=circuits&collection=designs

Department of Electronics & Telecommunication Engineering (2023-24)


MIOT- Lab Manual

Code:

import sys
import Adafruit_DHT as dht
from time import sleep
import urllib
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(24, GPIO.IN) #Smoke Sensor Digital output

GPIO.setwarnings(False)

def DHT11_data():
# Reading from DHT11 and storing the temperature and humidity
humi, temp = dht.read_retry(11, 23)
return humi, temp

# Enter Your API key here


myAPI = "ZQN4Z08XZ9HLOZY0"

# URL where we will send the data, Don't change it


baseURL = "https://api.thingspeak.com/update?api_key=%s" % myAPI

while True:

humidity, temperature = DHT11_data()


print ('Temp: {0:0.1f} C Humidity: {1:0.1f} %'.
format(temperature,humidity))

input_state = GPIO.input(24)

if input_state == False:
smoke = 1
print('Smoke Detected')
print(smoke)
else:
smoke = 0
print('Smoke is not Detected')
print(smoke)

from urllib.request import urlopen


content = urlopen(baseURL + "&field1=%s&field2=%s&field3=%s" %
(temperature,humidity,smoke))

sleep(15)

Subject Teacher

Department of Electronics & Telecommunication Engineering (2023-24)

You might also like