Breathalyzer with Android Phone IOIO, and MQ-3 Sensor

Ioio for Android Breathalyzer Tutorial

Ioio for Android Breathalyzer Tutorial

This is a really cool project I've been working on, and this will be both a presentation and a tutorial on how to use the IOIO with Android.

There's a lot to it if you never developed any Android application, but if you take some time to understand this one, you should be able to develop your own in no time!

In fact, this is also my first Android application and it took me just about 2 weeks to do it!





I have the IOIO for Android powered by 4 AA batteries. The MQ-3 sensor is wired to the Analog Pin 39 of the IOIO. The breadboard is used for a 1/2 voltage divider for the sensor output (not to damage the IOIO analog pin). The MQ3-Sensor resistor value is 16k (although the datasheet mentions a much higher one).

Then I have the phone plugged to the IOIO (the Bluetooth connection does not work with HTC phones so far, but it has been tried with Samsung ones and the Bluetooth connection worked perfectly fine!), and a shot of tequila!

The calibration phase has been fun (no animal has been harmed!), but for this, I'm just approaching the MQ-3 alcohol gas sensor from the tequila shot. The next 2 pictures show it close, then really close.


Android application:

We did not release it on the Android market yet, but if you want to see how it looks in real-life, just install it from the .apk file.

I swear the application is clean and it exactly corresponds to the one of the Eclipse project (project files available further down if you want to compile the application yourself).

Download the application manually


As I said in the introduction, this took me about 2 weeks to develop; in terms of hours, about 50, starting from knowing nothing about Android Applications!


Being able to get your IOIO working. For that, follow my IOIO for Android beginner's guide!


Breathalyzer for Android Eclipse project files

Then, as I said, there is quite a lot to it. Feel free to browse the files and take time to understand how it works.

I will not make a detailed tutorial about how to code in Java for Android here, but I will give you the basic things to get started with:

There are mainly 2 things I modified to develop this application: the .java file (in the src folder) and the graphical layout (main.xml)

On the right you can see the whole organization of the graphical layout.


For the .java file, it is very similar to Arduino in principle: you have an initialization function that is called only one time at the beginning, then a loop that repeats forever.

The complexity comes from the new java syntax and Android development tools, and the fact that Android does multi-threading.

Keep in mind that thing: what shows up on the screen is one thread, and you cannot access that thread within another one (the other one being the IOIO loop function).

You have to call:

runOnUiThread(new Runnable() {

public void run() {..... your UI modification code} });

The .java file is pretty long, as I have quite a bit of element declarations and graphical items management, but the process is detailed and commented.


There is a lot of java knowledge base online, I learned everything I used in this application by performing a search.

Keep in mind that this is my first Android application, and I am far from an Android expert. So for any java related question, you should do your own research.

Now if you have any question regarding this tutorial, and anything I used in my code, come and join us on our forum, we will be happy to help you!!

Happy breathalyzer-testing / science experimenting!!

This article was published by the Jaycon team. Learn more about how we can take your product design and hardware idea to the next level here.