Recently I have been learning Python implementations on Raspberry Pi's GPIO system. I'm interested in wireless sensor network examples and decided to make a fire alarm system using MQ-2 sensor as the gas detector and Raspberry Pi as the main server (i think). My first lead to build this project was this link.
http://www.learningaboutelectronics.com/Articles/MQ-2-smoke-sensor-circuit-with-raspberry-pi.php
After I bought everything I need to build the circuit according to the tutorial, the program won't run itself. To make the sensor works, I finally realized that I had to install wiringPi and Spidev, which was actually not mentioned in the tutorial. In order to fully run the smoke sensing program, the user must implement the botbook_mcp3002 library that I found on internet, which was also not provided in the tutorial. I'm assumming that the writer of this short tutorial made it unwillingly and was being lazy too.
My realization of spidev on mcp3002 was helped by this second link -> http://raspberry.io/projects/view/reading-from-a-mcp3002-analog-to-digital-converter/ . It helped me a lot to try the mcp3002 ADC and explain everything clearly. The circuit diagram on the first link didn't work so now I'm using the mcp3002 picture on the second link. I replaced the trim potentiometer with the MQ-2 sensor (removed the resistor too). By joining the two tutorials, I was able to build the first phase of my desired fire alarm system and later develope it into a mobile app. Here is the simple code from the tutorial.
import time
import botbook_mcp3002 as mcp
smokeLevel= 0
def readSmokeLevel():
global smokeLevel
smokeLevel= mcp.readAnalog()
def main():
while True:
readSmokeLevel()
print ("Current smoke level is %i " % smokeLevel) #
if smokeLevel > 120:
print("Smoke detected")
time.sleep(0.5)
if__name__=="__main__":
main()
Some people said that sensors work better with arduino devices, since it is made to work in real-time with the needed voltage current for the sensor. But here I want to prove that Raspbery Pi can work with sensors too. That's why the MCP3002 analog-to-digital converter is necessary for this project. My problem now is the output value of smoke sensing system with Raspberry Pi based on the code above only represents one single value. It doesn't distinguish between smoke level, LPG level, and other flammable gases. Some youtube videos show me that arduino can actually show different values at the same time. So what should I add or do to the python code above in order to distinguish the values in Raspberry Pi? Any suggestion or ideas will be appreciated.