2. System Components¶
CO_SAFE is a smart Carbon Monoxide lifesaver. It consists of two units, the first is Carbon Monoxide Monitoring unit (COM) and the second is Exhaust Fan Control unit (EFC). COM will measure CO levels in air inside and produce necessary action to inform people about potential risks. Also will communicate with EFC to operate and replace air inside.
2.1. CO Monitoring Unit (COM)¶
The COMU consists of the following:
Control unit
Microcontroller (ATMEGA328): analyzes data from input devices and takes the necessary actions and displays correct messages.
Input devices
CO sensor module (MQ-7): measures CO level in air.
Push buttons: the interface through which user controls the system.
Output devices
LCD (16x2): displays CO level and customized messages.
LEDs (white, orange, red): displays CO level (visual alarm).
Buzzer: activated at high CO levels (audio alarm).
LED (red): shows if unit is connected to power.
Communication Devices
Transceiver (NRF24L01+ 2.4GHz): communicates with exhaust fan control unit.
2.2. Exhaust Fan Control Unit (EFC)¶
The EFCU consists of the following:
Control devices
Microcontroller (ATMEGA328): analyzes data from input devices and takes the necessary actions.
Output devices
Control relay: controls the exhaust fan.
LED (green/red): shows the status of exhaust fan.
LED (red): shows if unit is connected to power.
Communication Devices
Transceiver (NRF24L01+ 2.4GHz): communicates with CO monitoring unit.
2.3. Components Overview¶
In this part I will explain some of components that were not introduced in previous weeks, and refer to some of those already used. For flexibility, I used the ATtiny44 Development Board, ATmega328P DIP and breadboard to test each component and module individually. In the final project I will use ATmega328P microcontrollers in both units.
2.3.1. Control Unit: ATmega328P Microcontroller¶
File Download¶
ATmega328P datasheet
ATmega328P test code files
Both COMU and EFCU will be based in ATmega328P. Compared to ATtiny44, the ATMEGA328P will provide more I/O pins and larger memory (FLASH, EEPROM, SRAM) which will be required in my project.
ATmega328P | ATtiny44A | |
---|---|---|
Programmable I/O | 23 | 12 |
FLASH | 32K bytes | 4K bytes |
EEPROM | 1K bytes | 256 bytes |
SRAM | 2K bytes | 256 bytes |
Speed range | 0-16 MHz | 0-20 MHz |
Microcontrollers in both units will be clocked internally at 8MHz, and the package for both is 32-lead TQFP. To select clock source and other settings, I used the low fuse byte of the ATmega328P.
CKDIV8 = 1: System clock prescaling 1:1 (CKDIV8 unprogrammed).
CKOUT = 1: Output system clock on CLKO pin (PB0) disabled (unprogrammed).
SUT1:0 = 10 6 CK start-up time from power-down and power-save, 14 CK + 65 ms additional delay from reset.
CKSEL3:0 = 0010 8.0 MHz calibrated internal RC oscillator.
CKDIV8 | CKOUT | SUT1:0 | CKSEL3:0 | Binary | Hexadeciaml |
---|---|---|---|---|---|
1 | 1 | 10 | 0010 | 11100010 | 0xE2 |
I edited the Makefile to work on ATmega328P and wrote a test code to blink a LED connected to PB0 (Ton = 1000 ms, Toff = 1000 ms). The lfuse can be programmed using the command “program-avr-fuses”, and to program the flash use “program-avr” command.
2.3.2. Display Module: 16x2 LCD¶
File Download¶
A standard 16 characters by 2 lines LCD module. It could be driven in 8-bit mode (using D7:0 bits), or in 4-bit mode (using D7:4 bits). In addition to data bus, two command bits (RS and E) should be driven. If 4-bit mode is used, only 6 pins are required from the microcontroller to drive the LCD.
The LCD module will be used in COMU to display CO levels and other customized messages. The code driving the LCD has a C file and a header file where function and pin assignments are defined. The code interfaces the LCD to users through 7 functions:
Lcd4_Init()
Lcd4_Clear()
Lcd4_Set_Cursor(lineN, charN)
Lcd4_Write_String(string)
Lcd4_Write_Char(char)
Lcd4_Shift_Right()
Lcd4_Shift_Left()
This code is built on the work found in Interfacing LCD with Atmega32 Microcontroller using Atmel Studio.
2.3.3. Carbon Monoxide Sensor: MQ-7 Module¶
File Download¶
MQ-7 datasheet
CO sensor test code files
The MQ-7 is a low cost sensor used to detect CO concentrations [PPM] in air. The sensitive material of MQ-7 is SnO2, which has low conductivity in clean air. As CO concentrations rise in air, the sensitive material conductivity increases.
To detect CO levels, the MQ-7 should be heated using 5 VDC for 60s (high heating), then using 1.4 VDC for 90s (low heating). The reading through R2 (RL in datasheet) is available at the end of low heating cycle. The driving voltage (Vc) is 5 VDC. Note that the heating cycle voltage (Vh) could be supplied using DC or AC source. In the test circuit the heater voltages are generated by a PWM signal to N-channel MOSFET supplied with 12 VDC. For 5 VDC the duty cycle is 107 (out of 255), and for 1.4 VDC the duty cycle is 30 (out of 255).
Before using the sensor it should preheated for 48 hours (using high-low cycle) and measurement in 100 PPM CO controlled environment recorded. This reading will be used to calculate Ro value which is needed to find the corresponding CO concentration.
I couldn’t manage to have 100 PPM CO controlled environment, so I measured the reading indoor in a well ventilated room away from any stove or pollutants. The VL reading was stable at 355 (out of 1023).
Applying Ohm’s Law to the circuit:
Rs = RL x (Vc - VL) / VL
Having VL = 355:
Rs = 10000 x (1023 - 355) / 355 Rs = 18817 Ohms
The relation between PPM and Rs/Ro is linear in log-log scale. Using the points p1(200, 0.6) and p2(100, 1) on the CO chart we can conclude that
PPM = [29.786 / (Rs/Ro)] ^ (1 / 0.737)
According to United States Environmental Protection Agency, the “Average levels in homes without gas stoves vary from 0.5 to 5 parts per million (ppm). Levels near properly adjusted gas stoves are often 5 to 15 ppm and those near poorly adjusted stoves may be 30 ppm or higher.” Source. For safety reason I will assume that my reading (355 out of 1023) corresponds to 20 PPM (somewhere between properly and poorly adjusted stoves!). Applying in PPM equation:
20 = [29.786 / (18817 / Ro)] ^ (1 / 0.737)
We find that Ro = 5746 Ohms.
To summarize, to calculate CO concentration in PPM:
Step 1: Measure VL value at the end of the low heating value using the ADC in microcontroller.
Step 2: Calculate Rs using the equation Rs = RL x (Vc - VL) / VL, where RL = 10 kOhms and Vc = 1023 (ADC resolution).
Step 3: Calculate PPM using the equation PPM = [29.786 / (Rs/Ro)] ^ (1 / 0.737)
For example, for the VL reading 450 (out of 1023):
Rs = 10000 x (1023 - 450) / 450
Rs = 12733 Ohms
PPM = [29.786 / (12733 / 5746)] ^ (1 / 0.737)
PPM = 34 PPM
The test circuit of CO sensor used the schematics given in Display Module: 16x2 LCD and Carbon Monoxide Sensor: MQ-7 Module sections.