Skip to content
Snippets Groups Projects
Commit e7155e3c authored by Ahmad Fares's avatar Ahmad Fares
Browse files

-m finishing the documentation

parent 647138a1
No related branches found
No related tags found
No related merge requests found
Pipeline #
......@@ -13,7 +13,7 @@ pandoc -s -t html -c styles.css shopbot/shopbot.md -o shopbot/shopbot.html
pandoc -s -t html -c styles.css vinyl-cutter/vinyl-cutter.md -o vinyl-cutter/vinyl-cutter.html
pandoc -s -t html -c styles.css principles.md -o principles.html
pandoc -s -t html -c styles.css C-programming/C-programming.md -o C-programming/C-programming.html
pandoc -s -t html -c styles.css final-project/final-project.md -o final-project/final-Project.html
pandoc -s -t html -c styles.css final-project/final-project.md -o final-project/final-project.html
echo "All files converted to html"
echo "Pull"
......
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta name="generator" content="pandoc" />
<title></title>
<style type="text/css">code{white-space: pre;}</style>
<style type="text/css">
div.sourceCode { overflow-x: auto; }
table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode {
margin: 0; padding: 0; vertical-align: baseline; border: none; }
table.sourceCode { width: 100%; line-height: 100%; }
td.lineNumbers { text-align: right; padding-right: 4px; padding-left: 4px; color: #aaaaaa; border-right: 1px solid #aaaaaa; }
td.sourceCode { padding-left: 5px; }
code > span.kw { color: #007020; font-weight: bold; } /* Keyword */
code > span.dt { color: #902000; } /* DataType */
code > span.dv { color: #40a070; } /* DecVal */
code > span.bn { color: #40a070; } /* BaseN */
code > span.fl { color: #40a070; } /* Float */
code > span.ch { color: #4070a0; } /* Char */
code > span.st { color: #4070a0; } /* String */
code > span.co { color: #60a0b0; font-style: italic; } /* Comment */
code > span.ot { color: #007020; } /* Other */
code > span.al { color: #ff0000; font-weight: bold; } /* Alert */
code > span.fu { color: #06287e; } /* Function */
code > span.er { color: #ff0000; font-weight: bold; } /* Error */
code > span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
code > span.cn { color: #880000; } /* Constant */
code > span.sc { color: #4070a0; } /* SpecialChar */
code > span.vs { color: #4070a0; } /* VerbatimString */
code > span.ss { color: #bb6688; } /* SpecialString */
code > span.im { } /* Import */
code > span.va { color: #19177c; } /* Variable */
code > span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code > span.op { color: #666666; } /* Operator */
code > span.bu { } /* BuiltIn */
code > span.ex { } /* Extension */
code > span.pp { color: #bc7a00; } /* Preprocessor */
code > span.at { color: #7d9029; } /* Attribute */
code > span.do { color: #ba2121; font-style: italic; } /* Documentation */
code > span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code > span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
</style>
<link rel="stylesheet" href="styles.css" type="text/css" />
</head>
<body>
<h1 id="final-project">Final Project</h1>
<h2 id="slide">Slide</h2>
<p>PUT PICTURE OF BOARD</p>
<h2 id="video">Video</h2>
<video width="1280" height="720" controls>
<source src=" ./video/finalproject.mp4" type="video/mp4"> your browser dose not support the video tag.
</video>
<h2 id="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>
<h2 id="list-of-components">list of components</h2>
<ol style="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>
<h2 id="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>
<div class="figure">
<img src="images/project2.jpg" />
</div>
<h2 id="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>
<h4 id="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>
<div class="figure">
<img src="images/project3.png" />
</div>
<h4 id="pcb-design">PCB Design</h4>
<div class="figure">
<img src="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>
<p><img src="images/coSensorTrace.png" /> <img src="images/coSensorCut.png" /></p>
<p>source code of the pcb can be found <a href="http://download1643.mediafire.com/561s7l3db6bg/g94brua4in4306n/coSensor.cad">here</a>.</p>
<h4 id="code">Code</h4>
<p>The following is just for testing the sensor, it will be slightly modified for real uses.</p>
<div class="sourceCode"><pre class="sourceCode c"><code class="sourceCode c"><span class="co">/*</span>
<span class="co">This program was created by Ahmad Fares on Dec-2017.</span>
<span class="co">The purpose of this program is to read CO sensor values.</span>
<span class="co">MIT License</span>
<span class="co">*/</span>
<span class="ot">#define F_CPU 1000000UL</span>
<span class="ot">#define setbit(register, bit) (register) |= (1 &lt;&lt; (bit))</span>
<span class="ot">#define clearbit(register, bit) (register) &amp;= ~(1 &lt;&lt; (bit))</span>
<span class="ot">#define testbit(register, bit) (register) &amp; (1 &lt;&lt; (bit))</span>
<span class="ot">#include &lt;avr/interrupt.h&gt;</span>
<span class="ot">#include &lt;avr/io.h&gt;</span>
<span class="ot">#include &lt;util/delay.h&gt;</span>
<span class="dt">int</span> main (<span class="dt">void</span>){
setbit(DDRB, PB1); <span class="co">// set PB1 as output in DDRB.</span>
clearbit(DDRA, PA2); <span class="co">// set PA2 as input in DDRB.</span>
sei(); <span class="co">// activate interrupts globally</span>
setbit(DDRA, PA3);
CLKPR = (<span class="dv">1</span> &lt;&lt; CLKPCE);
CLKPR = (<span class="dv">0</span> &lt;&lt; CLKPS3) | (<span class="dv">0</span> &lt;&lt; CLKPS2) | (<span class="dv">0</span> &lt;&lt; CLKPS1) | (<span class="dv">0</span> &lt;&lt; CLKPS0);
<span class="co">//</span>
<span class="co">// init A/D</span>
<span class="co">//</span>
ADMUX = (<span class="dv">0</span> &lt;&lt; REFS1) | (<span class="dv">0</span> &lt;&lt; REFS0) <span class="co">// Vcc ref</span>
| (<span class="dv">0</span> &lt;&lt; ADLAR) <span class="co">// right adjust</span>
| (<span class="dv">0</span> &lt;&lt; MUX5)| (<span class="dv">0</span> &lt;&lt; MUX4) | (<span class="dv">0</span> &lt;&lt; MUX3) | (<span class="dv">0</span> &lt;&lt; MUX2) | (<span class="dv">1</span> &lt;&lt; MUX1) | (<span class="dv">1</span> &lt;&lt; MUX0); <span class="co">// ADC3</span>
ADCSRA = (<span class="dv">1</span> &lt;&lt; ADEN) <span class="co">// enable</span>
| (<span class="dv">1</span> &lt;&lt; ADPS2) | (<span class="dv">0</span> &lt;&lt; ADPS1) | (<span class="dv">0</span> &lt;&lt; ADPS0); <span class="co">// prescaler /128</span>
<span class="kw">while</span> (<span class="dv">1</span>) {
ADCSRA |= (<span class="dv">1</span> &lt;&lt; ADSC);
<span class="kw">if</span> (ADC &lt; <span class="dv">9</span>){ <span class="co">// 9 is just a value for testing</span>
clearbit(PORTB,PB1);
}<span class="kw">else</span>{
setbit(PORTB,PB1);
_delay_ms(<span class="dv">500</span>);
clearbit(PORTB,PB1);
_delay_ms(<span class="dv">500</span>);
}
}
}</code></pre></div>
<h4 id="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>
<div class="figure">
<img src="images/project4.jpg" />
</div>
<h2 id="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><img src="images/project5.png" /> <img src="images/project6.png" /></p>
<h2 id="final-iteration">Final iteration</h2>
<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>
<h4 id="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>
<div class="figure">
<img src="images/cad.jpg" />
</div>
<p>The final design looks like</p>
<div class="figure">
<img src="images/cad2.jpg" />
</div>
<div class="figure">
<img src="images/cad3.jpg" />
</div>
<h4 id="pcb-design-1">PCB Design</h4>
<div class="figure">
<img src="images/cosensor.png" />
</div>
<div class="figure">
<img src="images/cosensornew.png" />
</div>
<div class="figure">
<img src="images/cosensorcut.png" />
</div>
<p>Source code of the design can be found <a href="http://download1079.mediafire.com/z8dj23nzbxvg/8nyoikd8zn5kf25/cosensornew.cad">here</a></p>
<h4 id="code-1">Code</h4>
<div class="sourceCode"><pre class="sourceCode c"><code class="sourceCode c">
<span class="co">/*</span>
<span class="co">This code was created by Ahmad Fares on 10-Dec-2017</span>
<span class="co">The purpose of this is program is to read a CO sensor analog signal</span>
<span class="co">and make an action.</span>
<span class="co">MIT License</span>
<span class="co">*/</span>
<span class="ot">#define setbit(register, bit) (register) |= (1 &lt;&lt; (bit))</span>
<span class="ot">#define clearbit(register, bit) (register) &amp;= ~(1 &lt;&lt; (bit))</span>
<span class="ot">#define testbit(register, bit) (register) &amp; (1 &lt;&lt; (bit))</span>
<span class="ot">#define togglebit(register,bit) (register) ^= (1&lt;&lt;bit)</span>
<span class="ot">#define F_CPU 1000000UL</span>
<span class="ot">#include &lt;avr/io.h&gt;</span>
<span class="ot">#include &lt;util/delay.h&gt;</span>
<span class="ot">#include &lt;avr/interrupt.h&gt;</span>
<span class="dt">int</span> counter = <span class="dv">0</span>;
<span class="dt">void</span> setADC(){ <span class="co">//Set up the Analog to digital converter</span>
ADMUX = (<span class="dv">0</span> &lt;&lt; REFS1)|(<span class="dv">0</span> &lt;&lt; REFS0)|(<span class="dv">0</span> &lt;&lt; MUX5)|(<span class="dv">0</span> &lt;&lt; MUX4)|(<span class="dv">0</span> &lt;&lt; MUX3)|(<span class="dv">0</span> &lt;&lt; MUX2)|(<span class="dv">1</span> &lt;&lt; MUX1)|(<span class="dv">0</span> &lt;&lt; MUX0); <span class="co">//vcc as reference, PA2</span>
ADCSRB &amp;=~(<span class="dv">1</span>&lt;&lt;ADTS2)|(<span class="dv">1</span>&lt;&lt;ADTS1)|(<span class="dv">1</span>&lt;&lt;ADTS0); <span class="co">//Right adject ADLAR is zero, Free running mode</span>
ADCSRA = (<span class="dv">1</span> &lt;&lt; ADEN)|(<span class="dv">1</span> &lt;&lt; ADPS2)|(<span class="dv">0</span> &lt;&lt; ADPS1)|(<span class="dv">0</span> &lt;&lt; ADPS0); <span class="co">// ADC enabled, prescaler /16</span>
}
<span class="dt">void</span> setTimer(){ <span class="co">//set up Timer0</span>
TCCR0A = <span class="dv">0</span>;
TCCR0B = <span class="dv">0</span>;
OCR0A = <span class="dv">61</span>;
setbit(TCCR0A, WGM01); <span class="co">//CTC</span>
sei();
setbit(TIMSK0,OCIE0A); <span class="co">// enable CTC interrupt when TCNT0 = OCR0A</span>
setbit(TCCR0B,CS01);
setbit(TCCR0B,CS00); <span class="co">//These 2 registers set prescalar to 1/64 and start the counter.</span>
}
<span class="dt">void</span> measure(){
<span class="co">//Set up PWM.</span>
TCCR1A = <span class="dv">0</span>;
TCCR1B = <span class="dv">0</span>;
setADC();
DDRA |= (<span class="dv">1</span>&lt;&lt;PA5);
clearbit(PORTA,PA5);
TCCR1A |= (<span class="dv">1</span>&lt;&lt;WGM11) | (<span class="dv">1</span>&lt;&lt;WGM10) | (<span class="dv">1</span>&lt;&lt;COM1A1) | (<span class="dv">1</span>&lt;&lt;COM1B1); <span class="co">//fast PWM non-inverting mode.</span>
TCCR1B |= (<span class="dv">1</span>&lt;&lt;WGM12)|(<span class="dv">1</span>&lt;&lt;CS10); <span class="co">//No prescalar.</span>
OCR1B = <span class="dv">65550</span> - <span class="dv">18350</span>; <span class="co">// 1.4v</span>
ADCSRA = ADCSRA |= (<span class="dv">1</span> &lt;&lt; ADSC); <span class="co">// Start the ADC</span>
<span class="co">//ADC value is based on the rough calibration, measurements may not be 100% accurate.</span>
<span class="kw">if</span>(ADC &lt;= <span class="dv">75</span>){ <span class="co">// 75 is the equivelant of 0.34v which the sensor analog output at clean environment.</span>
setbit(PORTB,PB1); <span class="co">// LED is ON.</span>
}<span class="kw">else</span>{
clearbit(PORTB,PB1);
}
}
<span class="dt">void</span> heating(){
TCCR1A = <span class="dv">0</span>;
TCCR1B = <span class="dv">0</span>; <span class="co">// No PWM</span>
clearbit(DDRA,PA5);
setbit(PORTA,PA5); <span class="co">//Write 5v</span>
}
ISR(TIM0_COMPA_vect){
counter++;
<span class="co">//2560 will allow the heating for 60 seconds.</span>
<span class="co">//2560 is calculated by experiment.</span>
<span class="kw">if</span>(counter &lt;= <span class="dv">2560</span>){
heating();
}<span class="kw">else</span> <span class="kw">if</span>(counter &gt; <span class="dv">2560</span> &amp;&amp; counter &lt;= <span class="dv">6400</span>){
<span class="co">//6400 - 2560 = 3840 which is equivalent to 90 seconds.</span>
measure();
}<span class="kw">else</span> <span class="kw">if</span>(counter == <span class="dv">6401</span>){
counter = <span class="dv">0</span>;
}
}
<span class="dt">int</span> main (<span class="dt">void</span>) {
counter = <span class="dv">0</span>;
setbit(DDRA, PA5); <span class="co">//PA5 output, PWM Pin</span>
clearbit(DDRA, PA2); <span class="co">//PA2 input, ADC Pin</span>
setbit(DDRB,PB1); <span class="co">// PB1 output, LED Pin</span>
clearbit(PORTB,PB1);
setTimer();
<span class="kw">while</span>(<span class="dv">1</span>) {
}
}</code></pre></div>
<h4 id="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>
<div class="figure">
<img src="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>
</body>
</html>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment