Build a smart smoke detector in 30 minutes with 12 euros budget

and lower the risk of fire in your house

Tonino (tonnoz)
Devjam
7 min readSep 26, 2020

--

Foreword : Lithium batteries and safety

leme flying an fpv drone in Italy

Folks who know me are aware I am a lot into drones. My house is basically swarming with them and along with drones come batteries: lithium-polymer batteries to be exact.

Lipo batteries and a fire extinguisher

These kinds of batteries can supply a great deal of power to my flying robot friends but they come with a great risk. Lithium-polymer batteries (LiPo for short) are in fact notoriously well known for creating nasty fires.

To avoid LiPo fires the most important thing to do is charge them safely, and discard them if they present any physical or electrical irregularity. Storing them correctly and keeping an eye on them when they are in storage is important too.

To lower these risks, I take several precautions:

  1. Buy two Bat-safe for charging and storing LiPos: Bat-safe is the best consumer solution to contain fire from LiPos. Check some example videos and happy stories.
  2. Buy a type-C fire extinguisher.
  3. Buy a smart smoke detector to get a real-time notification when smoke gets detected at home.

A quick Google search and I found out that the least expensive option for a smart smoke detector is the Xiaomi MiHome Honeywell (~32 euros at the time of writing) but this is not optimal since it requires an external gateway to function properly. Nest Protect is another premium possibility; it is though, very expensive and cumbersome to install. The last option was to build one myself, and that’s exactly what I did.

Components list

NodeMcu v2 (ES8266 chipset) board
Gas/Smoke sensor mq-135
Jumper wires Female-Female 20cm
  • Universal microUSB charger (e.g. phone charger) as long as it supplies 5v
  • (optional) plastic case / 3d printed case for enclosing

Wiring (2 minutes)

NodeMCU and smoke sensor wiring diagram

The wiring is pretty straightforward: the smoke sensor needs 5v to work properly and that can be derived from the the Vin pin since we will power-up the board with a phone charger (5v). For ground (GND) I chose the one right by Vin pin and finally I wired the A0 pin on the NodeMcu to the A0 pin on the smoke sensor to get the analog data reading from it. I used a big power bank to power-up the board at first (for testing) but then I switched to a regular phone charger. Voilà the wiring is done.

The smoke detector has a handy regulator on the back (the blue box on the right in the picture below) to set the sensitivity of the trigger for the digital port, but since we are relying on the raw analog data/pin output we are not going to use it.

Setup (~20 min)

For this project I chose to use Blynk: an hardware-agnostic IoT cloud platform and Android application to build IoT apps which is extremely powerful and intuitive to use.

The systems involved with our smoke detector are therefore the following :

  • NodeMcu board+sensor (local)
  • a smartphone with the Blynk app
  • the Blynk platform (cloud)
Systems involved

Setting up Arduino (local)

The cool thing about our NodeMcu board is that it has an ESP8266 chip and therefore is fully compatible with Arduino which is very good news!

To download Arduino IDE just go here https://www.arduino.cc/en/Main/Software

and select the right operating system for you. Once you have installed Arduino and all the drivers for your machine we can move to add the definition for the ESP8266 boards. Go to File->Preferences and under “Additional Board Manager URLs” add the following:

https://arduino.esp8266.com/stable/package_esp8266com_index.json

Board manager for node mcu

Now, let’s set up our Arduino to speak “ESP8266-ese” : Tools -> Board -> ESP8266 Boards -> NodeMCU 1.0

Select the right Arduino board
Select the right board

We need to add a few libraries for our Sketch to work properly: from the menu, select Sketch -> Include library -> add .ZIP library:

and add these three files:

https://github.com/tonnoz/iot-smoke-detector/raw/master/Blynk.zip

https://github.com/tonnoz/iot-smoke-detector/raw/master/BlynkESP8266_Lib.zip

https://github.com/tonnoz/iot-smoke-detector/raw/master/SimpleTimer.zip

Your Arduino setup is ready!

Setting up the Blynk platform (cloud/smartphone)

First let’s download the Blynk app from the store and register.

Then we’ll create a new project and select ESP8266 as device:

You will then see a message saying that an auth token was sent to your email address.

We will need this auth token very soon.

Creating the Blynk application

Now, let’s create our Blynk application: tap anywhere on the screen to add a widget:

Select the Notification, Email, Gauge, and most importantly the Eventor widget. For more info about these widgets and the concept of energy see the documentation.

Set up each one of them as shown in the screenshots below:

Gauge settings
Notification settings
email settings, put your own email address here
Eventor settings

NOTE: the values on the Eventor widget will probably be different for you. Find what works best for your sensor; for me, a value between 200 and 350 worked out, as you can see.

Done! Your mobile/cloud app is now complete, we are finally ready to write some code in Arduino:

Arduino coding (~10 min)

The code is pretty simple, let’s read it:

After setting up some constants and variables, we login to the Blynk platform with our auth token. We instruct a timer to repeat calling the procedure readAndSend() that will be called at every INTERVAL milliseconds (1000 in this case). The function is responsible for sending the smoke detector data, read from the NodeMcu to the Blynk platform using the WIFI internet connection.

Lines 43 to 45 define the condition to trigger a notification locally on the Arduino itself. They are optional and can be deleted if you want:

The reason for this is simple: it’s better to write this logic on the Blynk app than on Arduino since there is more flexibility. I left it in the code, so you know it’s a possibility.

Now copy the auth token in the received mail from Blynk and paste it into the field below where it says “YOUR_BLYNK_TOKEN” and then substitute “YOUR_HOME_WIFI_SSID” with your WIFI SSID and “YOUR_PASSWORD” with your WIFI password.

That’s it; everything’s ready, time to get some fire going 🔥!

Testing (~8min)

I suggest using candles to test the system since they are easy to light and snuff out and they make enough smoke to trigger a good reaction from the sensor. The right trigger level for me was around 250 to 300 but please test this on your own since every board/sensor may differ.

testing
Testing smoke detector with candle’s smoke
Eureka!
Email notifications are working too

Conclusions

final application

This project was a lot of fun and incredibly quick to complete. As you can see from the title of the article I spent just ~30 minutes from wiring to the first test and saved at least 25 euros by buying the least expensive commercial option available. Will it save my house from burning down? Hopefully I will never find out…

You can find the repository with the code shown in this article here:

Disclaimer:

This is just a research project. I do not take responsibility for damage caused to properties or people/animals in an event of fire. By re-creating this project you are fully responsible of your actions. Many insurance companies require fire detection systems to be compliant with adequate standards to be eligible for refunds. Do not re-create this project if you are not aware of the risks involved.

None of the links in this article are sponsored.

--

--

Tonino (tonnoz)
Devjam

👨‍💻 software engineer 🚀 drone fpv pilot