Following on from my last post about my DIY Intruder Alarm, I thought I’d post about another wee device I’ve hooked up to it, a Smoke/Combustible Gas/Carbon Monoxide detector that’s WiFi capable, for about $5.
It’s based on the WeMos D1 Mini, which can be got on AliExpress.com for about $3, and a Smoke/Gas detector that can also be got on AliExpress for about $2. For the software, I use a patched version of the excellent Sonoff software by Theo Arends. More on that later.
So here are the parts. The Wemos D1 Mini, the Gas detector, and a small DIY jumper cable to connect the Analog output of the sensor to the Analog Input on the D1 Mini. The other three pins can be plugged directly into the D1Min, as Vcc, GND and Digital output are in the correct order and orientation to make this possible.
Here’s a pic of the pins used on the Wemos D1 Mini:
I bent the pins on the Smoke/Gas detector as follows:
And apply the jumper wire for the Analog input:
And mounted it on the WeMos D1 Mini:
And that’s it. About 5 minutes with a crimp tool and soldering iron, and you’re done with the hardware. If you have a male-female jumper wire already, you won’t even need the crimp tool or soldering iron!
Next, to the software. I’ve taken a snapshot of Theo Arends excellent Sonoff software, and patched it to read the Analog Input, and send out an MQTT message with the other telemetry. Also, I’ve added a configurable threshold that will send an MQTT message when the threshold is exceeded. This allows you to configure the sensitivity of your sensor, and tweak it to suit the sensor you’re using. I find that an MQ-2 is good for smoke, but not so good for combustible gas, wheras an MQ9 is much better for combustible gas.
Here’s the Sonoff user interface with my “Analog Input” modification:
The user interface is standard on the Sonoff software, I just tweaked it to show the level of the Analog Input coming from the Gas sensor.
The interesting part of the code is in the config section:
/*-------------------------------------------------------------------------------------------*\ * ANALOG INPUT DATA \*-------------------------------------------------------------------------------------------*/ #define ANALOG_PIN A0 #define ANALOG_TRIGGER 400 #define SEND_ANALOG_ALARM #define SEND_TELEMETRY_ANALOG
This allows the user to set the threshold of the level at which the MQTT message for the alarm gets sent out to the MQTT broker elsewhere on the network. 300-500 seems like a reasonable level for my sensor, when I release some gas from a practically empty cigarette lighter near an MQ-9, the reading goes straight up to about 600, and I can’t smell much gas at that.
I’ve also configured all the MQTT telemetry (and alarm messages) to go to an MQTT broker on my local network, which I monitor with Node-Red.
So, looking at the Node red side of things (I’m a big fan of Node-Red), I’ve created an input MQTT node, and set the topic for my detector, which in this case is tele/sonoff/ANALOG_ALARM (“sonoff” is the default name for the device, I usually change this to “office” or “kitchen” or something identifiable). When this is running, I don’t see any messages come in to the MQTT node until I release some gas near the MQ-9 sensor, at which stage I then see the MQTT message come in.
Elsewhere in the Node-Red setup I have the ability to send all sorts of notifications – e-mail, SMS, etc. So next step is to hook it into that so I’ll get a notification when the sensors smell something they shouldn’t.
Of course, this gas alarm is only as a backup to the several other commercial smoke/gas sensors around the premises. I wouldn’t be fully comfortable depending on something DIY for something as critical as Smoke or Gas detection. This detector is purely for educational purposes.
And if you’re interested, here’s the patch for the Sonoff software, it should apply cleanly to git commit id f873a355af81f695c57cd7f348609de64d6b4e71 in the https://github.com/arendst/Sonoff-MQTT-OTA-Arduino repository.
All I need now is a nice 3D printed enclosure! 🙂
Hello Daveh,
Do you know any international website that I can buy this product and receive in Brazil?
Congratulations on blog work, I and my collaborators are very fond of your content!