<sourcesrc=" ./video/finalproject.mp4"type="video/mp4"> your browser dose not support the video tag.
</video>
<h2id="introduction">Introduction</h2>
<p>Final Project is a requirement to pass PreFab Academy, the project has to include at least one input and one output, a microcontroller fabricated by the student and using 2 machines minimum.</p>
<p>My final project is a Carbon monoxide detector which can be used to tell if a certain environment is safe or not. Carbon monoxide is colorless, odorless and tasteless gas, it is toxic to human if the concentration exceeded 35 ppm and may cause death in just 2 hours of exposure if the concentration exceeded 1600 ppm. In USA alone, over 20,000 emergency room visits because of CO poisoning.</p>
<p>Some common sources of CO are:</p>
<ul>
<li>Fireplace.</li>
<li>Vehicle is running inside a garage.</li>
<li>Furnace.</li>
<li>Water heater.</li>
</ul>
<p>Another common source is cigarettes, a person who smokes one pack will commonly have a CO level of about 20 ppm, why this is important ? The affinity between hemoglobin and carbon monoxide is approximately 230 times stronger than the affinity between hemoglobin and oxygen !</p>
<h2id="list-of-components">list of components</h2>
<olstyle="list-style-type: decimal">
<li>MQ-7 CO Sensor.</li>
<li>Sensor Breakout circuit.</li>
<li>Attiny44A.</li>
<li>LED.</li>
<li>100 Ohms Resistor.</li>
<li>x2 10K Ohms Resistor.</li>
<li>1k Ohms Resistor.</li>
<li>x4 10 micro farads capacitors.</li>
<li>1 micro farads capacitors.</li>
<li>Mosfet or NPN transistor.</li>
<li>5v Regulator.</li>
</ol>
<h2id="iteration-zero">Iteration zero</h2>
<p>In this iteration, I have started designing the body of the detector, I have not designed the PCB or test the sensor in this iteration. I was given about 20 minutes by the instructor to make a shape which looks like the final product so I have used cartoon cup and cut 3 holes one for the sensor and two for LEDs.</p>
<divclass="figure">
<imgsrc="images/project2.jpg"/>
</div>
<h2id="iteration-1">Iteration 1</h2>
<p>After iteration zero, I have started designing the body using FreeCad, designing and milling the PCB using kokopelli, soldering the components and finishing the first prototype.</p>
<h4id="cad">CAD</h4>
<p>The design is basically a cone shape. In iteration zero I have cut two holes for two LEDs, I was thinking about LEDs as indicators one for the environment and the other for telling the user if the device is ON or OFF, but in this iteration I have used only one for both purposes like the LED will be for 1 second and then the it will start blinking depending on the cleanness of the environment.</p>
<p>I have also added a cut for the ON-OFF switch.</p>
<p>The following picture shows the first iteration CAD</p>
<divclass="figure">
<imgsrc="images/project3.png"/>
</div>
<h4id="pcb-design">PCB Design</h4>
<divclass="figure">
<imgsrc="images/coSensor.png"/>
</div>
<p>Battery is 9v so I am using the regulator to change and settle the voltage at 5v. The sensor has two outputs, one digital and one analog. The digital output gives 1 if the ppm reading is very high and close to the threshold. Analog output varies and depends on the ppm readings. The digital pin is connected to PA2 and the analog pin is connected to PA3 which has ADC. LED is connected to PB1.</p>
<p>The following pictures are the real size of the traces and the cut.</p>
<spanclass="kw">if</span> (ADC <<spanclass="dv">9</span>){ <spanclass="co">// 9 is just a value for testing</span>
clearbit(PORTB,PB1);
}<spanclass="kw">else</span>{
setbit(PORTB,PB1);
_delay_ms(<spanclass="dv">500</span>);
clearbit(PORTB,PB1);
_delay_ms(<spanclass="dv">500</span>);
}
}
}</code></pre></div>
<h4id="design-problems">Design Problems</h4>
<p>I have had a major issue with the design. The parts could not be fitted inside the body also the switch is very big ! so I have moved on to iteration 2.</p>
<divclass="figure">
<imgsrc="images/project4.jpg"/>
</div>
<h2id="iteration-2">Iteration 2</h2>
<p>In this iteration, I have not made a major change in the design. I have increased the size, changed the place of the switch and made a place for the battery also I have designed the top cover and decided to use 3 screws to fix the cover with the body.</p>
<p>At the beginning, I thought that the sensor works on 5v, but I discovered that the sensor works in two cycles, heating and measuring. Heating phase requires Vcc to be 5v and lasts for 60 seconds, the purpose of this phase is to clean the sensor from any absorbed gases. Measuring phase requires Vcc to be 1.4v and lasts for 90 seconds. 1.4v is achieved by using pulse-width modulation. During measuring phase the sensor absorbs CO and gives meaningful data.</p>
<p>In the first time I tried the sensor, it gave me wrong measurements, I looked up in the data sheet and figured out that the sensor needs to be calibrated. There are two different ways of calibration, Rough calibration and precise calibration. Rough calibration is very easy and simple, just run the heating and measuring cycles in a clean environment for at least 10 hours, but this way will not give precise measurement. Precise calibration requires another calibrated CO sensor, flue gas, syringe and jar. I chose rough calibration so I won't go through the details of the precise calibration.</p>
<h4id="cad-design">Cad Design</h4>
<p>The are two changes in the design, the place of the battery is flipped so that the battery will be inside the body and the power switch has been changed from the body to the cover to allow a space inside the body for the battery</p>
<divclass="figure">
<imgsrc="images/cad.jpg"/>
</div>
<p>The final design looks like</p>
<divclass="figure">
<imgsrc="images/cad2.jpg"/>
</div>
<divclass="figure">
<imgsrc="images/cad3.jpg"/>
</div>
<h4id="pcb-design-1">PCB Design</h4>
<divclass="figure">
<imgsrc="images/cosensor.png"/>
</div>
<divclass="figure">
<imgsrc="images/cosensornew.png"/>
</div>
<divclass="figure">
<imgsrc="images/cosensorcut.png"/>
</div>
<p>Source code of the design can be found <ahref="http://download1079.mediafire.com/z8dj23nzbxvg/8nyoikd8zn5kf25/cosensornew.cad">here</a></p>
ADCSRA = ADCSRA |= (<spanclass="dv">1</span><< ADSC); <spanclass="co">// Start the ADC</span>
<spanclass="co">//ADC value is based on the rough calibration, measurements may not be 100% accurate.</span>
<spanclass="kw">if</span>(ADC <= <spanclass="dv">75</span>){ <spanclass="co">// 75 is the equivelant of 0.34v which the sensor analog output at clean environment.</span>
setbit(PORTB,PB1); <spanclass="co">// LED is ON.</span>
}<spanclass="kw">else</span>{
clearbit(PORTB,PB1);
}
}
<spanclass="dt">void</span> heating(){
TCCR1A = <spanclass="dv">0</span>;
TCCR1B = <spanclass="dv">0</span>; <spanclass="co">// No PWM</span>
<h4id="problems-and-difficulties">Problems and Difficulties</h4>
<ul>
<li><strong>PWM</strong></li>
</ul>
<p>I have used PWM in Arduino, it was just one line of code but here I have to use timers and set up registers and prescalars. I spent hours trying to get the 1.4v using the PWM. At last I figured out that I must define the prescalar even if I don't want to use it.</p>
<ul>
<li><strong>Bad soldering</strong></li>
</ul>
<p>The sensor was not working because of bad soldering.</p>
<divclass="figure">
<imgsrc="images/1.jpg"/>
</div>
<ul>
<li><strong>Calibration</strong></li>
</ul>
<p>Before I bought the sensor, I thought that it ready to use and just need power. I never thought about calibration which takes time and requires some tools. From this problem, I learned that I have to read and study anything before buying and using it.</p>