LPG Gas tracker(MQ5) with GSM/GPS

Hello, i am currently creating a project that detects LPG gases using MQ5 gas sensor. I had no problems regarding this, but had some issues when trying to combine with the GSM/GPS. I am using a GPS/GPRS/GSM V3.0(DF robot) module. I think my problem is with the GPS/GSM codings. I am suppose to trace an LPG gas and once it is detected, an LED will blink, buzzer will produce sound and send a message to a safety centre(my number). Would love for you all to check it out.

My problem:

  1. Trying to convert multiple analog readings and converting it to one single digital output. This is what i did;
    val = analogRead(sensorValue);
    Serial.println(val);

if (val < 350)
{
digitalWrite(sensor1,LOW);
digitalWrite(LED,LOW);
digitalWrite(buzzer,LOW);
delay(500);
}
else
{
if (val >= 350)
{
digitalWrite(sensor1,HIGH); //is this the right way to convert analog readings to a one digital output?
digitalWrite(LED,HIGH);
digitalWrite(buzzer,HIGH);
delay(500);
digitalWrite(LED,LOW);
digitalWrite(buzzer,LOW);
delay(500);
}

2)I do not know how, but i am able to receive the message displayed but I am not able to obtain any lattitude,longitude output.You can see an example of my serial port for the output on the picture below.

3)Usually, when i apply LPG gas on the sensor, it will go as high as 1000+ and returns back to normal range(below 350), and i've noticed on the way down, the program still reads the output and responds, example, when it reaches 1000+ it will send out a message, once it is done, if it is still above(350) it will keep sending out message until it is below 350, how do i send the message just once?

4)Ive attached a buzzer(pin 9) and an LED(pin 11) just for the sake of an alarm, and ive noticed both of them does not go on a loop once the message starts to be sent, how i make it continuosly HIGH(when input is detected) and have the system send out a message also?

TQ,please have a look,i really need the help..

test.txt (12.1 KB)

gpsoutput.png

Edit_Code_GPS_SMS.ino (5.75 KB)

anyone? help pls

This is odd:

    sensor1 = digitalRead(val);

Val is the result of an analogread, so it can vary from 0 to 1023. You're using it to try to read a digital pin in that same range, most of which don't exist.

As to doing a single SMS, you need a boolean variable that indicates whether there is a gas problem to control whether the alarms are on. When you set it to true, send the SMS.

wildbill:
Val is the result of an analogread, so it can vary from 0 to 1023. You're using it to try to read a digital pin in that same range, most of which don't exist.

As to doing a single SMS, you need a boolean variable that indicates whether there is a gas problem to control whether the alarms are on. When you set it to true, send the SMS.

Thanks wildbill, but im still not sure how to convert the analog readings to just one digital output, i mean, when the range is more than 350, it is a digital output =1, how do i do that? can u teach me?

and as far as declaring a boolean variable, what exactly do u mean? im not so sure what u meant by that, sorry, im still new, need many help

