Hi everyone !
Today, we will teach you how to reproduce our project : AirCitizen bythe AirCitizenPolytech Team !
Coming from the 'OpenAir / What's your air?' Projects, the AirCitizen project aims to enable citizens to actively evaluate the quality of their immediate environment and in particular the air they breathe, by offering them from:
Realize in "Fablabs" (digital manufacturing laboratories) portable stations of environmental measurements integrating various low-cost sensors (eg temperature, humidity, pressure, NOx gas, ozone or particles PM10 and PM2.5).
Perform in situ measurements in order to highlight spatiotemporal variability of the environmental variables: on the one hand, during itinerant campaigns with the support of geographers-climatologists and, on the other hand, in various places which present a diversity environmental contexts.
Contribute to improving knowledge by sharing these measurements in an environmental database and thus enable online mapping of air pollution.
The concept is to create an autonomous station who can collect environment datas and send them with the SigFox network to a dashboard.
So on the one hand, we will show you how to design the hardware and on the other hand how to do the software part.
Step 1: Hardware
Here are the components that we decided to use to design the station :
- STM32 NUCLEO-F303K8 -> For more informations
- HPMA115S0-XXX (Particles sensor PM2.5 & PM10) -> For more informations
- SHT11 or SHT10 or STH15 or DHT11(Temperature & Relative Humidity) -> For more informations
- MICS2714 (NO2 sensor, Nitrogen dioxide sensor) -> For more informations
- Solar Panel x2 (2W) -> For more informations
- Battery LiPo 3,7 V 1050 mAh -> For more informations
- Regulator LiPo Rider Pro (106990008) -> For more informations
- BreakOut SigFox BRKWS01 + 1 licence - > For more informations
- 7 resistors (86,6; 820; 1K; 1K; 4,7K; 10K; 20K)
- 1 capacitor (100nF)
- 1 transistor (2N222).
! ! ! You have to remove SB16 and SB18 on the stm32 nucleo board to prevent interferences between HPMA and SHT11 ! ! !
Basically, this is how you have to connect components :
- Weld, in parallel, the solar panels.
- Connect them to the LiPo Rider Pro and connect also the battery to the LiPo Rider Pro.
- Like the photo above, connect all the elements to the STM32. Connect only one temperature and humidity sensor not 2 ! Do not forget resistors, the capacitor and the transistor.
- Finally, connect the STM32 to the LiPo Rider Pro with a usb cable.
The next step is an alternative to this wired.
Step 2: Hardware - PCB
We decided to use Autodesk Eagle to design the printed circuit board (PCB).
You can choose to connect either a DHT or a SHT, we chose to design two fingerprints for these 2 sensors in order to change the sensor if needed.
In attachment, you can download the Eagle conception files so you can easily make it on your own.
We use the 5V pin of stm32 to supply the device. In this configuration, only stm32 core is powered.
Thus we can use the deep sleep mode of the MCU providing a low sleep current. In standby status,the whole sleeping current fall below XXµA.
Step 3: The LPWAN Protocol : Sigfox Communication
Sigfox is an LPWAN protocol created by a french telecom firm - SIGFOX
It enables remote devices to connect using ultra-narrow band (UNB) technology. Most of these will require only low bandwidth to transfer small amounts of data. Networks are only able to handle approximately 12 bytes per message and at the same time no more than 140 messages per device per day.
For many of IOT applications, the traditional cellular phone systems are too complex to allow for very low power operation and too costly to be feasible for many small low-cost nodes...The SIGFOX network and technology is aimed at the low-cost machine to machine application areas where wide area coverage is required.
For AirCitizen, the format of data detected is simple and the amount of data correct to use Sigfox for translating the data detected from sensors to our IOT platform - ThingSpeak.
We will introduce the use of Sigfox in the following steps.
Step 4: Software Configuration
Following the realization of our circuit, let's move on to the development of our STM32 F303K8 microcontroller.
For more simplicity, you can choose to program in Arduino.
Step 1: If you have not yet installed the Arduino IDE, download and install it from this link. Make sure you select your correct operating system.
The link : Download Arduino
Step 2: After Installing the Arduino IDE open and download the required packages for the STM32 board. This can be done by selecting File -> Preferences.
Step 3: Clicking on Preferences will open the below shown dialog box. In the additional Boards Manager URL text box paste the below link :
and press OK.
Step 4: Now go to Tool -> Boards -> Board Manager. This will open the Boards manager dialog box, search for “STM32 Cores” and install the package that appears (STMicrolectronics package).
Step 5: After the package, installation is completed. Go to Tools and scroll down to find the "Nucleo-32 series". Then make sure the variant is "Nucleo F303K8" and change the upload method to "STLink".
Step 6: Now, connect your board to the computer and check to which COM port the board is connected to using device manager. Then, select the same port number in Tools->Port.
You are now ready to program your STM32 F303K8 with Arduino !
Step 5: Program Your STM32
Once the configuration done, you need to program your micro controller to collect and send datas.
Step1: Check the affectation of I/O and measures timestamp in the "Define" part of the code.
Step2: Upload the code above to the stm32, open the serial monitor and reset the device. "AT" command should appear on the screen, if not, check I/O declaration.
You can have an idea of the veracity of your datas by consulting the french legislation standards in attachment.
Let's move on to the configuration of the dashboard.
Step 6: ThingSpeak - 1
Before configure how to redirect datas from our station to the ThingSpeak platform you have to create a ThingSpeak account.
Sign up : ThingSpeak Website
Step 1: Now click on "New Channel". This will open a form. Enter a name and a description (if needed).
Create 5 field :
- Field 1 : pm2,5
- Field 2 : pm10
- Field 3 : temperature
- Field 4 : humidity
- Field 5 : NO2
These titles will not be the titles of our charts.
If you need an example, See photo above.
You don't need to complete more fields but it could be interesting if you enter a location.
Scroll down and "Save Channel".
Step 2: AirCitizen Station Channel.
Now, you can see a page with 5 charts. By clicking on the pencil symbol you can change the properties of a graph.
The result is the second picture above.
At this step, those graphs are private. You will be able to make them public once the data received.
Step 3: After the configuration of your graphs. Go to the "API Keys" tab. Look at the API request part and more precisely the first field, "Update a Channel feed". Note the API KEY.
You will have something like this :
You are now able to go to the next chapter.
Step 7: Communication Between Sigfox Module and the ThingSpeak Platform
For your information, note that each Sigfox module card has a unique number wrote on the card and a PAC number.
To receive the data on ThingSpeak, you should redirect them.
Datas goes from the station to the Sigfox backend and will be redirect to the ThingSpeak server.
See the first picture above for explanations.
Step 1: We will not explain how to register on Sigfox because of many tutorials on the internet.
Go on the Sigfox Backend.
Click on "Device Type", then click on the line of your kit and select "Edit".
Now, go in "Callbacks" section and click on "New", "Custom Callback".
You should be on the configuration page :
- Type : DATA and UPLINK
- Channel : URL
- Send duplicate : none
- Custom payload config : Set the data source and decide the data form. You should write like:
In this case, we have 5 values named pm25, pm10, temperature, humidity, and NO2.
pm25::int:16 pm10::int:16 temperature::int:8 humidity::uint:8 NO2::uint:8
- Url pattern : This is the syntax. Use the previously found API key and insert it after "api_key =".
- Use HTTP Method : GET
- Send SNI : ON
- Headers : None
Click now on "Ok".
Your callback to the ThingSpeak API is now configured ! (Representation at the second picture above).
Step 8: ThingSpeak - 2
Now, you can be more picky in modifying the minimum and maximum values of the axes.
If necessary, click on the pencil logo at the top right of a graph.
Typical values :
- PM 2,5 & PM 10 = ug/m^3
- Temperature = °C
- Humidity = %
- Nitrogen Dioxide = ppm
You should have something like the two pictures above.
You can also add some other widgets like "Numeric Display" or "Gauge".
Finally, to make your channel public, go on the "Sharing" tab and select "Share channel view with everyone".
Step 9: Bonus - ThingTweet and React
Optional: Tweet if a condition is met !
Step 1: Create a twitter account or use your personal twitter account.
Step 2: In Thingspeak, go in "Apps" then click on "ThingTweet".
Link your twitter account by clicking on "Link Twitter Account".
Step 3: Now, go back in "Apps" then click on "React".
Create a new React by clicking on "New React".
By example :
- React Name: Temperature over 15°C
- Condition Type: Numeric
- Test Frequency: On data insertion
- Condition, if channel:
- Field: 3 (temperature)
- Sign: is greater than
- Value : 15
- Action: ThingTweet
- Then tweet: Oh ! The temperature is greater than 15 °C !
- using Twitter account:
- Options: Run action each time condition is met
Then click on "Save React".
Your will now tweet if the condition is met and many other conditions can be configured like depending on the level of PM10.
Step 10: It's Your Turn Now !
Finally, you now have all the elements to reproduce your own AirCitizen Station !
Video: You can watch a video where we present our work.
Our ThingSpeak platform: AirCitizenPolytech Station
Thank you for your attention !
The AirCitizen Polytech team