1 Introduction

Environment monitoring system is a complete data logging system. It automatically measures and records temperature, humidity and other parameters and provides warnings when readings go out of range [1]. Indoor environment monitoring is required to protect the building occupant’s health by providing thermally comfortable and toxicant free environment [2]. We need a system that monitors as well as records the indoor environment data easily. In this chapter, we are discussing about the developed indoor environment monitoring system that monitors and records indoor temperature, humidity, CO and CO2.

Available technologies for sensing these environmental parameters are developed by Onseat HOBO, Spectrum Technologies (Watch Dog weather conditions), TandD, Telaire (Wireless Monitoring Systems), Testo, Log Tag, Measurement Computing Corporation, Monarch Instruments, MSR Electronics GmbH, P3 International, Quality Thermistor, S3 Crop, Sensaphone, Sansatronics, Lascar, ICP, Graphtech, Extech Instruments, Dickson, Dent Instruments, Davis, ACR System Inc, 3M International, and Acumen [3]. The drawback of these available systems is that, both air quality and thermal comfort can not be measured simultaneously. So there is a need to develop an economical system (prototype data logger) which can help in collecting data to analyze the necessary environmental parameters simultaneously.

A prototype data logger has been developed to monitor the environmental parameters. The developed data logger consist (i) sensors module (ii) LCD (iii) Real Time Clock (RTC) (iv) EEPROM and (v) PC serial communication. This data logger is operated through PC using graphical user interface (GUI) in visual basic.

2 Sensors Module

A sensor is a device that measures a physical quantity and converts it into an equivalent analog or digital signal which can be read by an observer or by an instrument [4]. We have used temperature, relative humidity, CO, and CO2 sensors in the developed system.

A gas sensor detects particular gas molecules and produces an electrical signal whose magnitude is proportional to the concentration of the gas [5]. Till date, no gas sensor exists that is 100% selective to only a single gas. A good sensor is sensitive to the measured quantity but less sensitive to other quantities. Available gas sensors are based on five basic principles. These can be electrochemical, infrared, catalytic bead, photo ionization and solid-state [6, 7]. We have selected these sensors because they produce a strong signal for the selected variable especially at high gas concentrations with adequate sensitivity. They have a fast response time, high stability, long life, low cost, low dependency on humidity, low power consumption, and compact size [5]. Four sensors along with their signal conditioning circuit are used to sense the desired parameter such as temperature, humidity, CO, and CO2. Signal conditioning circuit for that sensor needs to be connected externally. In software we can select any of the analog channels. The interface of temperature, humidity, CO, and CO2 sensors with microcontroller PIC 18F4458 is described as follows.

2.1 Temperature Sensor

National semiconductor’s LM 35 IC has been used for sensing the temperature. It is an integrated circuit sensor that can be used to measure temperature with an electrical output proportional to the temperature (in °C). The temperature can be measured more accurately with it than thermistor. The operating and amplification circuit is shown in Fig. 1. The output voltage of IC LM 35 is converted to temperature in °C is given by the following expression [7]

$$Temp.(^\circ {\rm C}) = \left( {{V_{out}} \times 100} \right)/7^\circ {\rm C}$$
Fig. 1
figure 1

Operating and amplification circuitof temperature sensor

The measuring temperature range of the instrument is between 15°C and 70°C.

2.2 Humidity Sensor

The sensor circuit develops a linear voltage vs. RH (relative humidity) output, which is ratio metric to the supply voltage. This means when the supply voltage varies, the sensor output voltage follows the same proportion. It can operate over a range of 4–5.8 V supply. At 5 V supply voltage (at room temperature), corresponding to relative humidity variation from 0% to 100% (noncondensing), the output voltage varies from 0.8 to 3.9 V. The humidity sensor functions with a resolution of up to 0.5% of relative humidity (RH), with a typical current draw of only 200 μA, the HIH4000 series is ideally suited for low drain, battery operated systems.

The operating circuit is shown in Fig. 2. The change in the RH of the surroundings causes an equivalent change in the voltage output. The output is an analog voltage proportional to the supply voltage. Consequently, converting it to relative humidity (RH) requires both the supply and the sensor output voltages (At 25°C) and is given by the following expression [7].

$$RH = \left( {\left( {{V_{out}}/{V_{\sup ply}}} \right) - 0.16} \right)/0.0062$$
Fig. 2
figure 2

Operating circuit of humidity sensor

The output of the humidity sensor is 2.548 V i.e. the relative humidity is 56% at 25°C.

2.3 CO and CO2 Sensor

The operating circuit of CO and CO2 sensors is shown in Fig. 3. The relationship between output voltage and gas concentration is given by the following expression

$$c = {\left[\left(\frac{{({V_C}{R_L}/{V_{OUT}}) - {R_L}}}{{{R_0}}} - 1\right)\frac{1}{K}\right]^2}$$

