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

-m adding the video

parent 06f03b55
No related branches found
No related tags found
No related merge requests found
Pipeline #
Showing
with 356 additions and 6 deletions
......@@ -47,6 +47,12 @@ code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Inf
</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>
......@@ -59,6 +65,19 @@ code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Inf
</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">
......@@ -153,9 +172,161 @@ _delay_ms(<span class="dv">500</span>);
</div>
<h2 id="iteration-2">Iteration 2</h2>
<p>In this iteration, I have not made 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>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>
<h2 id="testing">Testing</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>
# Final Project
## Slide
PUT PICTURE OF BOARD
## Video
<video width="1280" height="720" controls> <source src=" ./video/finalproject.mp4" type="video/mp4">
your browser dose not support the video tag.
</video>
## Introduction
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.
......@@ -17,6 +27,18 @@ Another common source is cigarettes, a person who smokes one pack will commonly
## list of components
1. MQ-7 CO Sensor.
1. Sensor Breakout circuit.
1. Attiny44A.
1. LED.
1. 100 Ohms Resistor.
1. x2 10K Ohms Resistor.
1. 1k Ohms Resistor.
1. x4 10 micro farads capacitors.
1. 1 micro farads capacitors.
1. Mosfet or NPN transistor.
1. 5v Regulator.
## Iteration zero
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.
......@@ -126,7 +148,7 @@ I have had a major issue with the design. The parts could not be fitted inside t
## Iteration 2
In this iteration, I have not made 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.
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.
![](images/project5.png)
......@@ -135,4 +157,154 @@ In this iteration, I have not made made a major change in the design. I have inc
## Final iteration
## Testing
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.
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.
#### Cad Design
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
![](images/cad.jpg)
The final design looks like
![](images/cad2.jpg)
![](images/cad3.jpg)
#### PCB Design
![](images/cosensor.png)
![](images/cosensornew.png)
![](images/cosensorcut.png)
Source code of the design can be found [here](http://download1079.mediafire.com/z8dj23nzbxvg/8nyoikd8zn5kf25/cosensornew.cad)
#### Code
```c
/*
This code was created by Ahmad Fares on 10-Dec-2017
The purpose of this is program is to read a CO sensor analog signal
and make an action.
MIT License
*/
#define setbit(register, bit) (register) |= (1 << (bit))
#define clearbit(register, bit) (register) &= ~(1 << (bit))
#define testbit(register, bit) (register) & (1 << (bit))
#define togglebit(register,bit) (register) ^= (1<<bit)
#define F_CPU 1000000UL
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
int counter = 0;
void setADC(){ //Set up the Analog to digital converter
ADMUX = (0 << REFS1)|(0 << REFS0)|(0 << MUX5)|(0 << MUX4)|(0 << MUX3)|(0 << MUX2)|(1 << MUX1)|(0 << MUX0); //vcc as reference, PA2
ADCSRB &=~(1<<ADTS2)|(1<<ADTS1)|(1<<ADTS0); //Right adject ADLAR is zero, Free running mode
ADCSRA = (1 << ADEN)|(1 << ADPS2)|(0 << ADPS1)|(0 << ADPS0); // ADC enabled, prescaler /16
}
void setTimer(){ //set up Timer0
TCCR0A = 0;
TCCR0B = 0;
OCR0A = 61;
setbit(TCCR0A, WGM01); //CTC
sei();
setbit(TIMSK0,OCIE0A); // enable CTC interrupt when TCNT0 = OCR0A
setbit(TCCR0B,CS01);
setbit(TCCR0B,CS00); //These 2 registers set prescalar to 1/64 and start the counter.
}
void measure(){
//Set up PWM.
TCCR1A = 0;
TCCR1B = 0;
setADC();
DDRA |= (1<<PA5);
clearbit(PORTA,PA5);
TCCR1A |= (1<<WGM11) | (1<<WGM10) | (1<<COM1A1) | (1<<COM1B1); //fast PWM non-inverting mode.
TCCR1B |= (1<<WGM12)|(1<<CS10); //No prescalar.
OCR1B = 65550 - 18350; // 1.4v
ADCSRA = ADCSRA |= (1 << ADSC); // Start the ADC
//ADC value is based on the rough calibration, measurements may not be 100% accurate.
if(ADC <= 75){ // 75 is the equivelant of 0.34v which the sensor analog output at clean environment.
setbit(PORTB,PB1); // LED is ON.
}else{
clearbit(PORTB,PB1);
}
}
void heating(){
TCCR1A = 0;
TCCR1B = 0; // No PWM
clearbit(DDRA,PA5);
setbit(PORTA,PA5); //Write 5v
}
ISR(TIM0_COMPA_vect){
counter++;
//2560 will allow the heating for 60 seconds.
//2560 is calculated by experiment.
if(counter <= 2560){
heating();
}else if(counter > 2560 && counter <= 6400){
//6400 - 2560 = 3840 which is equivalent to 90 seconds.
measure();
}else if(counter == 6401){
counter = 0;
}
}
int main (void) {
counter = 0;
setbit(DDRA, PA5); //PA5 output, PWM Pin
clearbit(DDRA, PA2); //PA2 input, ADC Pin
setbit(DDRB,PB1); // PB1 output, LED Pin
clearbit(PORTB,PB1);
setTimer();
while(1) {
}
}
```
#### Problems and Difficulties
- **PWM**
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.
- **Bad soldering**
The sensor was not working because of bad soldering.
![](images/1.jpg)
- **Calibration**
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.
<?xml version="1.0" encoding="UTF-8"?>
<comment version="3.0">
<caption/>
<note>charset=&quot;InvalidCharsetId&quot; 0,8,-6 FN=0 FB = 0 me = 0x1 ct = 6 lidx=335.15 FM0 FC111111111:zzzzzz1 914f 007804409245e613e14014c0 bac1021e3 37 4135729e33f 0 0 0 0 0 0 0 0333417d4138 1d 3 232a417d4138 1c 3 2321417d4138 1f 0 2318417d4138 1f82 231b417d4138 1f 3 231e417d4138 1f 3 2321417d4138 1d 3 231e417d4138 1d 3 231e417d4138 1d 3 2 14f 14f 14f 14f 13f 13f 13f 13f 179 179 179 179 172 172 172 172 14a 14a 14a 14a 13d 13d 13d 13d 171 171 171 171 1a5 1a5 1a5 1a5 133 133 133 133138813881388138813881388138813881388138813881388138813881388138813881388138813881388138813881388138813881388138813881388138813881388138813881388138813881388138813881388138813881388138813881388138813881388138813881388138813881388138813881388138813881388138813881388138813881388138813881388138813881388138813881388138813881388138813881388138813881388138813881388138813881388138813881388138813881388138813881388138813881388138813881388138813881388138813881388138813881388138813881388138813881388138813881388138813881388138813881388138813881388138813881388138813881388138813881388</note>
<place/>
<categories/>
</comment>
participants/fares.ahmad/final-project/images/1.jpg

63.6 KiB

participants/fares.ahmad/final-project/images/cad.jpg

30.8 KiB

participants/fares.ahmad/final-project/images/cad2.jpg

24.9 KiB

participants/fares.ahmad/final-project/images/cad3.jpg

21.7 KiB

participants/fares.ahmad/final-project/images/cosensor.png

24.6 KiB

participants/fares.ahmad/final-project/images/cosensorcut.png

6.67 KiB

participants/fares.ahmad/final-project/images/cosensornew.png

8.36 KiB

File added
......@@ -11,7 +11,7 @@
<body>
<h2 id="introduction">Introduction</h2>
<p>Welcome to Ahmad Fares documentation of the PreFab academy. PreFab 2018 started on 19-Nov-2017, Mr. Fransisco Sanchez was the instructor, he introduced us to the concept of the Fab Labs and why Fab Labs exist.</p>
<p>A Fab Lab is a place which helps anyone who got an idea to make a prototype and transform his idea into real projects.</p>
<p>A Fab Lab is a place which helps anyone who got an idea to make a prototype and transform his idea into a real project.</p>
<p>I am a volunteer in the Crown Prince Foundation and will help building the first Fab Lab in Amman.</p>
</body>
</html>
......@@ -2,6 +2,6 @@
Welcome to Ahmad Fares documentation of the PreFab academy. PreFab 2018 started on 19-Nov-2017, Mr. Fransisco Sanchez was the instructor, he introduced us to the concept of the Fab Labs and why Fab Labs exist.
A Fab Lab is a place which helps anyone who got an idea to make a prototype and transform his idea into real projects.
A Fab Lab is a place which helps anyone who got an idea to make a prototype and transform his idea into a real project.
I am a volunteer in the Crown Prince Foundation and will help building the first Fab Lab in Amman.
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