Quantcast
Viewing all articles
Browse latest Browse all 45

BREATHALYZER WITH ANDROID PHONE, IOIO AND MQ-3 SENSOR

Image may be NSFW.
Clik here to view.

Introduction:

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!

Video:

[Coming]

Hardware:

IOIO for Android
Alcohol Gas sensor MQ-3
with the MQ-3 Breakout board
Also a Mini-breadboard, a bunch of different jumper wires, some resistors (3x 16k) and a battery holder.
And of course, an Android phone!

Image may be NSFW.
Clik here to view.

Principle:

Image may be NSFW.
Clik here to view.

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 way 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 works 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.

Image may be NSFW.
Clik here to view.

Image may be NSFW.
Clik here to view.

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

Image may be NSFW.
Clik here to view.

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

Prerequisite:

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

Project:

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.

Image may be NSFW.
Clik here to view.

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.

Conclusion

There is a lot of java knowledge base online, I learnt 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!!


Viewing all articles
Browse latest Browse all 45

Trending Articles