CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Has anyone used this MQ-2 Smoke/PG/CO/Gas Sensor

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
princejude



Joined: 07 Aug 2010
Posts: 72

View user's profile Send private message

Has anyone used this MQ-2 Smoke/PG/CO/Gas Sensor
PostPosted: Wed Oct 12, 2011 6:40 am     Reply with quote

Am trying to build a simple gas monitoring project that will detect gas leakage and display the name and concentration of the gas (in PPM) on 16x2 lcd and am using PIC16F887. If the concentration is too high it will sound an alarm.

The MQ-2 datasheet is here: http://www.pololu.com/file/download/MQ2.pdf?file_id=0J309

I googled for tutorial or sample codes and found this link: http://www.ebay.com/itm/MQ-2-Smoke-LPG-CO-Gas-Sensor-Module-Arduino-MCUs-/120723626960

The sample code was written in Arduino. I was trying to convert the code to CCS but the problem is that it has some float functions which generate some errors during compilation.

Please i will like someone to help me with simple ccs sample codes, tutorials or some advice on how to convert the Arduino to ccs.

I have all the components with me including the sensor.

Thanks in advance.
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Wed Oct 12, 2011 9:06 am     Reply with quote

if you show the CODE you are having trouble with - help might appear/
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Wed Oct 12, 2011 2:28 pm     Reply with quote

Quote:
display the name and concentration of the gas (in PPM)

You know, that this type of sensor won't be able to detect gases selectively? Except for not being
sensitive to regular air components and inert gases like carbon dioxide. In so far you have to know the
name of the gas before to display it on the LCD.
princejude



Joined: 07 Aug 2010
Posts: 72

View user's profile Send private message

PostPosted: Tue Oct 18, 2011 7:13 am     Reply with quote

Quote:
if you show the CODE you are having trouble with - help might appear/

asmboy, the arduino code i will like to convert to ccs is in the second link i posted first, shown below:
Code:
http://www.ebay.com/itm/MQ-2-Smoke-LPG-CO-Gas-Sensor-Module-Arduino-MCUs-/120723626960
.

Quote:
Quote:
display the name and concentration of the gas (in PPM)

You know, that this type of sensor won't be able to detect gases selectively?


FvM which type do you suggest that i will use?

I have started with simple test code to confirm if the sensor is working. The test code is just a simple ADC code that will get the analog input from the sensor, convert and display it on LCD and/or hyperterminal.

The code is here:
Code:

#include "16F887.h"
#fuses xt, nowdt, noput
#device ADC = 8
#use delay(clock = 4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

#include "flex_lcd.c"

void main()
{
   int8 gas;                         // Input variable
   setup_adc(ADC_CLOCK_DIV_8);    // ADC clock
   setup_adc_ports(sAN5);       
   set_adc_channel(5);          // Select AN5

   lcd_init();

   while (true)
   {
      delay_ms(10);
      gas = read_adc();       //Get input byte
      output_B(gas);
      lcd_gotoxy(1,1);
      printf(lcd_putc," Concentration: \n");   
      printf(lcd_putc,"   %u \n",gas);
      lcd_gotoxy(8,2);
      printf(lcd_putc," PPM");
      printf("Concentration = %u ",gas);
      printf("ppm\n\r");
      delay_ms(2000);
   }   
}


I have tested it with this code and the sensor is working because inside my room (without smoke) the LCD display a number from 63 to 75 and outside with smoke from motorcycle exhaust it was displaying up to 215.
That means the hardware is normal.

I asked a friend and he said that i must do the calibration in a LAB where I can produce a controlled level of gas concentration and then use a standard sensor to measure the concentration.

Pls i still need more info on the calibration OR if there is any other way i can do this without the calibration, I will be happy to follow the short cut.
temtronic



Joined: 01 Jul 2010
Posts: 9246
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Oct 18, 2011 7:29 am     Reply with quote

Well , you've already got a 'short cut' method. Test and record your 'clean air' value, then use the motorcycle exhaust as the 'bad air' concentration.
Unless you want 'lab grade' results, you should be fine with the 'short cut'.

If you need a sample of CO2, consider using the cartridges for a 'pellet pistol' or a 'wine bottle charger'.You'll have to rig up some kind of 'pierce and save' system, but it is a very cheap way to get 'small bottles' of CO2!.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Tue Oct 18, 2011 8:49 am     Reply with quote

Quote:
FvM which type do u suggest that i will use?

There are no cheap and simple sensors with selectivity and stable calibration. You get some electrochemical sensors with specific selectivity, e.g. for carbon monoxide. Catalytic sensors for flammable gases have an acceptable selectivity for all gases of this type.

Semiconductor (SnO2) sensors like the MQ2 are sensitive a broader slection of gases, stronger variation between different gases and less stable calibration. They are suitable for alarm devices but not with a guaranteed sensitivity.

Sensors, that can distinguish between different gases are clearly beyond the scope of a hobby project.

Quote:
If you need a sample of CO2, consider using the cartridges for a 'pellet pistol'

These sensor aren't sensitive to CO2.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group