where, V OUT = output voltage; V C = input voltage, R 0 = electrical resistance of sensor at zero ppm, K = a constant for particular, R L = sensor load resistance [5, 7].

Fig. 3
figure 3

Circuit for CO and CO2 sensor [7]

3 LCD Interface to the Microcontroller

In this work, we are using on-chip analog to digital converter which is on the microcontroller. This analog to digital converter is having the 12 bit resolution with programmable acquisition time. It is sensing the analog signal from the sensor at the variable sampling rate (1 s to 1 h). The sensed value is converted to its digital equivalent. This digital value is displayed on the LCD (liquid crystal display) and is interfaced to the microcontroller [8, 912].

4 Real Time Clock Interface to the Microcontroller

The IC DS1307 operates as a slave device on the I2C bus. Access is obtained by implementing a START condition and providing a device identification code followed by a register address. Subsequent registers can be accessed sequentially until a STOP condition is executed. When VCC falls below 1.25 VBAT, the device terminates an access in progress and resets the device address counter. Inputs to the device will not be recognized at this time to prevent erroneous data from being written to the device from an out of tolerance system. When VCC falls below VBAT, the device switches into a low-current battery backup mode. Upon power up, the device switches from battery to VCC when VCC is greater than VBAT +0.2 V and recognizes inputs when VCC is greater than 1.25 VBAT. We are using IC DS1307 as real time clock which have features such as real-time clock counts in seconds, minutes, hours, day of month, day of week, month, and year with leap year compensation valid up to 2100, 56 Byte, Nonvolatile (NV) RAM for data storage, I2C serial interface, programmable square wave output signal, automatic power fail detect and switch circuitry (consumes less than 500 nA in battery backup mode oscillator running), and temperature range −40°C to 85°C [9, 10]. We are using I2C to interface RTC and EEPROM to the microcontroller. The I2C bus is the most popular of three serial EEPROM protocols. The I2C chips include address pins as an easy way to have multiple chips on a single bus while only using two connections to the microcontroller [9].

5 EEPROM Interface to the Microcontroller

The EEPROM will store the digital value which is coming from analog to digital converter. We will require 52.73 MB of EEPROM if we are sampling all analog channels at the rate of 1 sample/s. We are using the EEPROM AT24C256 (ATMEL). This will store the sample data at different instants [1014].

6 PC Interface Using RS-232 Serial Communication

PIC 18F4458 using MAX-232 is interfaced with PC. IC (MAX-232) used to convert TTL logic level to RS-232 logic level. RS-232 is the serial communication protocol that does not require the clock along with data lines. Two data lines are there one is TX and another is RX for serial communication. MAX-432 has two receivers (converts RS-232 logic level to TTL logic) and two drivers. Separate power supply has been provided because minimum power supply needed is 5 V and MAX-232 consumes a lot of current for operation. External capacitors are required for internal voltage pump to convert TTL logic level to RS-232 level. For battery operated application MAX-232 can be used as level converter instead of MAX-232. It is low supply low power consumption logic converter IC for RS-232 [9, 10, 13].

7 Graphical User Interface

The GUI is one of the important parts for this device as it displays the data from microcontroller for data monitoring and analysis. The design template has to be user friendly for best usage. For this chapter, the main objective is to display data received in graphical form. As transducer detects and translate an analog signal, the data will go through a conversion at the ADC. This digital data will be stored in EEPROM chip with the help of Visual Basic 6.0 software. Since the data is using serial RS232 communication, an initialization needs to be done having baud rate, data bits, parity, stop bit, and the COM port at PC. The baud rate is the number of signal changes per second or transition speed between Mark (negative) and Space (positive) which ranges from 110 to 19,200, data bits is the length of data in bit which has one Least Significant Bit and one Most Significant Bit, the parity bit is an optional bit mainly for bit error checking. It can be odd, even, none Mark, and Space. Stop bit is used to frame up the data bits and usually combined with the start bit. These bits are always represented by a negative voltage and can be 1, 1.5 and 2 stop bits, and COM port is the selection of the available COM port at PC. The commonly used setting to establish a serial RS232 communication is 9600 baud rate, none parity, 8 data bits, 1 stop bit, and COM port 1. This can be done by using the GUI monitoring system where it automatically saves the data received in a notepad. The data saved is the date and time at which the data collected and the data value it self. Figures 4 and 5, represents the graphical user interface and logged data in file respectively [12, 13].

Fig. 4
figure 4

GUI for the data logger

Fig. 5
figure 5

Representations of the logged data in file

8 Schematic of the Data Logger

Figure 6 shows, the full schematic diagram of the data logger for indoor environment. This data logger has four embedded sensor module and other four channels are open to be used for the measurement of other environmental parameters.

Fig. 6
figure 6

