Browse our open source example apps to accelerate your wireless IoT project.

Blues Developers
What’s New
Resources
Blog
Technical articles for developers
Newsletter
The monthly Blues developer newsletter
Terminal
Connect to a Notecard in your browser
Developer Certification
Get certified on wireless connectivity with Blues
Webinars
Listing of Blues technical webinars
Blues.comNotehub.io
Shop
Docs
Button IconHelp
Notehub StatusVisit our Forum
Button IconSign In
Sign In
Sign In
What’s New
Resources
Blog
Technical articles for developers
Newsletter
The monthly Blues developer newsletter
Terminal
Connect to a Notecard in your browser
Developer Certification
Get certified on wireless connectivity with Blues
Webinars
Listing of Blues technical webinars
Blues.comNotehub.io
Shop
Docs
homechevron_rightExample Appschevron_rightAcceleratorschevron_rightIndoor Air Quality and Gas Leak Detector

Indoor Air Quality and Gas Leak Detector

  • Arduino Firmware
  • LoRa
  • Swan

Monitor air quality, including Air Quality Index, CO2 and VOC concentration, and send alerts when a potential gas leak is detected.

You Will Need

  • Notecard Lora
  • LoRaWAN Gateway
  • Notecarrier F
  • Swan
  • 2 USB A to micro USB cables
  • Sparkfun Indoor Air Quality Sensor - ENS160
  • Qwiic cable

Notehub Setup

Sign up for a free account on notehub.io and create a new project.

LoRa Gateway Setup

Before you can use the Notecard LoRa you need to have a LoRaWAN gateway that is provisioned to The Things Network. To make this easy you can use the Blues Indoor LoRaWAN Gateway . To get this set up follow the setup instructions

Swan Setup

First connect your Blues Swan and Notecard to your Notecarrier-F.

  1. Follow the steps in the Notecard Quickstart to connect your Notecard LoRa to your Notecarrier-F. Your antenna will only have one cable, and the Notecard LoRa only has one connection.

  2. Plug your Swan into the Feather headers on the Notecarrier F.

  3. Attach the Swan to your computer with a Micro USB to USB-A cable, using the Micro USB port on the Swan.

Notecard LoRa in Notecarrier F with antenna

Air Quality Sensor Connection

This solution makes use of the ENS160 sensor board, which measures indoor air quality. Connect the ENS160 sensor to the Swan board using the Qwiic cable:

  1. Insert one end of the Qwiic cable into the port labelled Qwiic on the Swan board
  2. Insert the other end of the Qwiic cable into either of the Qwiic sockets on the ENS160 sensor board.

Notecarrier connected to ENS160 breakout board with Qwiic cable

With the Swan board powered on, you will see a red LED light up on the ENS160 board, indicating that it is receiving power. To improve battery life, you may wish to cut the LED jumper to disable the LED. For more details, see the "LED Jumper" section in the Sparkfun ENS160 Qwiic Hookup Guide .

Firmware

The firmware provided uses the Arduino Framework, follow the instructions in the git repo to flash your Swan.

Air Quality Monitoring and Alerting Behavior

The firmware periodically monitors air quality and gas concentrations, and posts events with this information. Regular air quality 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.

Air quality events are posted to the Notefile aqi.qo. An air quality event has these properties:

{
  "app" : "nf30",       // the application name
  "aqi" : 1,            // Air Quality Index (1-5)
  "eco2" : 439,         // CO2 concentration in parts-per-million (ppm)
  "tvoc" : 41           // Total volatile organic compounds (VOCs) parts-per-billion (ppb)
}

Each air quality reading 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" : "nf30",       // the application name
  "aqi" : 3,            // Air Quality Index (1-5)
  "eco2" : 639,         // CO2 concentration in parts-per-million (ppm)
  "tvoc" : 241          // Total volatile organic compounds (VOCs) parts-per-billion (ppb)
}

The alert property has these values:

  • alert:1: Indicates an alert condition regarding air quality 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 the alert property set to 2, indicating that the alert is ongoing because air quality hasn't returned to normal levels. These events are not immediately sent to notehub, and are provided for continuous monitoring of air quality.

  • alert:3: Signifies a stand-down alert and that air quality has returned to normal levels. These events are sent immediately to notehub. This is typically used to send an external notification that air quality has returned to normal levels.

When air quality returns to normal, alert:3 is the last event sent with the alert property present. Subsequent events monitoring air quality do not have the alert property present until a new alert condition is detected.

