Final Project

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.

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.

Some common sources of CO are:

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 !

list of components

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.

Iteration 1

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.

CAD

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.

I have also added a cut for the ON-OFF switch.

The following picture shows the first iteration CAD

PCB Design

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.

The following pictures are the real size of the traces and the cut.

source code of the pcb can be found here.

Code

The following is just for testing the sensor, it will be slightly modified for real uses.

/*
This program was created by Ahmad Fares on Dec-2017.
The purpose of this program is to read CO sensor values.
MIT License
*/

#define F_CPU 1000000UL
#define setbit(register, bit)   (register) |= (1 << (bit))
#define clearbit(register, bit)   (register) &= ~(1 << (bit))
#define testbit(register, bit)   (register) & (1 << (bit))

#include <avr/interrupt.h>
#include <avr/io.h>
#include <util/delay.h>


int main (void){

  setbit(DDRB, PB1); // set PB1 as output in DDRB.
  clearbit(DDRA, PA2); // set PA2 as input in DDRB.

sei();  // activate interrupts globally



setbit(DDRA, PA3);


CLKPR = (1 << CLKPCE);
CLKPR = (0 << CLKPS3) | (0 << CLKPS2) | (0 << CLKPS1) | (0 << CLKPS0);


//
// init A/D
//
ADMUX = (0 << REFS1) | (0 << REFS0) // Vcc ref
   | (0 << ADLAR) // right adjust
 | (0 << MUX5)| (0 << MUX4)  | (0 << MUX3) | (0 << MUX2) | (1 << MUX1) | (1 << MUX0); // ADC3
ADCSRA = (1 << ADEN) // enable
   | (1 << ADPS2) | (0 << ADPS1) | (0 << ADPS0); // prescaler /128

while (1) {

   ADCSRA |= (1 << ADSC);

if (ADC < 9){ // 9 is just a value for testing


clearbit(PORTB,PB1);

}else{

setbit(PORTB,PB1);
 _delay_ms(500);
clearbit(PORTB,PB1);
_delay_ms(500);

}
}
}

Design Problems

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.

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.

Final iteration

Testing