EasyPIC v7: Talking Drunkometer


Friday! Time to stop working and start partying!

This blog post is more than two years old.

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 like 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 an PIC18F45K22 microcontroller, and it can be configured to work on 5V. Great!

Alcohol Click

Alcohol Click

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 a MP3 player that operates at 5V: my choice is the 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:

EasyPIC v7: Talking drunkometer

EasyPIC v7: Talking drunkometer

The board settings are as follows:

  • External power supply (highlyreccomended as teh 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 it’s 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 being used to update threshold levels.

1 2 3

Leave A Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.