Full Schematic of the data logger

9 Software Design of Data Logger

This section includes the discussion on software design for all the modules interfaced with PIC 18F4458. It also explains the functions of software designed for data logger [11].

9.1 Programming Steps for I2C Interface

I2C interface is bi-directional. This is implemented by an “Acknowledge” or “ACK” system allows data to be sent in one direction to one item on the I2C bus, than, that item will “ACK” to indicate the data received. Normally, the master device controls the clock line, SCL. This line dictates the timing of all transfers on the I2C bus. Other devices can manipulate this line, but they can only force the line low. This action means that item on the bus cannot deal with more data in to any device.

9.1.1 Writing to an I2C Chip

The function of writing to the EEPROM is shown here as “Control IN”, which represents putting the EEPROM in an “input” mode. Since we are only sending data to the EEPROM (as shown in Fig. 7), we use “Control IN” byte and later used “Control OUT”. Next, the EEPROM acknowledges this byte. This is shown by the “A” after the byte. It is put on the next line to indicate that this is transmitted by the EEPROM. The Address Byte contains the address of the location of the EEPROM where we want to write data. Since the address is valid, the data is acknowledged by the EEPROM. Finally, we send the data we want to write. The data is then acknowledged by the EEPROM. When that finishes, we send a stop condition to complete the transfer. Remember the “STOP” is represented as the “T” block on the end. Once the EEPROM gets the “STOP” condition it will begin writing to its memory.

Fig. 7
figure 7

Writing the data in I2C chip (Controlling Window)

9.1.2 Reading from an I2C Chip

The transfer will use the “Control IN” byte to load the address into the EEPROM (as shown in Fig. 8). This sends data to the EEPROM which is why we use the control in byte. Once the address is loaded, we want to retrieve the data. So, we send a “Control OUT” byte to indicate to the EEPROM that we want data FROM it. The EEPROM will acknowledge this and then send the data we requested. When we are done getting data, we send a “NACK” to tell the EEPROM that we do not want more data. If we were to send an ACK at this point, we could get the next byte of data from the EEPROM. Since we only want to read one byte, we send a “NACK”.

Fig. 8
figure 8

Reading the data from an I2C chip

9.2 Programming Steps for LCD Interface

Set RS = 0 to send command; Send 0b0010 to data lines three times with a delay of 2 ms; to send a byte on four data lines, send higher nibble first and give a RE pulse of 100 µs at RE; send a set of instruction one after another with a delay of 2 ms between each command to configure various setting as given in instruction set of LCD datasheet [9, 13]; send instruction set again.

Set RS = 1; Send higher nibble at four data lines. Send 100 µs RE pulse; Send lower nibble at data lines. Send RE pulse; Keep track of number of character already displayed on display panel using LCD_count. Go to line 2 or line 1 according to that.

9.3 Programming Steps for Sensor Data Collection

There are four sensor module connected such as temperature, humidity, CO, and CO2. Data is collected by the ADC inbuilt in PIC. ADC provides 12 bit of data after the conversion is completed.

9.3.1 Temperature Sensor Data Collection

Data collection from the temperature sensor needs following actions to be carried out (a) Selecting the analog channel AN0, sampling frequency, and alignment of bits for ADRESH and ADRESL, (b) Vref and power on the ADC module by setting ADCON0, ADCON1 and ADCON2 registers, (c) starting analog to digital conversion by setting ADGO bit high (wait till ADIF flag will not indicate the completion of conversion), and (d) copy of results from ADRESH and ADRESL to variables.

9.3.2 Humidity Sensor Data Collection

Select the AN3 and set other features of ADC as temperature sensor; after completion of conversion copy the result in variable.

9.3.3 CO and CO2 Sensor Data Collection

Data collection from the CO sensor needs following actions to be carried out (a) Selecting the analog channel AN1, sampling frequency, and alignment of bits for ADRESH and ADRESL, (b) Vref and power on the ADC module by setting ADCON0, ADCON1 and ADCON2 registers, (c) starting analog to digital conversion by setting ADGO bit high (wait till ADIF flag will not indicate the completion of conversion), and (d) copy of results from ADRESH and ADRESL to variables.

Now repeat the same process to collect the CO2 data on the channel number AN2.

10 Results and Discussion

Sensors module, EEPROM, RTC, and LCD have been successfully interfaced to the microcontroller. EEPROM is successfully storing the logged data with time and date tag. The sensors data is being displayed on LCD module. A simple GUI has been designed to store a logged data to a text file, so that it can be analyzed further.

11 Conclusions

We have developed a low cost, 12 bit resolution data logger and successfully measured temperature, humidity, and concentration of CO and CO2 gases. The GUI designed gives a lucratively look to the functioning of data logger. Initial results of the data logger are encouraging and we are working on to improve the GUI model as well as the accuracy of data logger.