Experiment 5
Experiment 5
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.
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
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
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
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).
Circuit Diagram:
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:
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
while True:
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)
sleep(15)
Subject Teacher