This project represent an device capable to measure six types of gases and environmental parameters.
For gases, only qualitative measurements are available, due to sensors characteristics.
After the gases and environmental sensors was read, all data are sent to Datacake IoT environment, to be stored visualized, using cellular connection, thanks to AVR IoT Cellular Mini kit.
The device is powered by a solar panel connected to a solar charger, that can also charge an LiPo accumulator, for backup.
Additionally I connected an ESP8266 module to the project, in order to send data over WiFi network, in case on cellular is not available (this part is in progress now...).
Because the intention of this device is to monitor outside places, I add to this device an GPS receiver; the location is also sent to Datacake, to know all the time where the sensor is present, on map.
To locally verify/monitor the data, I added an large TFT display 240x320 pixels to the project.
OBS: this devise should be calibrated in order to use the measured values for some decisions.
HardwareThe hardware part consist in the following components/modules:
- AVR IoT Cellular Mini board with SIM card and GSM antenna;
- TFT display 320x240 ILI9341;
- GY-GPS6MV2 GPS module with Ublox NEO-6 GPS SoC and antenna;
- BME280 environment sensor module;
- gas sensor module, that contain 6 analog gas sensors: VOC, CO, Smoke, CH4, Odor and NH3. All these 6 sensors are connected to only one analog input from AVR IoT Cellular Mini board, using an analog multiplexor (74HC4051);
- 6V/1A solar panel connected to Solar Power Manager 5V V1.1, both from DFRobot.
- DS3231 RTC;
- ESP8266-01 (optional, notimplemented yet);
The schematic for this project is splitted in two parts: one is the analog gas sensors and another is for whole device. The schematics and PCB for these two parts are available in attachments area.
The board with analog gas sensors contain:
- 6 analog sensors for the following gases type: VOC, CO, Smoke, Odor, CH4 and NH3;
- an analogic multiplexer 74HC4051;
- 5V to 3, 3V DC-DC step down power supply;
- other components, like: resistors, capacitors, LED, connectors.
The schematic and PCB are available in Attachment area. The PCB for the gas sensor is mabe by JLCPCB.
I used this construction approach in order to increase the number of analog input that can be read to 8. For this project, 7 analog inputs are used: 6 for sensors and one for DIP switch.
The whole 6 gas sensors, from DFRobot, are capable of only qualitative measurements. According to the datasheets (attached), each sensor can measure gas in the following range:
- VOC sensor: 0...500 ppm;
- CO sensor: 5...5000 ppm;
- Smoke sensor: 1...1000 ppm ( important gas measures is C3H8 Propane);
- CH4 sensor: 1...10000 ppm (CH4 - Methane, C3H8 - Propane);
- ODOR sensor: 0.5...50 ppm (H2S, Alcohol, and acetone gas);
- NH3 sensor: 1...300 ppm (NH3 - Ammonia).
Board with analog gas sensors:
The board with whole components contain:
- TFT display 320x240 pixels with SPI interface, analog gas sensor board, GPS module, ESP8266-01 module, BME280 sensor, AVR IoT Cellular Mini board, DS3231 RTC module, DIP switch and analog multiplexer CD4052B. This analog multiplexer is used to share the RS232 port from AVR IoT Cellular Mini with GPS receiver, ESP8266-01 and external Settings port.
The schematic of gas sensor and main PCB was created using KiCad 7.0. Then the Gerber files was sent to PCBWay to be produced, in pack of 5 pieces. The quality of the PCB is very good.
Main board presentation:
Obs: for the moment, the communication over RS232 is established only between GPS module and main AVR IoT Cellular Mini, because the WiFi communication and Settings is not implemented yet.
SoftwareThe software for this project is written using Arduino IDE V1.8.57.0, because the board AVR IoT Cellular Mini is fully supported by Arduino IDE.
The software is designed to read gas, light and environmental sensors, GPS data and then send the values to Datacake IoT cloud using GSM and/or WiFi network communication.
OBS: for this project stage, the WiFi communication is not implemented yet and the content of these functions are set to NTB!
All the libraries used are presented in the.ino file attached.
To communicate with Datacake via GSM, I setup the communication from this link, provided by Microchip site. For that I created an account on the Truephone site and then I finished the setup.
WorkingAfter the power is applied through AVR IoT Cellular Mini USB-C connector, the device will initialize GPS module, the TFT display, the internal board sensors (MCP9808 and Veml3328), configure all the PINs used to read analog sensors, initialize I2C communication with BME280 sensor and read the DIP switch positions.
If the DIP switch 3, GSM OnOff, is in ON position, then start connection to GSM operator, initialize connection to Datacake MQTT broker, read date and time from internet, set the RTC and then display the fixed part of information on TFT display (title and the name of sensors).
If the DIP switch 3, GSM OnOff is in OFF possition, then the GSM connection (and of course, connection to Datacake broker) will not be established and RTC will not be set; the data from sensors will be only displayed on TFT screen.
Then, the sensors are interrogated, the values are displayed on TFT and then are sent to Datacake through MQTT protocol over GSM.
Block diagram of the working application:
In the main loop, the program check the status of DIP switch, used for:
- switch 3 - used to enable/disable GSM connection;
- switch 2 - used to enable/disable WiFi connection;
- switch 1 - used to entre the system in Setup mode
OBS: WiFi and Setup mode are not implemented yet. These two functionalities will be implemented/used as follow:
- Setup mode will setup RTC (in case of no GPS signal availableor in case there will be no GSM and GPS coverage); also will be used to set the data transfer rate to Datacake broker, the sensor reading rate, the ssid and pass for wifi, and other variable used in this project;
- WiFi connection will be used to transfer data to Datacake or other local/on internet MQTT broker/web page.
The data from sensors is read and displayed more often that are transmitted to Datacake cloud.
For this project I set the read and display data to 30 seconds and transmission rate to Datacake to 1 minute. The rate of reading and transmission could be set in.ino file using variable "interval_2" (for sensors reading) and "interval_3" (for transmission to Datacake (see the.ino file for settings of these to variables).
In real world, these read and transmission rates could/should be higher, at least for MQTT transmission.
OBS: during MQTT transmission, if the sensor module can not reach the Datacake broker, then an restart mechanism of re-connecting to GSM and Datacake broker is implemented. if this reconnection failed, an specific icon is displayed on TFT ("sad face").
Explanation of data displayed on TFT:
The text, numbers and special characters displayed on TFT are defined in the "Adafruit_ILI9341.h" library. The manual of this library is attached to the project. Here is presented the whole characters that can be used/displayed without external code (the character set is used in default state - from left side):
The RTC is set during the Setup, after the system is powered up.
The procedure is this: if GSM connection is established, then the date and time is read from "worldtimeapi.org" and the DS3231 RTC is set. Then, in the main loop, the date and time is displayed from two source, as follow:
- from RTC, if GPS data is not available and is colored in white on TFT;
OR
- from GPS, if GPS data are available and is colored in green on TFT.
Very important:
A. in order to use I2C1 communication, from QWIC connector (these pins are exposed on AVR IoT Cellular Mini) I modified the library "DS3231.h", file DS3231.ccp, as follow, to "tell" the library to use the I2C1 communication instead the default I2C:
- line 50 is modified from original code:
DS3231::DS3231() : _Wire(Wire) {
to modified line:
DS3231::DS3231() : _Wire(Wire1) {
B. to convert the unit time receiver from "worldtimeapi.org" I used the "TimeLib.h" library; but at compilation, a lot o errors was generated because this library interferes with the RTC "DS3231.h" library. After some investigation I solved the errors by commented the following lines from "DS3231.h"library, file DS3231.ccp, starting to line number 271:
// setEpoch function gives the epoch as parameter and feeds the RTC
// epoch = UnixTime and starts at 01.01.1970 00:00:00
// HINT: => the AVR time.h Lib is based on the year 2000
//void DS3231::setEpoch(time_t epoch, bool flag_localtime) {
//#if defined (__AVR__)
// epoch -= SECONDS_FROM_1970_TO_2000;
//#endif
// struct tm tmnow;
// if (flag_localtime) {
// localtime_r(&epoch, &tmnow);
// }
// else {
// gmtime_r(&epoch, &tmnow);
// }
// setSecond(tmnow.tm_sec);
// setMinute(tmnow.tm_min);
// setHour(tmnow.tm_hour);
// setDoW(tmnow.tm_wday + 1U);
// setDate(tmnow.tm_mday);
// setMonth(tmnow.tm_mon + 1U);
// setYear(tmnow.tm_year - 100U);
//}
Video with working Gas sensor:
DatacakeThe data from gas sensor are sent to the Datacake IoT platform in order to be stored and displayed. I used this solution because the data could be available from the internet, even on mobile application.
First I created an account on Datacake, accessing this link.
Then, I created a new device on Datacake, in order to be able to receive data from my Gas sensor:
Next, select the Gas sensor, new device created, and go to Settings:
Here I created all the fields used to receive data from my Gas sensor:
OBS: the fields created in Configuration tab should be the same as in the.ino file, function "send_MQTT_data_to_Datacake()"; example (in red):
Then I configured the MQTT server used to sent data from AVR IoT Cellular mini to Datacake, from the Configuration tab, as above:
The MQTT Datacake server uned to publish measurements:
OBS: the MQTT server from Datacake is not free to use; for that I purchased a subscription for Light plan:
Plan for using MQTT server:
Then, I created a panel where all the data is displayed:
OBS: to send data to MQTT broker (to Datacake) the user name and pass are the same; these are equal with MQTT API generated from here:
In order to use Datacake, the information from Documentation (from Datacake) section is used; moreover, the following link can be used to find out more details about how to setup Datacake MQTT broker: link
Datacake mobile application can be downloaded from Magazin Play (for Android OS). Then, go to in Datacake Devices, Dashboard, enter in development mode and press on Public link button. Then, from mobile app, scan the QR code to connect with Gas sensor mobile dashboard.
Datacake mobile application dashboard:
For this device I used an main PCB, made on PCBWay (schematic and Gerber files are available in Attachment area). On this main pcb I arranged the whole components as follows:
- on the front, I mounted: TFT display, GSM module, 6 analog gas sensors module, environmental sensor BMR280 and WiFi ESP8266-01.
- on the back I mounted: the main board AVR IoT Cellular Mini, DIP switch, RTC module.
In order to assemble the Gas sensor, I designed also an 3D printed "case" to hold all components: the main PCB, the antennas (GSM and GPS), solar power supply and 3, 7V LiPo battery. The files are available in Attachment section.
Pictures with gas sensor assembled:
Gas sensor is powered by DFRobot Solar Power Manager 5V module to which a solar panel is connected, DFRobot Semi Flexible Monocrystalline Solar Panel (6V 1A); also, the power module can charge a 3.7V/1200mA LiPo battery, used when the solar panel can not supply enough energy. To charge the LiPo battery, an external 5V/1A microUSB connector is present on power supply module.
Pictures with power supply:
The current consumption:
- 250-270 mA without data transmission;
- 320-360mA with GSM data transmission.
1. AVR IoT Cellular mini is mounted on the back of the gas sensor.
Explanation: after receiving the board, I soldered the pin headers on top of the board. Was ok during the initial tests, but then, after I start to develop the main pcb, I realized that I soldered the pin headers on wrong surface of AVR board and, because I can damage the board if I try to change the pin headers position, I decided to mount the AVR board on the back of the main pcb of gas sensor.
2. Connectors J6 and J2 are placed in wrong position.
Explanation: during main pcb development, I placed the connectors J2 and J6 in wrong position, as follow:
- J6, used to connect TFT display should be placed flipped horizontally;
- J2, used to connect auxiliary analog input should be flipped vertically.
I reworked the PCB, but in this project I used the first one, with these errors and I used some wires to re-route the signals in the correct way:
1. Setup the ESP8266-01 to send the sensors data to local MQTT broker to save data; the local broker will be created on Raspberry PI; Node red will be set to receive data and store them on a local SQLite database. To transmit the data using the WiFi module, I try two methods:
- using AT Commands, build in the ESP8266-01 firmware; this is in progress;
- using a specific firmware; this will be done after the MQTT server, Node Red and SQLite database will be installed and configured.
2. Setup AVR IoT Cellular Mini to store the data from sensors locally, on the on board eeprom memory; then, am mechanism will be designed to retrieve these data over serial port (using Settings) or over WiFi.
3. Implement a low power mechanism that will "put to sleep" the MCU between GSM transmissions, to conserve the battery energy.
4. Note from 18 June 2024: the continuation of the project can be seen here: https://www.hackster.io/popa-mihai/portable-gas-analyzer-enhanced-291d3e
Comments