Configuration

The file ./firmware/src/main.cpp contains a number of #defines that are used to configure how often air quality is measured and the thresholds that trigger an alert:

NameDefaultUnitDescription
AQI_MONITOR_PERIOD60secondsThe period in seconds between each air quality reading.
ALERTS_ONLYfalsebooleanWhen true, disables reporting of normal air quality and only alerts are sent.
ALERT_AQI_LEVEL31-5Trigger an alert when the measured AQI is at least this high. (Higher numbers mean poorer air quality.) Set to 0 to disable AQI alerts.
ALERT_ECO2_LEVEL500ppmTrigger an alert when the measured concentration of CO2 is at or above this level. Set to 0 to disable CO2 alerts. Note that the concentration of CO2 in the atmosphere is around 420 ppm.
ALERT_TVOC_LEVEL200ppbTrigger an alert when the measured concentration of VOCs is at or above this level. Set to 0 to disable VOC alerts.

Routing Data out of Notehub

Notehub supports forwarding data to a wide range of API endpoints by using the Route feature. This can be used to forward your air quality data to external dashboards and alerts to a realtime notification service. Here, we will use Twilio SMS API to send a notification of an alert to a phone number.

For an introduction to Twilio SMS routes, please see our Twilio SMS Guide.

  1. Fill out the required fields for the Twilio SMS route, including "from" and "to" phone numbers, where "from" is your virtual Twilio number, and "to" is the number of the phone that receives the alerts. We will not be using placeholders for these numbers, but will use a placeholder for the message, so set the message field to [.body.customMessage].

  2. Under the "Filters" section, set "Notefiles" to "All Notefiles" (the default value.)

  3. Under "Data", select "JSONata Expression" and copy and paste the contents of jsonata/route.jsonata into the text field "Insert your JSONata expression here".

  4. Click "Save Changes".

Naming Air Quality Monitors

Once the node names are configured, the name rather than the node ID will be used in SMS alerts.

Testing the Route

The ideal test is to use the app firmware to generate alerts. However, it's also possible to simulate an event by pasting these JSON snippets into the the in-browser terminal.

This is a regular air quality monitoring event. It does not generate an SMS alert.

{ "req": "note.add", "file":"aqi.qo", "sync": true, "body": {
  "alert":1, "tvoc":200, "eco2":500, "aqi":3
}}

This is an alert event (due to the presence of the alert property), which will result in an SMS message being sent to the phone number in the "to" field.

{ "req": "note.add", "file":"aqi.qo", "sync": true, "body": {
  "alert":1, "tvoc":200, "eco2":500, "aqi":3
}}

This event will send an SMS that looks like this:

ALERT! Air quality alert in main conference room. AQI: 3, CO2: 500ppm, TVOC: 200ppb.

These are the parts of the message:

  • The first part of the message indicates that this is an air quality alert and which monitor generated the alert, here, "main conference room".

  • Following that is the AQI, indicating air quality (1-5), and the concentration of CO2 and TVOCs.

Once the air quality returns to normal, another SMS is sent. This can be simulated by sending the event below:

{ "req": "note.add", "file":"aqi.qo", "sync": true, "body": {
  "alert":3, "tvoc":50, "eco2":400, "aqi":1
}}

Sending this event results in the message

Air quality normal in main conference room. AQI: 1, CO2: 400ppm, TVOC: 50ppb.

Blues Community

We’d love to hear about you and your project on the Blues Community Forum !

Additional Resources

  • ENS160 Datasheet

On This Page

  • You Will Need
  • Notehub Setup
  • LoRa Gateway Setup
  • Swan Setup
    • Air Quality Sensor Connection
  • Firmware
  • Air Quality Monitoring and Alerting Behavior
    • Configuration
  • Routing Data out of Notehub
    • Naming Air Quality Monitors
    • Testing the Route
  • Blues Community
  • Additional Resources

Resources

  • GitHub
  • Request More Info
© 2025 Blues Inc.
© 2025 Blues Inc.
TermsPrivacy
Notecard Disconnected
Having trouble connecting?

Try changing your USB cable as some cables do not support transferring data. If that does not solve your problem, contact us at support@blues.com and we will get you set up with another tool to communicate with the Notecard.

Advanced Usage

The help command gives more info.

Connect a Notecard
Use USB to connect and start issuing requests from the browser.
Try Notecard Simulator
Experiment with Notecard's latest firmware on a Simulator assigned to your free Notehub account.

Don't have an account? Sign up