Skip to content

Commit 04a884f

Browse files
committed
Content update (Arduino style example code)
1 parent d21a675 commit 04a884f

File tree

3 files changed

+71
-65
lines changed

3 files changed

+71
-65
lines changed
Loading
Loading

content/hardware/06.nicla/boards/nicla-sense-env/tutorials/environmental-monitor-application-note/content.md

Lines changed: 71 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: 'Environmental Monitoring with the Nicla Sense Env'
3-
description: "This application note describes how to implement an outdoor air quality monitor with the Nicla Sense Env."
3+
description: "This application note describes how to implement a simple outdoor air quality monitor with the Arduino® Nicla Sense Env."
44
difficulty: intermediate
55
compatible-products: [nicla-sense-env]
66
tags:
@@ -19,69 +19,79 @@ software:
1919
- IoT-Cloud
2020
---
2121

22+
![ ](assets/hero-banner.png)
23+
2224
## Introduction
2325

24-
Air pollution is a growing concern in urban and industrial areas due to the harmful effects of airborne pollutants such as nitrogen dioxide (NO2), ozone (O3) and airborne particulate matter (PM) on human health and the environment. This application note presents the development of an outdoor air quality monitor using the Portenta C33 and the Nicla Sense Env. The outdoor air quality monitor provides real-time data on temperature, humidity, concentrations of NO2 and O3, and the outdoor air quality index (AQI), making it suitable for use in urban areas, industrial zones, or environmental research.
26+
Air pollution is a growing concern in urban and industrial areas due to the harmful effects of airborne pollutants such as nitrogen dioxide (NO₂) and ozone (O₃) on human health and the environment. This application note describes how to build a basic outdoor air quality monitor using the Arduino® Portenta C33 and the Nicla Sense Env board.
27+
28+
The outdoor air quality monitor provides real-time data on temperature (°C), humidity (%), concentrations of NO₂ (ppb) and O₃ (ppb), as well as the outdoor air quality index (AQI). It is suitable for deployment in urban areas, industrial zones or environmental research.
2529

2630
## Goals
2731

2832
The main goals of this application note are as follows:
2933

30-
- Develop a simple outdoor air quality monitor that provides real-time data on temperature, humidity, and pollutants such as nitrogen dioxide (NO2) and ozone (O3).
31-
- Collect accurate readings of NO2, O3 and the outdoor air quality index (AQI) to assess overall outdoor air quality.
32-
- Display real-time data from the Nicla Sense Env on the Arduino IDE Serial Monitor for immediate data observation and analysis.
33-
- Establish a connection to the Arduino Cloud to enable remote monitoring and data analysis of the collected outdoor air quality data.
34+
- Develop and implement a simple outdoor air quality monitor that provides real-time data on temperature, humidity, and pollutants such as nitrogen dioxide (NO₂) and ozone (O₃).
35+
- Collect real-time data on NO₂, O₃ and the outdoor air quality index (AQI) to evaluate outdoor air conditions.
36+
- Display live readings from the Nicla Sense Env board using the Arduino IDE Serial Monitor for immediate analysis.
37+
- Enable remote monitoring and analysis by connecting the monitor to the Arduino Cloud.
3438

3539
## Hardware and Software Requirements
3640

3741
### Hardware Requirements
3842

