Temperature and Smoke Detector
Warning: This project uses Sparrow, a Blues product that is no longer under active development. We are working on updating this project to the successors of Sparrow: Notecard LoRa and the LoRaWAN Starter Kit. In the meantime, if you would like assistance building a Temperature and Smoke Detector feel free to reach out on our community forum.
Temperature monitoring and smoke detection across a number of rooms at a facility.
You Will Need
- Sparrow Development Kit
- MQ2 Gas and Smoke Sensor
- 3.3-to-5v voltage converter
- Soldering Iron
- 2 USB A to micro USB cables
- 3 male-to-female jumper wires
Notehub Setup
Sign up for a free account on notehub.io and create a new project.
Sparrow Setup
Quickstart
Follow the Sparrow Quickstart pair your Sparrow reference node with the gateway and associate it with the Notehub project you just created. Note also that you only need one reference node for this project (although multiple reference nodes can be used to monitor multiple rooms). Make sure that you use the ProductUID generated in Notehub Setup when it comes time to issue the hub.set
command in the quickstart.
After you've completed the quickstart, leave the Notecarrier and Sparrow Essentials board powered and connected. These two devices will act as our gateway to Notehub, and you won't need to touch them again. The rest of this guide will focus on the Sparrow Reference Sensor node.
MQ2 Sensor Connection
This solution makes use of the an MQ2 sensor module, which detects smoke, as well as various gasses. Using the 3 male-to-female jumper wires, connect the MQ2 sensor to the Sparrow Reference Sensor board and the v5 converter as follows:
- Splice a male to female jumper in half and solder the exposed wires to the
GND
pad on the 5v converter. Connect the female end toGND
on the sensor and the male end to theGND
pin on Sparrow. - Splice another jumper, and solder the exposed wire on male half to
Vi
on the converter. Connect the male connector toVBAT
on Sparrow. Solder the exposed wire on the female half toVo
and connect the female end to theA0
pin on the MQ2 sensor. - Using an intact male-to-female jumper, connect
A0
on the sensor to theA1
pin on Sparrow. - The 4th pin on the sensor is left unconnected.
Firmware
This section shows how you build the Temperature and Smoke Detector firmware and flash it to the reference node.
-
You will need to fetch the dependencies required by the firmware. After cloning this repository, run these commands:
git submodule update --init 31-temperature-and-smoke-detector/firmware/note-c
andgit submodule update --init 31-temperature-and-smoke-detector/firmware/sparrow-lora
. This will fetch thenote-c
andsparrow-lora
submodules that this project depends on. -
Connect the STLINK-V3MINI to your development PC with a USB A to micro USB cable.
-
Connect the STLINK to your reference node with the 2x7 JTAG ribbon cable.
-
There are a few ways to build and flash the firmware onto the reference node. These are covered in the Sparrow Builder's Guide. Follow the steps in that guide and then return to these instructions.
Note: When building the firmware with VSCode, be sure the
firmware
folder is added at the root of the workspace. This ensures the project's tasks to compile the firmware are recognized by VSCode.
-
Build and flash the firmware using whichever method you chose when following the Sparrow Builder's Guide.
-
Open a terminal emulator and connect to the STLINK's serial connection to view the logs from the device. See the documentation here.
-
Start the program in debug mode (again, how you do this depends on the IDE: VS Code or STM32CubeIDE). In your terminal emulator, you should see something like this:
===================
===================
===== SPARROW =====
===================
Feb 16 2023 22:42:58
2037335832365003001d001f
APPLICATION HOST MODE
CONSOLE TRACE ENABLED
You will see a message like this after a few minutes:
mq2: note sent. gas: 4226, temperature: 20.2C, humidity: 35.26%
Temperature Monitoring and Smoke Alerting Behavior
The firmware periodically monitors temperature and gas concentrations, and posts events with this information. Regular monitoring events are not synced immediately to Notehub, and will be delivered as often as the Notecard is configured to sync with Notehub via the hub.set
request.
Temperature and Gas measurements are posted to the Notefile *#mq2.qo
, where *
is replaced with the unique ID of the Sparrow node. An event has these properties:
{
"app" : "nf31", // the application name
"temperature" : 20.6, // ambient temperature (in °C)
"humidity" : 41.2, // ambient humidity (in percent)
"voltage" : 4.7 // battery voltage (in V)
}
Each reading taken is checked against the configured thresholds. If any reading is higher than the corresponding threshold, the event is sent immediately to Notehub as an alert. Alerts are distinguished from regular monitoring events by the alert
property.
{
"alert" : 1, // Signifies an alert
"app" : "nf31", // the application name
"temperature" : 40.3, // ambient temperature (in °C)
"humidity" : 25.2, // ambient humidity (in percent)
"voltage" : 4.7 // battery voltage (in V)
}
The alert
property has these values:
-
alert:1
: Indicates an alert condition regarding temperature or presence of smoke or gas has been detected. The event is immediately synced to Notehub. You can use this to signal an alert externally, such as notifying a pager other messaging service. -
alert:2
: Signifies that the alert is still ongoing. Subsequent alerts after the initial alert have thealert
property set to2
, indicating that the alert is ongoing because temperature or gas levels haven't returned to normal. These events are not immediately sent to notehub, and are provided for continuous monitoring. -
alert:3
: Signifies a stand-down alert and that temperature and gas levels have returned to normal. These events are sent immediately to notehub. This is typically used to send an external notification that normal temperature and gas levels have been reached.
When temperature and gas levels return to normal, alert:3
is the last event sent with the alert
property present. Subsequent events do not have the alert
property present until a new alert condition is detected.
Configuration
The file ./firmware/sparrow-application/mq2/mq2.c
contains a number of #define
s that are used to configure how often temperature and gas levels are measured and the thresholds that trigger an alert:
Name | Default | Unit | Description |
---|---|---|---|
MQ2_MONITOR_PERIOD | 60 | seconds | The period in seconds between each sensor reading. |
ALERTS_ONLY | false | boolean | When true, disables reporting of regular monitoring events and only alerts are sent. |
ALERT_TEMPERATURE | 50.0 | C | Trigger an alert when the temperature is at least this high. Set to 0 to disable temperature alerts. |
ALERT_GAS_LEVEL | 40000 | 1-65535 | Trigger an alert when the measured gas level is at least this high. Set to 0 to disable gas level alerts. |
Calibrating the Gas Sensor
The MQ2 sensor indicates the the gas level detected by way of the the voltage produced on the A0 analog output - a higher voltage means more gas or smoke was detected. The absolute value of this voltage is not calibrated. Additionally, some sensors feature a potentiometer to adjust the sensitivity, which further changes the range of voltages the sensor outputs.
In order to determine the range of values you should test the solution in clean air, and, if possible, in a smokey environment in order to determine a suitable value for ALERT_GAS_LEVEL
.
Blues Community
We’d love to hear about you and your project on the Blues Community Forum!
Additional Resources
- Sparrow Datasheet
- Sparrow Hardware Behavior (e.g. what do the various Sparrow LEDs indicate?)
- MQ2 Datasheet