Close
0%
0%

IAQ WSN

We are building a wireless sensor network that is monitoring indoor air quality

Similar projects worth following
Air quality is a vital component in our lives. Yet it is very hard to feel or sense, since its changes are usually gradual. We are all familiar with that situation when one person enters the room we’ve spent the past couple of hours in and immediately says: “The air is really bad”. Usually, we don’t notice the air quality degrade while we are in the room. Therefore it seems logical to transfer this task to a technological device.
Indoor air quality has a significant impact on public health. Nowadays, an average person spends approximately 90% of their time indoors. The US-American Environmental Protection Agency identified poor indoor air quality as one of the five major public health risks.
At workplaces the air quality is sometimes measured, but this is usually a single measurement.
Continuous indoor air quality measuring provides immediate feedback relevant to that current situation.

Most IAQ systems that are commercially available are designed to warn users once the measured data passes a certain dangerous limits (for example smoke detectors). However, they don't deliver regular data.

Our goal is to create a wireless indoor air quality monitoring system that measures carbon monoxide (CO), carbon dioxide (CO2), VOC and temperature within our university buildings and communicate the data to the students and staff using those buildings.

This will raise the user's awareness of air quality and possibly trigger actions like opening windows or going outside to take a break and get some fresh air.

JPEG Image - 1.96 MB - 01/07/2016 at 23:34

Preview
Download

  • 1 × Arduino Uno
  • 1 × Raspberry Pi 2B
  • 1 × TGS2442 CO sensor
  • 1 × TGS2602 VOC sensor
  • 1 × TMP36 Temperature sensor