39-
- [Portenta C33](https://store.arduino.cc/products/portenta-c33) (x1)
4043
- [Nicla Sense Env](https://store.arduino.cc/products/nicla-sense-env) (x1)
41-
- USB-C® cable (x1)
44+
- [Portenta C33](https://store.arduino.cc/products/portenta-c33) (x1)
45+
- [USB-C® cable](https://store.arduino.cc/products/usb-cable2in1-type-c) (x1)
4246
- Wi-Fi® W.FL antenna (x1)
4347

4448
### Software Requirements
4549

46-
- [Arduino IDE 1.8.10+](https://www.arduino.cc/en/software), [Arduino IDE 2.0+](https://www.arduino.cc/en/software), or [Arduino Cloud Editor](https://create.arduino.cc/editor).
47-
- For the Wi-Fi® connectivity feature of Portenta C33, we will use the [Arduino Cloud](https://create.arduino.cc/iot/things). If you do not have an account, create one for free [here](https://cloud.arduino.cc/).
50+
- [Arduino IDE 2.0+](https://www.arduino.cc/en/software) or [Arduino Web Editor](https://create.arduino.cc/editor)
51+
- [Arduino_NiclaSenseEnv library](https://github.com/arduino-libraries/Arduino_NiclaSenseEnv)
52+
- [Arduino Renesas Portenta Boards core](https://github.com/arduino/ArduinoCore-renesas) (required to work with the Portenta C33 board)
53+
54+
***The Nicla Sense Env board is not intended as a standalone device but as a shield of another Portenta, MKR, or Nano family board. In this application note, we will use the Portenta C33 as the main board and the Nicla Sense Env board as a shield.***
4855

4956
## Hardware Setup Overview
5057

51-
The electrical connections of the proposed outdoor air quality monitor are shown in the diagram below:
58+
The electrical connections for the outdoor air quality monitor are outlined in the diagram below:
59+
60+
This diagram shows how the components are connected. The Portenta C33 serves as the host board or primary controller, while the Nicla Sense Env board (the host board or shield) collects temperature, humidity, and outdoor air quality data.
5261

53-
The diagram illustrates the connection of all the monitor's components. The Portenta C33 is the monitor's main controller; the Nicla Sense Env board provides temperature, humidity, and outdoor air quality data.
62+
![The environmental monitor hardware setup ](assets/user-manual-1.png)
5463

55-
The Nicla Sense Env is connected to the Portenta C33 via ESLOV. The monitor has one main voltage bus (+5 VDC from the Portenta C33) that powers the Nicla Sense Env, the Portenta C33 is powered through its onboard USB-C port for testing purposes.
64+
65+
The Nicla Sense Env board connects to the Portenta C33 using the ESLOV interface. The monitor operates with a single power supply bus (+5 VDC from the Portenta C33), which powers the Nicla Sense Env. For testing purposes, the Portenta C33 is powered via its onboard USB-C port.
5666

5767
## Understanding Outdoor Air Quality
5868

59-
Air pollution is not just a problem in urban areas; rural environments also face significant risks from pollutants like nitrogen dioxide (NO2) and ozone (O3). These gases pose serious health risks, especially for vulnerable populations. NO2, produced by combustion engines and industrial processes, can travel far beyond urban centers. O3, formed by atmospheric chemical reactions, affects urban and rural regions, especially during warmer seasons of the year.
69+
Air pollution is not just a problem in urban areas; rural environments also face significant risks from pollutants like nitrogen dioxide (NO₂) and ozone (O₃). These gases pose serious health risks, especially for vulnerable populations. NO₂, produced by combustion engines and industrial processes, can travel far beyond urban centers. O₃, formed by atmospheric chemical reactions, affects urban and rural regions, especially during warmer seasons of the year.
6070

6171
Real-time monitoring is critical in urban and rural settings to manage exposure to these pollutants properly. Air quality tracking and monitoring helps individuals and communities to proactively reduce health risks.
6272

6373
### The Role of Sensors in Air Quality Monitoring
6474

65-
This application note uses modern and state of the art sensors to provide accurate, real-time measurements of various pollutants. The Nicla Sense Env board offers an interesting solution for monitoring outdoor air quality.
75+
This application note uses advanced sensors to provide accurate, real-time measurements of various pollutants. The Nicla Sense Env board offers a versatile solution for outdoor air quality monitoring.
6676

67-
- **NO2 Sensor**: Detects nitrogen dioxide, a harmful gas released by vehicles and industrial activities.
68-
- **O3 Sensor**: Measures ozone, a gas that forms in the atmosphere through reactions between pollutants and sunlight, contributing to respiratory problems.
69-
- **Outdoor Air Quality Index (AQI)**: The AQI simplifies the interpretation of air quality by combining data from multiple pollutants (PM, NO2, O3) into a single value.
77+
- **NO₂ Sensor**: Detects nitrogen dioxide, a harmful gas released by vehicles and industrial activities.
78+
- **O₃ Sensor**: Measures ozone, a gas that forms in the atmosphere through reactions between pollutants and sunlight, contributing to respiratory problems.
79+
- **Outdoor Air Quality Index (AQI)**: The outdoor AQI simplifies the interpretation of air quality by combining data from multiple pollutants (NO₂ and O₃) into a single value.
7080

71-
The AQI index is based on a scale that ranges from 0 to 500, where:
81+
The AQI scale ranges from 0 to 500, with the following classifications:
7282

73-
- 0-50 indicates good air quality.
74-
- 51-100 is moderate.
75-
- 101-150 is unhealthy for sensitive groups.
76-
- 151-200 is unhealthy for everyone.
77-
- 201-300 is very unhealthy.
78-
- 301-500 signals hazardous conditions.
83+
- 0-50: Good air quality.
84+
- 51-100: Moderate air quality.
85+
- 101-150: Unhealthy for sensitive groups.
86+
- 151-200: Unhealthy for everyone.
87+
- 201-300: Very unhealthy.
88+
- 301-500: Hazardous conditions.
7989

80-
The AQI makes it easy to understand how outdoor air quality might affect public health, particularly when pollutant levels rise to unhealthy levels.
90+
The AQI makes it easy to understand how outdoor air quality affects public health, particularly when pollutant levels reach unhealthy or hazardous thresholds.
8191

82-
Monitoring NO2, O3, and AQI in real-time allows for immediate responses when air quality worsens. This is especially important in rural areas with less visible air quality issues. The data collected can be sent to platforms like Arduino Cloud, enabling remote monitoring and long-term trend analysis, improving public awareness and policy decisions.
92+
Monitoring NO₂, O₃, and AQI in real-time allows for immediate responses when air quality worsens. This is especially important in rural areas with less visible air quality issues. The data collected can be sent to platforms like Arduino Cloud, enabling remote monitoring and long-term trend analysis, improving public awareness and policy decisions.
8393

84-
## Environmental Monitor Example Sketch
94+
## Simple Environmental Monitor Example Sketch
8595

8696
Now that we have covered the hardware components of our environmental monitor and how they are interconnected, let's study the software that brings this monitor to life. The example sketch in the following section manages data collection from the Nicla Sense Env board and the PMS7003 sensor connected to the Portenta C33 board, allowing us to monitor real-time environmental data such as temperature, humidity, outdoor air quality, and particulate matter concentrations.
8797

@@ -97,7 +107,7 @@ The complete example sketch is shown below.
97107
from the Nicla Sense Env connected to the Portenta C33 board.
98108
The data is reported to the Arduino IDE's Serial Monitor every 10 seconds.
99109
100-
@version 1.0 01/09/24
110+
@version 1.1 06/10/24
101111
@author Arduino Product Experience Team
102112
*/
103113
@@ -108,10 +118,8 @@ The complete example sketch is shown below.
108118
static const uint32_t READ_INTERVAL = 10000;
109119
uint32_t lastReadTime = 0;
110120
111-
// Sensor objects for Nicla Sense Env data (using pointers)
121+
// Sensor object for Nicla Sense Env data
112122
NiclaSenseEnv device;
113-
TemperatureHumiditySensor* tempHumSensor;
114-
OutdoorAirQualitySensor* airQualitySensor;
115123
116124
/**
117125
Initializes the sensors and serial communication.
@@ -124,18 +132,14 @@ void setup() {
124132
Serial.begin(115200);
125133
126134
// Wait for Serial to be ready with a timeout of 5 seconds
127-
for(auto start = millis(); !Serial && millis() - start < 5000;);
135+
for(uint32_t start = millis(); !Serial && millis() - start < 5000;);
128136
129137
// Initialize NiclaSenseEnv sensors
130138
if (device.begin()) {
131139
Serial.println("- Nicla Sense Env is connected");
132140
133-
// Get the temperature and humidity sensor (use pointer)
134-
tempHumSensor = &device.temperatureHumiditySensor();
135-
136-
// Get and enable the outdoor air quality sensor (use pointer)
137-
airQualitySensor = &device.outdoorAirQualitySensor();
138-
airQualitySensor->setEnabled(true);
141+
// Enable the outdoor air quality sensor
142+
device.outdoorAirQualitySensor().setEnabled(true);
139143
} else {
140144
// Error message if the Nicla Sense Env is not found
141145
Serial.println("- ERROR: Nicla Sense Env device not found!");
@@ -165,14 +169,18 @@ void loop() {
165169
Reads data from the Nicla Sense Env and prints it in a single line format.
166170
*/
167171
void displayAllData() {
172+
// Get the temperature/humidity and air quality sensors
173+
TemperatureHumiditySensor& tempHumSensor = device.temperatureHumiditySensor();
174+
OutdoorAirQualitySensor& airQualitySensor = device.outdoorAirQualitySensor();
175+
168176
// Check if both temperature/humidity and air quality sensors are enabled
169-
if (tempHumSensor->enabled() && airQualitySensor->enabled()) {
177+
if (tempHumSensor.enabled() && airQualitySensor.enabled()) {
170178
// Read data from the Nicla Sense Env sensors
171-
float temperature = tempHumSensor->temperature();
172-
float humidity = tempHumSensor->humidity();
173-
float NO2 = airQualitySensor->NO2();
174-
float O3 = airQualitySensor->O3();
175-
int airQualityIndex = airQualitySensor->airQualityIndex();
179+
float temperature = tempHumSensor.temperature();
180+
float humidity = tempHumSensor.humidity();
181+
float NO2 = airQualitySensor.NO2();
182+
float O3 = airQualitySensor.O3();
183+
int airQualityIndex = airQualitySensor.airQualityIndex();
176184
177185
// Print all sensor data in a single line, with AQI at the end
178186
Serial.print("- Temperature: ");
@@ -211,13 +219,11 @@ The first step is to ensure that all necessary libraries are included to control
211219
static const uint32_t READ_INTERVAL = 10000;
212220
uint32_t lastReadTime = 0;
213221
214-
// Sensor objects for Nicla Sense Env data (using pointers)
222+
// Sensor object for Nicla Sense Env data
215223
NiclaSenseEnv device;
216-
TemperatureHumiditySensor* tempHumSensor;
217-
OutdoorAirQualitySensor* airQualitySensor;
218224
```
219225

220-
The Nicla Sense Env library handles data such as temperature, humidity, and outdoor air quality, including also the NO2 and O3 gas concentrations.
226+
The `Arduino_NiclaSenseEnv` library handles data such as temperature, humidity, and outdoor air quality, including NO, and O₃ gas concentrations.
221227

222228
### Sensors Initialization
223229

@@ -229,18 +235,14 @@ void setup() {
229235
Serial.begin(115200);
230236
231237
// Wait for Serial to be ready with a timeout of 5 seconds
232-
for(auto start = millis(); !Serial && millis() - start < 5000;);
238+
for(uint32_t start = millis(); !Serial && millis() - start < 5000;);
233239
234240
// Initialize NiclaSenseEnv sensors
235241
if (device.begin()) {
236242
Serial.println("- Nicla Sense Env is connected!");
237243
238-
// Get the temperature and humidity sensor (use pointer)
239-
tempHumSensor = &device.temperatureHumiditySensor();
240-
241-
// Get and enable the outdoor air quality sensor (use pointer)
242-
airQualitySensor = &device.outdoorAirQualitySensor();
243-
airQualitySensor->setEnabled(true);
244+
// Enable the outdoor air quality sensor
245+
device.outdoorAirQualitySensor().setEnabled(true);
244246
} else {
245247
// Error message if the Nicla Sense Env is not found
246248
Serial.println("- ERROR: Nicla Sense Env device not found!");
@@ -283,14 +285,18 @@ The `displayAllData()` function pulls together the data from each sensor and dis
283285

284286
```arduino
285287
void displayAllData() {
288+
// Get the temperature/humidity and air quality sensors
289+
TemperatureHumiditySensor& tempHumSensor = device.temperatureHumiditySensor();
290+
OutdoorAirQualitySensor& airQualitySensor = device.outdoorAirQualitySensor();
291+
286292
// Check if both temperature/humidity and air quality sensors are enabled
287-
if (tempHumSensor->enabled() && airQualitySensor->enabled()) {
293+
if (tempHumSensor.enabled() && airQualitySensor.enabled()) {
288294
// Read data from the Nicla Sense Env sensors
289-
float temperature = tempHumSensor->temperature();
290-
float humidity = tempHumSensor->humidity();
291-
float NO2 = airQualitySensor->NO2();
292-
float O3 = airQualitySensor->O3();
293-
int airQualityIndex = airQualitySensor->airQualityIndex();
295+
float temperature = tempHumSensor.temperature();
296+
float humidity = tempHumSensor.humidity();
297+
float NO2 = airQualitySensor.NO2();
298+
float O3 = airQualitySensor.O3();
299+
int airQualityIndex = airQualitySensor.airQualityIndex();
294300
295301
// Print all sensor data in a single line, with AQI at the end
296302
Serial.print("- Temperature: ");
@@ -313,7 +319,7 @@ void displayAllData() {
313319
In the code snippet shown before:
314320

315321
- The function first checks that the temperature/humidity sensor and the air quality sensor are enabled.
316-
- The function retrieves temperature, humidity, gas concentrations (NO2 and O3), and the air quality index (AQI) from the Nicla Sense Env board.
322+
- The function retrieves temperature, humidity, gas concentrations (NO₂ and O₃), and the air quality index (AQI) from the Nicla Sense Env board.
317323
- Finally, the data is printed in a single line on the IDE's Serial Monitor, with the AQI displayed at the end.
318324

319325
### Complete Example Sketch
@@ -322,13 +328,13 @@ The complete example sketch can be downloaded here.
322328

323329
## Conclusions
324330

325-
The development of this outdoor air quality monitor demonstrates the effectiveness of using affordable and accessible sensors to measure key environmental parameters in real-time. Integrating the Nicla Sense Env with the Portenta C33 allows the system to track temperature, humidity, NO2, and O3 levels. The ability to monitor these pollutants, combined with the outdoor AQI, provides valuable insights for understanding air quality in urban and rural areas. Furthermore, the system's connection to the Arduino Cloud allows for remote monitoring and analysis, making it versatile for various applications, from personal use to environmental research.
331+
The development of this outdoor air quality monitor demonstrates the effectiveness of using affordable and accessible sensors to measure key environmental parameters in real-time. Integrating the Nicla Sense Env with the Portenta C33 allows the system to track temperature, humidity, NO₂, and O3 levels. The ability to monitor these pollutants, combined with the outdoor AQI, provides valuable insights for understanding air quality in urban and rural areas. Furthermore, the system's connection to the Arduino Cloud allows for remote monitoring and analysis, making it versatile for various applications, from personal use to environmental research.
326332

327333
## Next Steps
328334

329335
Several improvements can be considered to extend the functionality of the outdoor air quality monitor:
330336

331-
- Add more sensors to the monitor to measure pollutants such as carbon monoxide (CO) or sulfur dioxide (SO2).
337+
- Add more sensors to the monitor to measure pollutants such as carbon monoxide (CO) or sulfur dioxide (SO₂).
332338
- Improve the monitor's energy efficiency for long-term deployment in remote or outdoor environments.
333339
- Build a custom dashboard on Arduino Cloud to visualize trends over time and allow for more detailed analysis of air quality data.
334340
- Implement an alert system that notifies users when pollutant levels exceed safe thresholds.

0 commit comments

Comments
 (0)