EasyPIC v7: Talking Drunkometer

Friday! Time to stop working and start partying!

For today I have prepared a little prank: a talking drunkometer — or breathalizer if you prefer the more scientific name, a cool device that tells you if you still need to drink, or sends you home before you fall asleep on the street.

As in many other projects featured on this blog, I use MikroElektronika hardware: I start with the most important part, the alcohol sensor: one MQ-3 gas sensor Alcohol click board. This click board is designed to work on 5V power supply only, so I have to choose a development board that operates at 5V. I already have the EasyPIC v7 board, with a PIC18F45K22 microcontroller, and it can be configured to work on 5V. Great!
 
Alcohol click board
 
 
Now I need something that talks. The MP3 click featured in the Theremin project works only at 3.3V, so it doesn’t help me much. What I need is an MP3 player that operates at 5V: my choice is the Smart MP3 board.

Smart MP3 board

This little board has all I need: it integrates all the power and level-shifting circuits that allow it to work for both 3.3V and 5V supplies. It has a VS1053 MP3 player, plus a pair of LM4864 amplifiers and a speaker. There’s also an SD card slot — all the required hardware to get some sound.

The final project looks like this:


The board settings are as follows:
  • External power supply (highly recommended as the MQ-3 sensor is power-hungry)
  • 5V supply
  • Put PORTA switches in the middle (neutral) position.
  • Put PORTD switches in the pull-down position and put Button Press Level jumper J17 in the VCC position.
  • Put J15 to RA3 position
  • Alcohol click is in mikroBUS socket #1
  • SmartMP3 connected to PORTC
Before going to the software part, a fair warning: this little contraption is not calibrated in any way, and its output might not reflect actually how drunk you are. It’s just a device designed for having fun, and all the thresholds were set arbitrarily. Even if I would have had access to a calibrated Breathalyzer, calibrating this device would have been impossible. The response of the MQ-3 sensor is non-linear, is influenced by temperature, humidity, and by other factors, I can’t take into account. To compensate for all this I would have to build some lookup tables based by comparing the output of the MQ-3 sensor with the response of a calibrated device. The major problem is that the code, as it is now, occupies 99% of the RAM of the PIC18F45K22, leaving little room for improvements.

The only thing that I did is to insert a manual threshold to compensate for the background reading. This is done by using the potentiometer onboard EasyPICv7 as a voltage divider, the value is used to update threshold levels.

The software builds upon the code example for the SmartMP3 board and has the same way to set the volume: RD0 and RD2 are used to increase volume for left and right channels, RD1 and RD3 decrease volume for left and right channels, respectively.

The MP3_Play was changed to accept the filename as an argument — you can compare it with the original to see how I did this. I also commented on most of the LCD outputs to gain some precious memory space.

Reading MP3 files from the SD card relies on the FAT library — high capacity FAT32 SDHC cards are not supported. I found an old 4Gb simple SD in my junk box and I have formatted it to FAT, and it works fine. The only other issue is there’s no support for long filenames, so all files must obey the 8.3 naming standard.

I know there’s also a FAT32 library in MikroC, but the functions in that library are different than those in the simple FAT library. Perhaps one day I will come with a code example for playing MP3 files from the newer, high capacity SD cards…

Anyway, here are the listings for the MP3 code, and you’ll find that except a few changed lines it’s just like in the code example (double click on code to expand it):



The MQ-3 sensor needs a warming phase to measure correctly — don’t blow onto it during the warmup. I have to say here that it also needs some 100mA to work, and this is why I recommended the use of an external power supply, able to provide at least 1A.

The above code first starts a “calibration” phase, where you should adjust the ADC input potentiometer onboard EasyPIC V7 until the value displayed on LCD is close to zero — this will compensate for the reading of the background gases.

Then we’re good to go. The code waits for RE0 to be pressed, starting a new measurement cycle. The actual measurement is done after five seconds from the button press, and you should blow over the sensor for this whole period of time to get an accurate measurement.

Once a reading is done, the result is compared against some thresholds, taking the background response into account. One can compensate for changes in the background (smoke, for example) by simply adjusting the potentiometer onboard EasyPIC v7.

Another possibility is to play with the thresholds — you need some practice with those, as you wish to get all of the messages played before you get plastered. Anyway, drinking is fun, but you should always remember that hangover comes as a penalty for drinking too much…

As for the voices, I used some Homer Simpson’s .wav files that I got from http://www.wavsource.com/ and I have converted to MP3 using an online converter from http://audio.online-convert.com/convert-to-mp3. I can’t post those files here due to copyright reasons, but you can easily recreate them.

As I have said before, but I feel the need to repeat it, this is just a mere toy and is not designed as a replacement for a calibrated Breathalyzer. Don’t use the results as an excuse to drink too much…


Name

Air quality,2,Arduino code library,2,Arduino projects,23,Buggy,1,Casual stuff,1,ESP8266,2,MikroElektronika,3,PIC projects,7,Review,26,Robots,1,Tutorial,20,
ltr
item
Electronza: EasyPIC v7: Talking Drunkometer
EasyPIC v7: Talking Drunkometer
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjspadtffmmRDFpA6Yh5cFa9USr0Okd4yaSJPX4mdNu8yJHrMjI6S3dI24A-QRTR1kYVQ8QqnBoBMZG7FKh8WqJgbkvf9c3E2tcrHKU3n9A2hqeaGZoSL5uAQI_odbTndM8ZCfXRqEb3RH64NkLL-er3RuA0IGtTSOhwvAdvi7I9WCG6QLOByrbYrR3/w640-h306/smart-mp3.jpg
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjspadtffmmRDFpA6Yh5cFa9USr0Okd4yaSJPX4mdNu8yJHrMjI6S3dI24A-QRTR1kYVQ8QqnBoBMZG7FKh8WqJgbkvf9c3E2tcrHKU3n9A2hqeaGZoSL5uAQI_odbTndM8ZCfXRqEb3RH64NkLL-er3RuA0IGtTSOhwvAdvi7I9WCG6QLOByrbYrR3/s72-w640-c-h306/smart-mp3.jpg
Electronza
https://www.electronza.com/2016/04/easypic-v7-talking-drunkometer.html
https://www.electronza.com/
https://www.electronza.com/
https://www.electronza.com/2016/04/easypic-v7-talking-drunkometer.html
true
4275662725798500575
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content