Escolar Documentos
Profissional Documentos
Cultura Documentos
Setup
Parts:
Stack the LCD Shield & Sensor Shield on the top of Arduino GPRS Shield as per the pin
markings on the top of the shield (make sure all connections are intact).
Light Sensor
1. The terminal S of the sensor is connected to A1 terminal of Arduino*
Buzzer
MQ 8 GAS Sensor
The RGB LED Strip is Triggered via a pulse applied from A5 teminal of Arduino (incase if any
Toxic Gas is sensed) to the base pin of TIP 120 Transistor (present onboard)
The Connections are as shown in the diagram:
VIN Terminal of Arduino (Wired
via sensor Shield)
GND1
3 After making the connections as shown in this
12 diagram, connect the wires (labeled-VCC,GND)
11 from the LCD Shield to respective pins of
10 LCD Shield
9 Sensor Shield.( VCC,GND- marked on
GPRS 8 Pins
SENSOR shield)
Shield
PINs 7
6 6
5 5
4 4
3 3
2 2
1 1
After Switching the system on the LCD should display Air Quality and then after few seconds
it should display sensor names and its values. Periodiclly it should display Uploading to
signify that data is being uploaded to Xively.com through the cellphone network.
Output:
GPRS shield is powering on, but data is not getting uploaded to the
website.or The LCD shield constantly displays Uploading
This is possibly due to the fact that the Cell Phone Data Plan has expired its MB limit. One
quick way to check this is to Recharge the SIM card data plan and Try again.
This problem also occurs when the signal strength is too low.
Make sure the API key for feed upload is correct by cross checking with the xively site
for our Air Quality Measurements Channel .The default program attached has the right
API Key in it (See the comments of the code). In future if any changes made in the
channel in the xively site, it will bring changes to the API key and the key has to updated
in the program.
This might be due to the fact that the SMS limit is exceeded or the Programmed Mobile
Number is wrong. Double check the mobile number (see comments in the code) also make
sure country code is entered. International SMS transfer will again depend upon the
mobile plan adopted.
an open connection in the Pcb wiring connections to the sensor. Check for continuity in
the Wiring (power and signal (data) terminals) to the particular sensor using a
multimeter.
Check the pins DATA, VCC , GND lines interfaced to Arduino board. A loose
connection n any of the three might be a possible reason for null data.
If sensor data is not getting updated- Switch off and Switch on the system.
Press Reset Button on Arduino and check for Ouput Air Quality If not,
Make sure LCD Shield is inserted in a proper way as shown in the previous sections
This problem is rare to occur but if it occurs, this might be due to excessive air blown on
the gas sensor (like winds or if it too close to the fan etc).
Below show is a snippet of the code prepared for data dashboard. For future work, change the
feed ID and the datastream Id (channel name: like Humidity or Temperature as shown in Xively)
in the respective places marked with circles as shown
Xively Feeds URL
Feed URL
http://api.xively.com/v2/feeds/779412251/datastreams/ Humidity.json?
&key=GtGuoMKJSqv2tzqGvWaITLhlEDUxrYXSixqPSmlyj-
s&datastreams= Humidity&duration=14days&interval=10800
For Future, in the above URL link change the Feed ID, datastream or channel name as
per the requirements or changes made if any.The above URL will yield the data of the particular
channel in JSON format which is used by google visualization tool for Graphical Info rendering.
If the data doesnt load after opening the website hit refresh twice to see the output.
Appendix
/* Air Quality Measurements Project
LiquidCrystal lcd(1,2,3,4,5,6);
SoftwareSerial mySerial(7, 8);
DHT dht(16, DHT11);
float alert_level,h,t,l,g;
unsigned long lastConnectionTime = 0;
int flag;
int count;
float senval[4];
char* channel[]={"Gas_Level", "Light", "Temp(Celcius)","Humidity" };
int ch;
void setup()
{
lcd.clear();
lcd.begin(16, 2);
lcd.print("Air Quality");
delay(800);
count=0;ch=0;
void loop() {
// Read Sensor Values
h = dht.readHumidity();
t = dht.readTemperature();
l = analogRead(1);
l = l/400*100; //Light Percent
g = analogRead(0);
g = g/1024*100; //Gas Percent
lcd.clear();
lcd.setCursor(0,2);
lcd.print(channel[ch]);
lcd.print(" ");
lcd.print(senval[ch]);
lcd.print("%");
ch=ch+1;
ch=ch%4;
senval[0]=g;
senval[1]=l;
senval[2]=t;
senval[3]=h;
delay(1000);
check_toxicity();
if (flag==1)
{
alert_sms();
}
else
{
flag=0;
}
if(millis() - lastConnectionTime > 30000)
{
lcd.clear();
lcd.print("Uploading");
update_cloud(); //upload data to xively
lastConnectionTime=millis();
}
if (mySerial.available())
{
//Serial.write(mySerial.read());
}
else{
lcd.clear();
lcd.print("NO GPRS SHIELD");
}
}
void alert_sms()
{
if (flag ==1)
{
mySerial.print("AT+CMGF=1\r"); //Because we want to send the SMS in text mode
delay(100);
mySerial.println("AT + CMGS = \"+19176993991\"");//send sms message, be careful
need to add a country code before the cellphone number
delay(100);
mySerial.println("Toxic Gas Level!");//the content of the message
delay(100);
mySerial.println(g);//the content of the message
delay(100);
mySerial.println("%(Message from GSM Modem JONNY)");//the content of the
message
delay(100);
mySerial.println((char)26);//the ASCII code of the ctrl+z is 26
delay(100);
mySerial.println();
}
else
{}
}
void check_toxicity()
{
noTone(17);
while (analogRead(0) > alert_level && count<5)
{
flag=1;
lcd.clear();
lcd.print("Toxic Gas Alert!!");
pinMode(19,OUTPUT);
digitalWrite(19,HIGH);
for(int i=500;i<1500;i++)
{
tone(17,i);
delay(2);
}
for(int i=1500;i>500;i--)
{
tone(17,i);
delay(2);
}
noTone(17);
count=count+1;
}
digitalWrite(19,LOW);
count=0;
}
void update_cloud()
{
String humidity = "1031";//these 4 line code are imitate the real sensor data, because
the demo did't add other sensor, so using 4 string variable to replace.
String moisture = "1242";//you can replace these four variable to the real sensor data
in your project
String temperature = "30";//
String barometer = "60.56";//
//Serial.print("Sorry");
mySerial.println("AT+CGATT?");
delay(1000);
PrintResponse();
PrintResponse();
PrintResponse();
PrintResponse();
mySerial.println("AT+CIPSPRT=0");
delay(3000);
PrintResponse();
mySerial.println("AT+CIPSTART=\"tcp\",\"api.xively.com\",\"8081\"");//start up the
connection
delay(2000);
PrintResponse();
PrintResponse();
mySerial.print("\"},\"body\":");
delay(500);
PrintResponse();
mySerial.print(" {\"version\": \"1.0.0\",\"datastreams\": ");
delay(500);
PrintResponse();
/* mySerial.println("[{\"id\": \"01\",\"value\": \"" + barometer + "\"},");
delay(500);
PrintResponse();
mySerial.println("{\"id\": \"02\",\"current_value\": \"" + humidity + "\"},");
delay(500);
PrintResponse();
mySerial.println("{\"id\": \"03\",\"current_value\": \"" + moisture + "\"},");
delay(500);
PrintResponse();
mySerial.println("{\"id\": \"04\",\"current_value\": \"" + temperature + "\"}]}}");
*/
//
mySerial.print("[{\"id\": \"Humidity\",\"current_value\": \"");
mySerial.print(h);
mySerial.print("\"},");
mySerial.println("");
delay(500);
PrintResponse();
mySerial.print("{\"id\": \"Temperature\",\"current_value\": \"");
mySerial.print(t);
mySerial.print("\"},");
mySerial.println("");
delay(500);
PrintResponse();
mySerial.print("{\"id\": \"Light_Level\",\"current_value\": \"");
mySerial.print(l);
mySerial.print("\"},");
mySerial.println("");
delay(500);
PrintResponse();
mySerial.print("{\"id\": \"Toxic_Gas_Level\",\"current_value\": \"");
mySerial.print(g);
mySerial.print("\"}]}}");
mySerial.println("");
delay(500);
PrintResponse();
mySerial.println((char)26);//sending
delay(5000);//waitting for reply, important! the time is base on the condition of internet
mySerial.println();
PrintResponse();
delay(3000);
mySerial.println("AT+CIPCLOSE");//close the connection
delay(100);
PrintResponse();
}
void PrintResponse()
{
while(mySerial.available()!=0)
{}
}