The Talking Breathalyzer Mark II using PIC18F1220
The Talking Breathalyzer Mark II
Thanks for having a gander! This is my second Breathalyzer project. IT TALKS TO YOU, and gives you an idea of how much you’ve had to drink! I made it specifically for for this contest. I hope you all like it. From a block diagram point of view, it consists of a DC power regulator circuit, an analog alcohol sensor + driving circuit, an audio recording and playback circuit, and the brain, which is a single PIC18F1220 MCU. If you have the time, go though my Instructable, and you will see how it works. The program is relatively simple, the function is REALLY NIFTY, and the hardware is easy to assemble. The original breathalyzer that I made about a year ago was perhaps more fun to play with, but required a lot more hardware, and was inferior in design. This version is much simpler, and it would be relatively easy for someone to reproduce it, or something similar. If you want to see the original, go here:
A lot of the parts involved with this project can be found on www.electroniclessons.com or www.engineeringshock.com. I will break this down into three areas of instruction:
1) Hardware and Assembly
4) Math and Conclusions
Of course, this won’t all be done in only a few steps, but I think you will have a lot of fun learning as we go along! Now, if you watch the video, you’ll get a good idea as to how this is meant to function.
The idea is this:
1) The MQ3 alcohol sensor has an analog output. You when you blow on the sensor, the output voltage changes based on two variables. First, the amount of alcohol it detects, and second, the value of the pull-down resistor at the output. If you have the proper value for the pull-down resistor, then you will get a good voltage range at the output. Low voltage = Little booze / Higher voltage = Lotsa booze!
2) We want to take that analog voltage and read it digitally. How? The brain chip, or MCU: the PIC18F1220, has a 10-bit internal analog to digital converter (Set up in program to work as an 8-bit ADC) that takes the analog voltage from the MQ3, and changes it into an 8 bit binary number, that can be interpreted digitally by the PIC.
3) On power on, you can program the audio recording IC on the board by pressing the record button. Since it will be our audio indicator that it is time to blow on the sensor, it is only appropriate that we hold down the RECORD button and say something along the lines of “:BLOW ON THE SENSOR”, or perhaps something a little more humorous. From there, we can press the PLAYBACK button to hear our message, to make sure it is what we want. this audio message is stored in memory, and is not lost when the device is powered off. The audio message can be up to 12 seconds. We are going to use this sound byte later.
4) We’ve had a few beers to drink. How is our drunkenness ranked? Well, press the SAMPLE button (As seen in the video). Assuming the output of the MQ3 is stable, the chip will not have to go through a calibration sequence. It will order your audio recording IC to playback your sound byte “Blow!”, at which point you will blow into the sensor. The output LEDs (6 of them) will shift upwards 12 times (Just to pass some time while you blow into the sensor), at which point the PIC makes its calculation, and BOOM, the output LED that indicates your level of drunkenness.
5) The program resets.
6) From there, if you want to take another reading, press the SAMPLE button again. If the output is still unstable from the last reading, it will go through a calibration state before the audio byte sounds.
Ready for Step#1?
Step#1 Hardware: The Full Schematic + Parts List
Okay, so now you can see each block!
1) The upper right block of the schematic is the ISD1218 chip with all necessary passive components. This bad boy is used to record an audio byte that will be played back when the PIC determines when it is time to take a reading. For instance, if no calibration period is necessary, or when calibration is complete, the PIC will initiate playback of the audio byte; “BLOW into the sensor”, or something to that end.
2) The upper left block shows off the very simple LM7805 regulator circuit. since there will be no further explanation for this block, let’s talk about it a little bit here. There is an input terminal block for DC-In. In order for the LM7805 chip to output a solid 5VDC, we have to make sure that there is at least 7VDC at the input (Pin#1) at all times, or else the circuit will not work properly. A 9V battery is more than satisfactory, although it it suggested that you use an on/off switch (not seen here), and that you use a Duracell or Energizer battery, as the MQ3 sensor is a power sucker. We will talk about that later. So, we want 7VDC+ at the input pin (Pin#1), Input DC- (Ground)) at pin#2, and 5VDC (regulated) at pin#3. This 5VDC line will power ALL of our blocks! The 100uF capacitor at the input is used to smooth any ripple on the DC input. However, if you are using a battery, there is really not necessary, as there should be no ripple at all. The 0.1uF capacitor at the output is merely to decouple the circuit, and dissipate any unlikely high frequency spikes.
3) In the lower left Block, we see the MQ3 alcohol sensor and driver circuit. This sensor has an analog output. The heater (middle two pins) is merely a 150mA coil (at 5v input voltage). This makes this component a relatively high power pain in the butt =) However, if you have an ON/OFF switch and a good battery, you’re good for a few nights on the town! We will talk more of this block function later on, as well as the required driver circuit.
4) Ah, the BRAIN! Block#4! The MCU is a PIC18F1220, 18-pin DIP IC, made by Microchip Technologies. The code is a little long, as we are using assembly code, but I think that it is a very simple program. There is a little basic math involved, but nothing a grade 7 student couldn’t handle =) I have done my very best to comment what each line of code does, and if you are interested, I will happily send you the .ASM code to you so that you can replicate it exactly, or perhaps modify it. The PIC has several functions. It takes instructions from the SAMPLE button, located at pin#7 (PORTA,RA3), instructs the ISD1218 record and playback IC to playback an audio byte when necessary (after the calibration period), takes the analog voltage from the MQ3 sensor, and changes it into an 8-bit binary number, does the math, adds wait-times (delays), and does the math. When a conversion has been made, the LED that is relative to your intoxication lights up (LED#1 being little to no alcohol, and 6 being massively wasted).
We will talk about each of these blocks, minus the power supply, as well as the code in the following steps. Here is the parts list:
1x 2-pronged terminal block
1x 100uF electrolytic capacitor
1x 0.1uf ceramic capacitor
1x 10uF electrolytic capacitor
1x 10k Ohm resistor
1x 1k Ohm multi-turn potentiometer
1x 10k Ohm resistor
6x 330-470 Ohm resistors
7x Red LEDs
1x LM7805 5v regulator
1x MQ3 Alcohol sensor
1x Mini 8-ohm speaker
1x ISD1218 record and playback IC (kit at www.electroniclessons.com)
3x Monetary push-buttons
1x 1N4401 Diode
1x Electret condenser microphone
The MQ3 and the ISD1218 kit can be found at http://www.electroniclessons.com. I can offer you a programmed PIC18F1220 if you’d like, as well. Heck, maybe I could put this whole thing together as a kit. That might be fun! =) As well, my youtube channel can be found here:
Step#2 Hardware Breakdown – MQ3 Sensor
The MQ3 is an easy to use analog alcohol sensor. It has 6 pins:
4) A (2)
5) H (2)
6) B (2)
The two (A) pins are connected internally, so you have the option of using either of them. The same goes for the (B) pins. There are two Heater pins, and they are not polarized in any way, so you can connect 5V/GND from either left to right, or from right to left. The resistance on the heater coil is 150 Ohms, so when you power it at 5V, it consumes 150mA on it’s own. This is why it is necessary to have an on/off switch, as the battery will drain if left on. You can also apply 5v from (A) to (B) or from (B) to (A). This sensor was built to be very versatile..
The basic idea is this: When you blow onto the heater coil through the head of the sensor, the voltage at the output (In this case pin B) changes. Some people say to use a 100k trim-pot between the output and ground, but I have never had a good result using such a high resistance. Notice that the pull down trip pot is 1k Ohms. I calibrated it to about 427-428 Ohms, so if you wanted to get a good voltage range at the output, I suggest using either a 420 Ohm resistor between your output and ground, or the trip,-pot.
When the sensor powers on, the output is slightly unstable, much like a PIR sensor. However, it does not take long for the output to becomes usable. When the output reads below 700mV, it is in the usable range, however, if left on, the output will likely go down to as low as 300mV, but that is of little consequence, as the program does not work with any voltage under 700mV.
If you want to know more about this sensor, I found a great blog about it that can be found here:
The output voltage range is between roughly 300mV to about 3.70v. However, if you legitimately blew an output reading of 3.5v or higher, you’d likely be on your way to the hospital =( If you take a swig of hard liquor, then blow into the sensor, you’re going to blow a 6 (Highest). However, if you wait 5 minutes or so since your last drink, you will have a more legitimate idea of exactly how much alcohol you’ve had to drink.
The output voltage is fed to the pin on the PIC18F1220 that I’ve assigned through programming to be the internal ADC. When the PIC takes a reading, it will sample the analog voltage at PORTA,RA0 (Pin#1) and convert it into an 8-bit binary number.
For more detail: The Talking Breathalyzer Mark II using PIC18F1220
Current Project / Post can also be found using:
- microchip block mq3 sensör