This section:

    sensor1 = digitalRead(val);
    if (sensor1 == HIGH)
    {
      Serial.println("AT"); //Send AT command

Could be fixed in this fashion:

int    SensorReading = digitalRead(sensor1);
    if (SensorReading == HIGH)
    {
      Serial.println("AT"); //Send AT command

But there's really no need to check the state of the pin - you set it earlier. Better to move the SMS code inside the block of code where it was set high. Better yet to put it in its own function and call it from there. Note that the additional check for >=350 is irrelevant - given that you made it into the else section, you already now that val isn't less than 350.

As to the single SMS, declare a global boolean variable called SentSMS. In the section of code where you've detected a gas problem, check whether SentSMS is true. If it is, do nothing, otherwise send the message and set the variable to true. When no gas condition is detected, set the SentSMS variable to false.

thanks wildbill.. first of all, ive been away from arduino a while now, and im kinda lost right now, really need your help to clarify to me clearly..

wildbill:
This section:

int    SensorReading = digitalRead(sensor1);

if (SensorReading == HIGH)
    {
      Serial.println("AT"); //Send AT command



But there's really no need to check the state of the pin - you set it earlier. Better to move the SMS code inside the block of code where it was set high. Better yet to put it in its own function and call it from there. Note that the additional check for >=350 is irrelevant - given that you made it into the else section, you already now that val isn't less than 350.

for the first part, i need to show you my codings,

codings:
int sensorValue=A3;
int val=0;
int buzzer=9;
int LED=11;
int sensor1=0; //my global declaration

void loop()
{
val = analogRead(sensorValue);
Serial.println(val);

if (val < 350)
{
digitalWrite(sensor1,LOW);
digitalWrite(LED,LOW);
digitalWrite(buzzer,LOW);
delay(500);
}

else
{

digitalWrite(sensor1,HIGH);
digitalWrite(LED,HIGH);
digitalWrite(buzzer,HIGH);
delay(500);
digitalWrite(LED,LOW);
digitalWrite(buzzer,LOW);
delay(500);

sensor1 = digitalRead(val);
if (sensor1 == HIGH)
{
Serial.println("AT"); //Send AT command

so you're saying i should change my sensor 1 and declare an int SensorReading? and change my val to sensor1? i dont really see the difference there?

wildbill:
As to the single SMS, declare a global boolean variable called SentSMS. In the section of code where you've detected a gas problem, check whether SentSMS is true. If it is, do nothing, otherwise send the message and set the variable to true. When no gas condition is detected, set the SentSMS variable to false.

for this part, u mean , at the top of the codings, i declare for SentSMS? can u please show me what you mean, and what u mean by puting it in the code sections?

THANKS WILDBILL FOR YOUR TIME, PLEASE HELP ME!!

anyone?

Hello,
Can you please give us the link of the product page (Gas sensor) or a photo? I doubt that there are 2 seperate pins for digital (attached with a comparator) & analog outputs.
You have to choose from either one. I shall suggest you to take the analog output because the digital O/P needs calibration( with the onboard preset pot).

Im curreny using the analog gas sensor below, from Tutorials - Myduino, and i just want to know how to convert the multiple analog outputs to just 1 digital output,so i can use that output to trigger the alarm and send a message through gsm..but i am unable to do so,since it will take each analog output and convert it to each digital ouput..thats just too much sms to send for the same message..

nightcrawler218:
Hello,
Can you please give us the link of the product page (Gas sensor) or a photo? I doubt that there are 2 seperate pins for digital (attached with a comparator) & analog outputs.
You have to choose from either one. I shall suggest you to take the analog output because the digital O/P needs calibration( with the onboard preset pot).

image.jpg

Anyone out there who can help me out?

Hi,
After having a look at the product page it is clear that the device has only Analog O/p capabilities. Well, it's absolutely fine.
Now first start with the basic algo

void Loop ()
Read sensor value(Analog)
If the analog value is less than the threshold (in your case you put 350)
{
Do nothing; (generally the gas sensors o/p around 200-300 adc value in normal condition, & if LPG or smoke is detected the value rise up to >500)
}
else{
Lit the LED 13;
}

int sensorValue=A3;
int val=0;
int buzzer=9;
int LED=11;
int sensor1=0;       //my global declaration
void loop()
{
  val = analogRead(sensorValue);
  Serial.println(val);
      if (val < 350) // this part will be active if sensor senses nothing notable
    {
      //digitalWrite(sensor1,LOW);// Remove that line, 
      digitalWrite(LED,LOW);
      digitalWrite(buzzer,LOW);
      delay(500);
    }
    
    else   // in this case else represents a higher or notable o/p from the GAS sensor ( val >= 350 )
  {
  digitalWrite(LED,HIGH);
  digitalWrite(buzzer,HIGH);
  delay(500);
  digitalWrite(LED,LOW);
  digitalWrite(buzzer,LOW);
  delay(500);

Check this if it works.

nightcrawler218:
Hi,
After having a look at the product page it is clear that the device has only Analog O/p capabilities. Well, it's absolutely fine.
Now first start with the basic algo

int sensorValue=A3;

int val=0;
int buzzer=9;
int LED=11;
int sensor1=0;      //my global declaration
void loop()
{
  val = analogRead(sensorValue);
  Serial.println(val);
      if (val < 350) // this part will be active if sensor senses nothing notable
    {
      //digitalWrite(sensor1,LOW);// Remove that line,
      digitalWrite(LED,LOW);
      digitalWrite(buzzer,LOW);
      delay(500);
    }
   
    else  // in this case else represents a higher or notable o/p from the GAS sensor ( val >= 350 )
  {
  digitalWrite(LED,HIGH);
  digitalWrite(buzzer,HIGH);
  delay(500);
  digitalWrite(LED,LOW);
  digitalWrite(buzzer,LOW);
  delay(500);



Check this if it works.

Thanks nightcrawler,alright i get the codings that u've just wrote,but my main problem is,trying to get all those analog ouput for "else" and convert it to just ONE digital output, so that i can use that digital ouput(HIGH or 1) to send out a warning message to a phone,so i cant do that with analog ouputs,how do i make all the (>350) outputs to just one digital output and stop the loop? Pls tell me thank you

okk, I understand your problem. You can do this by hardware(using a comparator) or you can do this by software (adding a couple of lines in the code). Here it is---

void loop()
{
  val = analogRead(sensorValue);
  if (val<350) sensor1=0;  // All the o/P below 350 will be a LOW
  else sensor1=1; // If the o/p >= 350 it will be treated as HIGH
Serial.println(sensor1); // you may see if the value is either a 0 or a 1

      if (sensor1==0) // sensor1=0 stands for assigning the value to the variable & sensor==0 is for checking if the value of the variable is 0 or not
    {
      //digitalWrite(sensor1,LOW);// Remove that line, 
      digitalWrite(LED,LOW);
      digitalWrite(buzzer,LOW);
      delay(500);
    }
       else if (sensor1==1)   // and also it represents a higher or notable o/p from the GAS sensor ( val >= 350 )
  {
  digitalWrite(LED,HIGH);
  digitalWrite(buzzer,HIGH);
  delay(500);
  digitalWrite(LED,LOW);
  digitalWrite(buzzer,LOW);
  delay(500);

nightcrawler218:

void loop()

{
 val = analogRead(sensorValue);
 if (sensorValue<350) sensor1=0;  // All the o/P below 350 will be a LOW
 else sensor1=1; // If the o/p >= 350 it will be treated as HIGH
Serial.println(sensor1); // you may see if the value is either a 0 or a 1

if (sensor1==0) // sensor1=0 stands for assigning the value to the variable & sensor==0 is for checking if the value of the variable is 0 or not
   {
     //digitalWrite(sensor1,LOW);// Remove that line,
     digitalWrite(LED,LOW);
     digitalWrite(buzzer,LOW);
     delay(500);
   }
      else if (sensor1==1)   // and also it represents a higher or notable o/p from the GAS sensor ( val >= 350 )
 {
 digitalWrite(LED,HIGH);
 digitalWrite(buzzer,HIGH);
 delay(500);
 digitalWrite(LED,LOW);
 digitalWrite(buzzer,LOW);
 delay(500);

Hi nightcrawler, so i've edited my codings and make it more simpler for me to understand,and you can see it from the attachments below,but i still have the following problems, if you or anyone can help me out with;

  1. How do i make the LED & BUZZER to continuously be HIGH while sending only one MSG ( The buzzer and LED stops once the message is sent)
    2)I cant seem to obtain any longitude and latitude, it came out as "inf"

Please guys.need you guys to help me out and if u can, be more specific, cause im still learning..THANK YOU

Edit_Code_GPS_SMS.ino (5.78 KB)

GAS_GSM_GPS.txt (12.2 KB)

SerialOutput.png

what pins you have used in connecting the GSM modem with the Arduino?
You have to printed the code in arduino serial monitor pins. so, you have to connect the gsm modem with pins o&1

nightcrawler218:
what pins you have used in connecting the GSM modem with the Arduino?
You have to printed the code in arduino serial monitor pins. so, you have to connect the gsm modem with pins o&1

Well based on the data sheet,i used pins 3,4,5..i dont think its the pins..but i donno why im not getting any latitudes or longitudes output,by the way,do you know how i can do the first problem? The one i stated just now,thanks nightcrawler

i am still not able to solve the problem for latitude and longitude and their directions, it still came out as "inf", does it have something to do with the fact my GPS module is not able to retrieve the coordinates or is it the codings? please can someone clarify, would really appreciate it.

Write yourself a sketch that does nothing but echo the GPS data to serial so you can see what it's doing. Remember that GPS generally doesn't work well indoors although you may get a signal if it's near a window - outside is best.

aveaqim:

nightcrawler218:

Hey even I'm trying to build the same project! I downloaded the code text file but it was full of some chinese characters. It'll be great help if you could please upload the code in a Word file! Thanks!!

nightcrawler218:
okk, I understand your problem. You can do this by hardware(using a comparator) or you can do this by software (adding a couple of lines in the code). Here it is---

void loop()

{
  val = analogRead(sensorValue);
  if (sensorValue<350) sensor1=0;  // All the o/P below 350 will be a LOW
  else sensor1=1; // If the o/p >= 350 it will be treated as HIGH
Serial.println(sensor1); // you may see if the value is either a 0 or a 1

if (sensor1==0) // sensor1=0 stands for assigning the value to the variable & sensor==0 is for checking if the value of the variable is 0 or not
    {
      //digitalWrite(sensor1,LOW);// Remove that line,
      digitalWrite(LED,LOW);
      digitalWrite(buzzer,LOW);
      delay(500);
    }
       else if (sensor1==1)   // and also it represents a higher or notable o/p from the GAS sensor ( val >= 350 )
  {
  digitalWrite(LED,HIGH);
  digitalWrite(buzzer,HIGH);
  delay(500);
  digitalWrite(LED,LOW);
  digitalWrite(buzzer,LOW);
  delay(500);

somebody help please!