0% found this document useful (0 votes)
97 views6 pages

Experiment No 8 Gas and Light Sensor

The experiment aims to (1) detect gas contents using a gas sensor and light levels using a light sensor, (2) send this sensor data to ThingSpeak cloud in real-time, and (3) view the measured values on ThingSpeak and potentially perform further analysis. The gas and light sensors are connected to an Arduino Uno, which reads the sensor values at intervals and sends the data to ThingSpeak cloud using WiFi. The measured values can be viewed live on ThingSpeak and downloaded as CSV files for future processing.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
97 views6 pages

Experiment No 8 Gas and Light Sensor

The experiment aims to (1) detect gas contents using a gas sensor and light levels using a light sensor, (2) send this sensor data to ThingSpeak cloud in real-time, and (3) view the measured values on ThingSpeak and potentially perform further analysis. The gas and light sensors are connected to an Arduino Uno, which reads the sensor values at intervals and sends the data to ThingSpeak cloud using WiFi. The measured values can be viewed live on ThingSpeak and downloaded as CSV files for future processing.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Experiment No:9

Experiment to a)detect the contents of gas using gas sensor and b) detect the light using light
sensor, IoT and cloud paradigm.

Requirements:

IOT Evaluation board

Gas and light sensor

Thingspeak cloud paradigm

Arduino Uno and its accessories

Wi-Fi hotspot with device name and password

Theory: The gas contents detected by gas sensors and light detected by light sensors can be further
processed for the required computation or analysis using IoT. The objective of this experiment is to
connect a) Gas and b) light sensor to the Arduino Uno embedded microcomputer and configure the
Arduino Uno to read the values of the at the desired interval of time and display the same in the serial
monitor window. The measured values can be used for future processing or analysis using a suitable
cloud computing paradigm. In this procedure Thingspeak cloud is used for the storage of the values
measured by the gas and light sensor in real time and the stored data can be operated upon as per
the requirement. A MATLAB program can be used to transform the stored values and editing for future
use. The graphical representation of the measured values can also be seen in the real time in the cloud
paradigm. This is useful in the real time analysis of the data using the techniques like machine learning
and Artificial Intelligence.

About ThingSpeak Cloud: (Not to write in journal)

ThingSpeak is a cloud platform providing various services exclusively targeted for building IoT
applications. It offers the capabilities of real-time data collection, visualizing the collected data in the
form of charts, ability to create plugins and apps for collaborating with web services, social network
and other APIs.

Features:The core element of Thingspeak is a ‘Thingspeak Channel’. A channel stores the data that we
send to Thingspeak and comprises of the below elements: 1.8 fields for storing data of any type –
These can be used to store the data from a sensor or from an embedded device. 2. 3 location fields –
Can be used to store the latitude, longitude and the elevation. These are very useful for tracking a
moving device. 3.1 status field – A short message to describe the data stored in the channel. To use
Thingspeak, we need to sign up and create a channel. Once we have a channel, we can send the data,
allow Thingspeak to process it and also retrieve the same. Let us start exploring Thingspeak by signing
up and setting up a channel. Usinghttps://thingspeak.com/the link user can connect to the Thingspeak
Cloud.(Create your own account in Thingspeak)

Connection diagram of light sensor:


Connection diagram of gas sensor:

Block diagram

Procedure:

1) For observing the values of gas and light at various measured instances on serial monitor
• The Arduino Uno IDE (Integrated Development Environment is installed in the PC
• The connections are established form gas and light to Arduino Uno board respectively
• The different connections between the board , power supply and computer are established
using the respective cables and connectors.
• The program is written for the intended purpose of recording the gas and light at various
time intervals.
• The program is run, and serial monitor is observed for real time display of the output data.

2)For observing the values of gas and light at various measured instances on cloud (Assignment)
(Not to write in journal)

• The same procedure is followed by writing the program for the cloud configuration and
sending the measured data to the cloud
• The ThingSpeak window is opened and in the “field data” tab the real time output data can
be seen.
• The csv files of the real time data can also be downloaded from the Thingspeak if required.
• Using the available API reference in the ThingSpeak , the interaction with the external world
is possible
Recordings:
1.The values of the output data displayed in the serial monitor of Arduino Uno

Program to display measured gas and light values on the serial monitor

a)Detection of Gas contents:

//Define pin

// RM5 - RM22 connected

int gas_pin = 0; // Arduino pin #8/A0 or Board pin P11

