Arduino Based Air Quality Monitoring IOT Project

Arduino UNO is one of the most popular prototyping boards. It is small in size and packed with rich features. The board comes with built-in Arduino boot loader. It is an Atmega 328 based controller board which has 14 GPIO pins, 6 PWM pins, 6 Analog inputs and on board UART, SPI and TWI interfaces. In this IOT device, 9 pins of the board are utilized. There are six pins used to interface the character LCD. There are two pins utilized to interface the ESP8266 Wi-Fi Module and an analog input pin is used to connect with the MQ-135 sensor. Learn more about Arduino UNO from

16X2 Character LCD – The 16X2 LCD display is used to monitor the sensor values read by the Arduino board from MQ-135. It is interfaced with the Arduino UNO by connecting its data pins D4 to D7 with pins 6 down to 3 of the controller respectively. The RS and E pins of the LCD are connected to pins 13 and 12 of the controller respectively. The RW pin of the LCD module is connected to the ground. The circuit connections of the character LCD with the Arduino board are summarized in the following table – 

Fig. 5: Table listing circuit connections between Character LCD and Arduino Uno

From the sensitivity curve of the sensor, it can be seen that the resistance of the sensor decreases as the concentration of the target gas is increased in PPM while for clean air its resistance remains constant. In the graph, the Rs is the resistance in target gas and Ro is the resistance in clean air. The graph is shown for Carbon dioxide, Carbon Monoxide and Ammonia. The sensitivity of this sensor can be adjusted and calibrated to detect specific concentration level of a target gas. The sensor has four terminals – Ground, VCC, Digital Out and Analog Out. The VCC and Ground terminals of the sensor are connected to the common VCC and Ground. The Analog Output pin of the sensor is connected to the A0 pin of the Arduino. The analog output voltage from the sensor can be assumed directly proportional to the concentration of CO2 gas in PPM under standard conditions. The analog voltage is sensed from the sensor and converted to a digital value in range from 0 to 1023 by the inbuilt ADC channel of the controller. The digitized value is hence equal to the gas concentration in PPM.

MQ-135 Sensor – MQ-135 is a gas sensor which is used to measure the concentration of combustible gases. It has lower conductivity in clean air while its conductivity increases with the presence of the combustible gases in the air. The sensor is highly sensitive to gases like Ammonia, Sulphide and Benzene steam. The sensor can detect the concentration of combustible gases in range from 100 PPM to 1000 PPM.

MQ-135 Sensor – MQ-135 is a gas sensor which is used to measure the concentration of combustible gases. It has lower conductivity in clean air while its conductivity increases with the presence of the combustible gases in the air. The sensor is highly sensitive to gases like Ammonia, Sulphide and Benzene steam. The sensor can detect the concentration of combustible gases in range from 100 PPM to 1000 PPM.

The ESP-12 model is used in the project. The Reset and VCC pins of the module are connected to the 5V DC while Ground pin is connected to the common ground. The Tx and Rx pins of the module are connected to the pins 10 and 11 of the Arduino board respectively. The Arduino pins 10 and 11 are configured to serial receiver and transmitter through software serial function.

The ESP-12 model is used in the project. The Reset and VCC pins of the module are connected to the 5V DC while Ground pin is connected to the common ground. The Tx and Rx pins of the module are connected to the pins 10 and 11 of the Arduino board respectively. The Arduino pins 10 and 11 are configured to serial receiver and transmitter through software serial function.

The ESP8266 is capable of either hosting an application or off loading all Wi-Fi networking functions from another application processor. Each ESP8266 module comes pre-programmed with an AT command set firmware. So, one can simply hook this up to an Arduino device. Here it uploads the monitoring data to the cloud. The module comes available in two models – ESP-01 and ESP-12. ESP-12 has 16 pins available for interfacing while ESP-01 has only 8 pins available for use. The ESP-12 has the following pin configuration –

The ESP8266 is capable of either hosting an application or off loading all Wi-Fi networking functions from another application processor. Each ESP8266 module comes pre-programmed with an AT command set firmware. So, one can simply hook this up to an Arduino device. Here it uploads the monitoring data to the cloud. The module comes available in two models – ESP-01 and ESP-12. ESP-12 has 16 pins available for interfacing while ESP-01 has only 8 pins available for use. The ESP-12 has the following pin configuration –

ESP8266 Wi-Fi Module – The ESP8266 Wi-Fi Module is used to connect with any available internet hotspot and transfer sensor data to ThingSpeak Platform via Wi-Fi. The ESP8266 Wi-Fi Module is a self contained SOC with integrated TCP/IP protocol stack that can give any microcontroller access to a Wi-Fi network.

ESP8266 Wi-Fi Module – The ESP8266 Wi-Fi Module is used to connect with any available internet hotspot and transfer sensor data to ThingSpeak Platform via Wi-Fi. The ESP8266 Wi-Fi Module is a self contained SOC with integrated TCP/IP protocol stack that can give any microcontroller access to a Wi-Fi network.

 

Power Supply – The Arduino board and the Wi-Fi module require 3.3 V while LCD and MQ-135 sensor need 5V DC for their operation. The Arduino can be powered by connecting it to a USB connection. Since the voltage supply and ground pins of the other modules are connected with the common VCC and ground respectively, the rest of the components draw power from the 5V output of the Arduino board itself. 

 

How the circuit works – 

 

The device developed in this project can be installed near any Wi-Fi hotspot in a populated urban area. As the device is powered, the Arduino board loads the required libraries, flashes some initial messages on the LCD screen and start sensing data from the MQ-135 sensor. The sensitivity curve of the sensor for different combustible gases is already mentioned above. The sensor can be calibrated so that its analog output voltage is proportional to the concentration of polluting gases in PPM. The analog voltage sensed at the pin A0 of the Arduino is converted to a digital value by using the in-built ADC channel of the Arduino. The Arduino board has 10-bit ADC channels, so the digitized value ranges from 0 to 1023. The digitized value can be assumed proportional to the concentration of gases in PPM. The read value is first displayed on LCD screen and passed to the ESP8266 module wrapped in proper string through virtual serial function.  The Wi-Fi module is configured to connect with the ThingSpeak IOT platform. ThingSpeak is an IOT analytics platform service that allows to aggregate, visualize and analyze live data streams in the cloud. ThingSpeak provides instant visualizations of data posted by the IOT devices to ThingSpeak server. With the ability to execute MATLAB code in ThingSpeak one can perform online analysis and processing of the data as it comes in. 

 

The Wi-Fi module can be connected with the ThingSpeak server by sending AT commands from the module. The module first test the AT startup by sending the following command – 

 

AT

 

The command is passed by the controller to the Wi-Fi module using software serial function. In response to the command ‘AT’, the platform must respond with ‘OK’ if the  cloud service is running. Then, the AT command to view the version information is passed as follow – 

 

AT + GMR

 

 In response to this command, the IOT platform must respond by sending back the version information, sdk version and the time bin is compiled. Next, the AT command to set the connection to Wi-Fi mode is sent as follow – 

 

AT + CWMODE = 3

 

By setting the parameter in CWMODE to 3, the Wi-Fi connection is configured to SoftAP as well as station mode. This AT command can in fact take three parameters as follow – 

 

1 – set Wi-Fi connection to station mode

2 – set Wi-Fi connection to SoftAP mode

3 – set Wi-Fi connection to SoftAP + station mode

 

In response to this command, the IOT platform must send back the string indication the Wi-Fi connection mode set. Now the AT command to reset the module is sent as follow – 

AT + RST

In response to this command, the Wi-Fi module must restart and send back a response of ‘OK’. After resetting the module, AT command to setup multiple connections is  enabled by sending the following command –

 

AT + CIPMUX=1

 

 This AT command can take two parameters – 0 for setting single connection and 1 for setting multiple connections. Next, the command to connect with the Access Point (AP) is passed which takes two parameters where first parameter is the SSID of the registered cloud service on ThingSpeak and the other parameter is the password to login the cloud service. 

 

Now, the AT command to get local IP address is passed as follow – 

 

AT + CIFSR

 

In response to this command, the local IP address of the Wi-Fi connection is sent back by the module. Now, the module is ready to establish TCP IP connection with the ThingSpeak server. The controller reads the sensor data and store it in a string variable. The TCP IP connection is established by sending the following AT command – 

 

AT + CIPSTART = 4, “TCP”, “184.106.153.149”, 80

 

The AT + CIPSTART command can be used to establish a TCP connection, register an UDP port or establish an SSL connection. In the above command, it is used to establish a TCP IP connection. For establishing a TCP-IP connection, the command takes four parameters where first parameter is link ID which can be a number between 0 to 4, second parameter is connection type which can be TCP or UDP, third parameter is remote IP address or IP address of the cloud service to connect with and last parameter is detection time interval for checking if the connection is live. If the last parameter is set to 0, the TCP keep-alive feature is disabled otherwise a time interval in seconds range from 1 to 7200 can be passed as parameter. In response to this command, the server must respond with ‘OK’ if connection is successfully established otherwise it should respond with message ‘ERROR’. 

 

Now when the connection with the server is successfully established and the controller has read the sensor value, it can send the data to the cloud using the following command – 

 

AT + CIPSEND = 4

 

 This command takes four parameters, where first parameter is the link ID which can be a number between 0 to 4, second parameter is data length which can be maximum 2048 bytes long, third parameter is remote IP in case of an UDP connection and remote port number in case of UDP connection. The third and fourth parameter are optional and used only in case of UDP connection with the server. Since, the TCP IP connection is established, these parameters are not used. The command is followed by a string containing the URL having the field names and values passed through the HTTP GET method. In this project, a string containing the URL having API Key and the sensor value as the field and value is passed. The passed field and its value are logged on the cloud server.  It is important to pass the API key in this URL as one of the field-value in order to connect with the registered cloud service. The Air quality measured by sensor can now be monitored and recorded through the thingspeak IOT plat form through the Wi-Fi module.  The recorded data is shown at the ThingSpeak platform as follow – 

 

Screenshot of User Interface of ThingSpeak PlatformScreenshot of User Interface of ThingSpeak Platform

 

Fig. 8: Screenshot of User Interface of ThingSpeak Platform