View all 14 components

  • Project relevance

    vlapp1701/15/2016 at 09:20 0 comments

    Air quality is a vital component in our lives. Yet it is very hard to feel or sense, since its changes are usually gradual. We are all familiar with that situation when one person enters the room we’ve spent the past couple of hours in and immediately says: “The air is really bad”. Usually, we don’t notice the air quality degrade while we are in the room. Therefore it seems logical to transfer this task to a technological device.

    Indoor air quality has a significant impact on public health. Nowadays, an average person spends approximately 90% of their time indoors. The US-American Environmental Protection Agency identified poor indoor air quality as one of the five major public health risks.

    At workplaces the air quality is sometimes measured, but this is usually a single measurement.

    Continuous indoor air quality measuring provides immediate feedback relevant to that current situation.

    Most IAQ systems that are commercially available are designed to warn users once the measured data passes a certain dangerous limits (for example smoke detectors). However, they don't deliver regular data.

    Our goal is to create a wireless indoor air quality monitoring system that measures carbon monoxide (CO), carbon dioxide (CO2), VOC (volatile organic compounds) and temperature within our university buildings and communicate the data to the students and staff using those buildings.

    This will raise the user's awareness of air quality and possibly trigger actions like opening windows or going outside to take a break and get some fresh air.

    Volatile organic compounds (VOCs) are gases that get emitted by certain liquids or solids. Some VOCs can lead to adverse health effects. Monitoring VOCs is especially relevant indoors because the concentrations of VOCs are higher indoors than outdoors (up to 10 times). On top of that, VOC pollution persists long after the actual usage moment of the VOC-emitting product. Sources of VOCs are paints, cleaning products, air fresheners, wood preservatives, etc. Short term health effects are irritation of eye, nose and throat, headaches, nausea, and coordination problems. On the long term, exposure to VOCs can damage liver, kidney and the central nervous system and some VOCs are known to cause cancer.

    Carbon monoxide is often referred to as the “silent killer” because it reduces oxygen delivery to the body’s organs and tissues and can cause death. The fact that it is odourless and invisible makes it especially necessary to monitor. Indoor monitoring is essential because CO levels can quickly become lethal in closed environments. Causes include malfunctioning fuel-burning devices such as water heaters or furnaces, fireplaces, generators or other engine-powered devices, etc.

    The main source of indoor carbon dioxide emissions are humans. High levels may lead to drowsiness or headaches.

    But why a wireless sensor network?

    The divided spaces of large buildings exhibit vastly different microclimate conditions, which necessitate simultaneous distributed monitoring with many sensor nodes to accurately characterize the spatiotemporal dynamics and correlation properties of the air quality conditions throughout the building.

  • Setup

    vlapp1701/15/2016 at 09:19 0 comments

    We have several parts interacting with each other. The data from the sensors is stored in the Arduino Uno and sent to the Raspberry Pi 2B through the WiFi module. The Raspberry Pi can then process the data and produce a graph with the current gas levels in a space. In order to receive data, the Raspberry Pi also needs a WiFi module. We use the TGS2442 CO sensor, the TGS2602 VOC sensor, and a simple TMP36 sensor for temperature. A CO2 sensor isn’t included due to long delivery times. The sensors and the Arduino function as a sensor node, the Raspberry Pi as the data sink.

  • ​Sensor Circuit

    vlapp1701/15/2016 at 09:09 0 comments

    The gas sensors both have four contacts. Basically, a heater is powered by connecting contact 4 to the required voltage and contact 1 to ground. The second part of the circuit is a variable resistor that is incorporated in each sensor. The resistance between contacts 2 and 3 varies depending on how much of the respective gas is sensed. The higher the gas concentration, the lower the resistance (and the higher the conductivity). Instead of directly measuring that resistance, the voltage level between load resistor and sensor contact 2 gets measured. It can be acquired by using an analog input pin of the Arduino. The sensor and the load resistor together form a voltage divider, so the higher the sensor resistance, the higher the voltage measured. The figure below shows a voltage divider. In our situation R1 corresponds to the sensor resistance, R2 is the load resistance, Vout is the measuring point, and Vin is the circuit voltage powering the sensor circuit.

    The sensor resistance – voltage relationship is:

    Vout=R2*R1+R2.

    It should be considered that the sensors have long break-in periods (2 days CO, 7 days VOC). That means they have to be running for a specific period of time before the readings are stable.

    Fig. Circuit wiring of the setup.

    The wiring of the sensor pin connections can be found in the datasheets of each sensor. The heater voltage and circuit voltage of the CO sensor are alternating differently, therefore the CO sensor has to be connected to two different digital pins. The heater and circuit voltage of the VOC sensor are both always kept at 5V, which makes it possible to use the same pin as voltage source.

  • Sensor calibration

    vlapp1701/15/2016 at 09:08 0 comments

    Ideally, the analog input value should be converted into parts per million (ppm). This requires calibration of the sensors. Calibration involves exposing the sensor to a known gas concentration and see the voltage reading. This can then be used to calculate an unknown concentration from a reading. Since we couldn’t find a way of producing an environment with a known VOC or CO concentration, we decided to simply convert the raw voltage values into percentages via a map function.

    On top of that, there are other environmental factors that affect the sensor resistance such as humidity and temperature which make a reliable data acquisition even harder.

  • TCP Python code

    vlapp1701/15/2016 at 09:06 0 comments

    We have tried to create a TCP socket, but this hasn't worked out.

    import socket   
    import sys  
    import struct
    import time
    
    #main function
    if __name__ == "__main__":
    
        host = "192.168.16.100"
        port = 22  
    
    #create an INET, STREAMing socket
    try:
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    except socket.error:
        print 'Failed to create socket'
        sys.exit()
    
    print 'Socket Created'
    
    try:
        remote_ip = socket.gethostbyname( host )
        s.connect((host, port))
    
    except socket.gaierror:
        print 'Hostname could not be resolved. Exiting'
        sys.exit()
    
    print 'Socket Connected to ' + host + ' on ip ' + remote_ip
    
    def recv_timeout(the_socket,timeout=2):
        #make socket non blocking
        the_socket.setblocking(0)
    
        #total data partwise in an array
        total_data=[];
        data='';
    
        #beginning time
        begin=time.time()
        while 1:
            #if you got some data, then break after timeout
            if total_data and time.time()-begin > timeout:
                break
    
            #if you got no data at all, wait a little longer, twice the timeout
            elif time.time()-begin > timeout*2:
                break
    
            #recv something
            try:
                data = the_socket.recv(8192)
                if data:
                    total_data.append(data)
                    #change the beginning time for measurement
                    begin=time.time()
                else:
                    #sleep for sometime to indicate a gap
                    time.sleep(0.1)
            except:
                pass
    
        #join all parts to make final string
        return ''.join(total_data)
    
    #get reply and print
    print recv_timeout(s)
    
    #Send some data to remote server
    massage = "I'm here!!!"
    
    try :
        #Set the whole string
        while True:
            message = recv_timeout(s)
            s.send(massage)
            print message
            print massage
            time.sleep(1)
            print 'Sending...'
    except socket.error:
        #Send failed
        print 'Send failed'
        sys.exit()
    
    
    s.close()

  • Arduino code

    vlapp1701/15/2016 at 09:03 0 comments

    The code we wrote for the sensor circuit is very straightforward (see Appendix). It basically reads the voltage belonging to each sensor. The voltage of the temperature circuit is then converted to degrees Celsius. For simplicity reasons the voltages of the gas sensors are simply mapped to a scale from 0 to 100. So you can read the gas concentration in percent. The CO sensor requires the application of a one second heating cycle in connection with a circuit voltage cycle. Each heating cycle consists of 4.8V being applied for 14ms followed by a 0V pulse for the remaining 986ms. The circuit voltage cycle starts with 0V being applied for 995ms, followed by 5ms of 5V. This is implemented in the code using the digitalWrite and analogWrite commands. For the analogWrite command, the required PWM frequency for the wanted voltage needs to be determined. The output consists of several numbers, namely the data from each sensor. The data from all sensors per time slot can be broadcasted as one data packet.

    int VOCSensor = A0; //TGS2602
    int COSensor = A1; //TGS2442
    int TempSensor = A2; //TMP36
    //int SoundSensor = A3; 
    int circ = 5;
    int heat = 6;
    int circheat = 9;
    float VOC, CO, Temp, Sound;
    
    void setup() {
    Serial.begin(9600);
    pinMode(circ, OUTPUT);
    pinMode(heat, OUTPUT);
    pinMode(circheat, OUTPUT);
    }
    
    void loop() {
    
    GetVOC();
    GetCO();
    GetTemp();
    
    Serial.println(VOC);
    Serial.println(CO);
    Serial.println(Temp);
    //Serial.println(Sound);
    delay(1000);
    }
    
    void GetVOC()
    {
     digitalWrite(circheat, HIGH);
     float VOC = analogRead(VOCSensor);
     VOC = map(val0, 0, 1023, 0, 100); //in %
    }
    
    void GetCO()
    {
     digitalWrite(circ, LOW);
     analogWrite(heat, 245); //PWM pin (range 0 to 255), PWM pin value = 255* (AnalogVolts / 5), here: AnalogVolts: 4.5, gives PWM pin value 245
     delay(14);
     analogWrite(heat, 0);
     delay(981);
     digitalWrite(circ, HIGH);
     delay(5); //original code: 3
     float val1 = analogRead(COSensor);
     CO = map(val1, 0 , 1023, 0, 100); //in %
    }
    
    void GetTemp()
    {
     Temp = (getVoltage(TempSensor)-0.5)*100; //in degrees C
    }
    
    float getVoltage(int pin) //This converts the analog reading (range from 0 - 1023) to a voltage (range from 0 to 5V)
    {
      return (analogRead(pin)*(5.0/1023.0));
    }
    
    float map(float x, float in_min, float in_max, float out_min, float out_max)
    {
     return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
    }

  • Raspberry Pi 2B

    vlapp1701/15/2016 at 08:57 0 comments

    The Raspberry Pi 2 comes in great when a low-cost, multi-purpose minicomputer with computational power is needed. Our reason to choose this device is that we want the setup to be able to run independently from its makers. Leaving an expensive PC or smartphone is more difficult in a public building than leaving small boxes with relatively cheap hardware. The Raspberry Pi is used in our project as the sink of the network, and therefore it needs to be able to connect to the server (Arduino WiFi shield), receive data sent by the Arduino, process this data and display it to the user. The Raspberry Pi runs on Raspbian, which is a version of the OS Linux, and in order to execute all the necessary commands it needs to run several programmes. Now, as an open source operating system, Linux is very different from Windows and assumes that everything more specific than basic programming and mathematics programmes are to be built by the user himself. An http server has to be configured in order for a TCP client/server socket to work, Raspberry Pi has a descriptive tutorial on how to do this. Then the TCP client can be programmed in Python, we found code for that online. The TCP socket creates a connection between the Raspberry Pi and the WiFi shield of the Arduino through a port defined in the code, so that it can receive data from the Arduino. Real-time graphing could possibly be done with Python with an adjusted version of a tutorial we also found online. We could make a list of the data that is received each time, and instead of pins assign an index in the list to the data from each type of sensor.

    We have tried to install a readymade TCP client/server by changing a kernel and installing wine, we have installed Windows 10 IoT to see if that could install and run a readymade TCP client/server and finally back to Linux we have adjusted different TCP Python codes but it all seemed to not work. The problem was that we did not know the Raspberry Pi is secured and that a TCP needs to be configured in a special way to overcome this, but luckily Raimond Frentrop from the Optics group could tell us running an http server would solve the issue of dealing with all the detailed fiddling with the TCP. This is due to the Raspberry Pi trusting the http server rather than a bare TCP socket. We have configured the http server as a last minute resort to establish a link between the Arduino and the Raspberry Pi. It turned out that the web page has to be configured to allow changes to be made to it by the Arduino so that the Raspberry Pi can then read that data, but we did not look into this.

  • INTERNET PROTOCOL STACK

    vlapp1701/15/2016 at 08:56 0 comments

    In the 1990s, there was no standard way to communicate between the different networks, operating systems and computers available. As a consequence of this interoperability problem the International Standards Organization (ISO) developed the OSI (Open Systems Interconnect) model. It was a guide on how to get all computers, networks and operating systems to smoothly communicate with each other. The OSI model describes the network protocol stack which is a set of rules that determine how data is communicated over a network. It consists of seven layers that each have a special function:

    Application

    Consists of network aware applications like e.g. email, web browsers, file sharing services etc.

    Presentation

    Its job is to configure the data if needed, e.g. through encryption

    Session

    Its job is to control the communication by for instance coordinating login rights etc.

    Transport

    Guarantees end to end delivery of data (e.g. by verifying existence of destination, using ACK packages, error checking of data)

    Network

    Finds best path to the destination network (responsible for e.g. routing, traffic control)

    Data Link

    Guarantee reliable transmission through managing usage of the (shared) transmission medium and finding physical device on the network

    Physical

    Describes physical part of the network, e.g. cables, responsible for transmission of bits to physical destination (bit encoding, transfer rates)

    TCI/IP is the implementation of the OSI model that is used for the Internet. It consists of many protocols that are all sorted into four layers which correspond to the OSI model. Each layer has a PDU that describes the layer’s information.

    Internet protocol (TCP/IP)

    OSI model

    Protocols

    PDU (Protocol data unit)

    Application

    Application, Presentation, Session

    HTTP, FTP, etc.

    Data

    Transport

    Transport

    TCP, UDP, etc.

    TCP: segments, UDP: datagrams

    Internet

    Network Layer

    IP, ICMP, etc.

    Packets

    Network Access

    Data Link, Physical

    Ethernet, ISDN

    Data link: frames, physical: bits

  • TCP

    vlapp1712/15/2015 at 19:29 0 comments

    TCP stands for Transmission Control Protocol and is a standard that defines how to establish a network conversation than can be used to exchange data between different applications. TCP works together with the Internet Protocol (IP), which defines how computers send data to each other. TCP and IP together are the most important protocols of the internet protocol suite that will be described in detail later (see INTERNET PROTOCOL STACK).

    Communication with the protocol at the same level in the stack at the other end is called a peer connection and is possible if the peers use the same protocol. To send the data from the sensor node to the sink we established a TCP link between the Arduino and our Smartphones. This was achieved by using an Arduino WiFi shield with an UART WiFi module and downloading a TCP/IP communication app on our phones (“TCP Client”). The TCP Client app allows the phone to connect to a specific TCP in order to deliver data between applications that are located on the same network. The network in this case is the WiFi network HI-LINK created by the WiFi module on the Arduino. In the case of the project setup, the Arduino is of course wired to its router, and the connection with the Raspberry Pi is wireless. This connection was very challenging to make, and after figuring out how to do it, there was no time left to try it out (see RASPBERRY PI).

  • WiFi

    vlapp1712/15/2015 at 18:10 0 comments

    WiFi is the wireless networking IEEE standard IEEE 802.11 and it's used across the globe. Many different versions have been named (half of the alphabet has been used already to name these) and an incredible amount of improvements have been proposed since the introduction of the standard in 1997. Our WiFi shield supports the use of several versions: Wireless B, Wireless G and Wireless N. This is stated on the outside of the WiFi module. These versions differ in their transfer rate, frequency range and reach. The transfer rate can depend on the amount of antennas. Wireless N uses MIMO (multiple in, multiple out) and therefore the WiFi module will have multiple antennas. Only one antenna is visible, so the other one or two will be built-in.

    WiFi version

    Year

    Transfer rate (mbps)

    Frequency range (GHz)

    Reach (m)

    Wireless B

    1999

    4.5 (11 theoretically)

    2.4

    35

    Wireless G

    2002

    19 (54 theoretically)

    2.4

    38

    Wireless N

    2009

    130 or less (300-450 theoretically with 2 and 3 antennas, respectively)

    2.4 and 5

    70

View all 10 project logs

Enjoy this project?

Share

Discussions

zakqwy wrote 12/15/2015 at 19:13 point

Neat project. You should ping @Radu Motisan--he's got tons of experience working with air quality sensors of various sorts.

  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates