Friday, November 11, 2011

PICAXE / MQ2 Gas Sensor Project in a Mouse

The project detects flammable gases (LPG, butane, propane, methane, methane, methane, methane, methane, alcohol, hydrogen, and methane.) via the MQ2 Gas Sensor. When a flammable gas is detected the frequency of the speaker beep increases. The whole enchilada is controlled by a PICAXE 08M uController and some custom code.
---
Here is a video of the system operating. Keep reading if you want the details.
---
The rig gets its power from a 5VDC USB port (Windows and Mac compatible ;) or a car USB charger). The MQ2 Gas Sensor is protected by a metal screen which can be seen in this photo of the finished product.

---
Here is a shot of the circuit board powered up. In the final version we had to cut off the excess PCB material to make all the gear fit into the mouse. Note the "headphone input jack" near the top. That is actually a programming port allowing us to easily reprogram the PICAXE if we want to change the rigs personality. Such as, make the speaker beep faster, louder, flash lights, etc. Also, you can see that the PICAXE is not plugged into the socket yet. We wanted to check for solder shorts and smoke first to avoid damage to the PICAXE.
---
Is all this stuff going to fit into the gutted mouse?
---
Of course, if you watched the video above, you know it all fit (just barely). The build schematic:
---
Here is a video of the rig working on the bench.  The current thinking at this time was to use a servo motor to move a needle over a calibrated meter.  In the final design the beeping speaker was used to reduce the size.
---
The source code for the PICAXE 08M is straightforward:
;
#picaxe08m
#com 11

main:
readadc C.2,b0 ; read the MQ2
sound B.1,(119,5) ; make a sound
w1 = 255 - b0
w1 = w1 * 5
pause w1 ; decrease pause between beeps if gas detected
goto main ; loop back to start
-----