void setup() {

pinMode(gas_pin, INPUT);

Serial.begin(9600);

void loop() {

int gas_value = analogRead(gas_pin);

Serial.print("Gas Value : ");

Serial.println(gas_value);

// Checks if it has reached the threshold value

delay(1000);

b) For light detection:

// Example testing sketch for Digital light sensor

//Connect RM3 to RM20

int light_pin = 5; //Arduino board pin #19 / D5

void setup() {

pinMode(light_pin, INPUT);

Serial.begin(9600);

void loop() {

int light_data = digitalRead(light_pin);

if(light_data)
Serial.println("Light Not Detected!");

else

Serial.println("Light Detected!");

Serial.println(light_data);

delay(1000);

2. Program to display measured gas and lightvalues on the serial monitor and
cloud(Assignment) (Not to write in journal)

#include <SoftwareSerial.h>
#include <LiquidCrystal.h>
#include<SerialESP8266wifi.h>
#include<ThingSpeak.h>
#include<DHT.h>
#include<ArduinoJson.h>
#include <Wire.h>
String rawData;
#define RX 2
#define TX 3
const int rs = 16, en = 17, d4 =13, d5 = 12, d6 = 11, d7 = 10;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
#define DHTTYPE DHT11
#define dht_pin 4
#define light_pin 5
#define gas_pin A0
int light = 1;
int gas_value = 0;
String AP = ""; // CHANGE ME
String PASS = ""; // CHANGE ME
String API = ""; // CHANGE ME
String HOST = "api.thingspeak.com";
String PORT = "80";
int countTrueCommand;
int countTimeCommand;
boolean found = false;
SoftwareSerial esp8266(RX,TX);
StaticJsonBuffer<200> jsonBuffer;
DHT dht(dht_pin,DHTTYPE);
void setup()
{
Serial.begin(115200);
esp8266.begin(115200);
sendCommand("AT",5,"OK");
sendCommand("AT+IPR = 9600",5,"OK");
sendCommand("AT+UART_DEF=9600,8,1,0,0",5,"OK");
Serial.begin(9600);
esp8266.begin(9600);
dht.begin();
pinMode(light_pin,INPUT);
pinMode(gas_pin,INPUT);
//sendCommand("AT",5,"OK");
//sendCommand("AT+IPR = 9600",5,"OK");
//sendCommand("AT+UART_DEF=9600,8,1,0,0",5,"OK");
sendCommand("AT",5,"OK");
sendCommand("AT+CWMODE=1",5,"OK");
sendCommand("AT+CWJAP=\""+ AP +"\",\""+ PASS +"\"",20,"OK");
}
void loop() {
light = digitalRead(light_pin);
Serial.print("Light : ");
Serial.println(light);
gas_value = analogRead(gas_pin);
Serial.print("Gas Value : ");
Serial.println(gas_value);
lcd.print(gas_value);
String getData = "GET /update?api_key="+ API +"&field3="+light+"&field5="+gas_value;
//String getData = "GET
/channels/1716906/fields/1/last.json?api_key=ZZJESL7WIRVT3A8X";
sendCommand("AT+CIPMUX=1",5,"OK");
delay(1000);
sendCommand("AT+CIPSTART=0,\"TCP\",\""+ HOST +"\","+ PORT,15,"OK");
delay(1000);
sendCommand("AT+CIPSEND=0," +String(getData.length()+4),4,">");
delay(1000);
esp8266.println(getData);
delay(1500);
// if(esp8266.available()>0)
// {
// Serial.println("OKKKKK");
// rawData = esp8266.readString();
// delay(2000);
// Serial.println(rawData);
// delay(1000);
// }
countTrueCommand++;
sendCommand("AT+CIPCLOSE=0",5,"OK");
Serial.println();
Serial.println("Data sent to cloud Success");
lcd.clear();

}
void sendCommand(String command, int maxTime, char readReplay[]) {
Serial.print(countTrueCommand);
Serial.print(". at command => ");
Serial.print(command);
Serial.print(" ");
while(countTimeCommand < (maxTime*1))
{
esp8266.println(command);//at+cipsend
if(esp8266.find(readReplay))//ok
{
found = true;
break;
}

countTimeCommand++;
}

if(found == true)
{
Serial.println("OYI");
countTrueCommand++;
countTimeCommand = 0;
}

if(found == false)
{
Serial.println("Fail");
countTrueCommand = 0;
countTimeCommand = 0;
}

found = false;
}

You might also like