Introduction: Fartometer - Arduino
Fartometer allows you to measure how mighty your farts are.
FartometerProject is an Open Source Project that brings the art of releasing flatulences to another level.
Using a very intuitive Arduino code, it allows you to send and receive data among an Arduino device, a BLE Shield and another device such as a smartphone (FartometerIOSProject) through bluetooth.
More details on https://github.com/ideiadoluiz/FartormeterArduino... and https://github.com/ideiadoluiz/FartormeterArduino... . Both FartometerArduinoProject and FartometerIOSProject are licensed under GNU GPL v. 2 or later.
Step 1: Intro
At first, I thought of the Fartometer project as a mean to get to know the Arduino environment. However, as I have some background in doing researches, I can't stop thinking about science even when I'm playing.
I lost so many sleeping hours in this project just by the fact that I was waking up 2am with random questions like “But methane doesn’t smell, so what kind of chemical element does it in the fart?”.
The good thing is, not sleeping gave me a lot to share about general knowledge of farts.
Step 2: Research
Before starting this project, I did some research on past projects and turned out that I found on the Internet two very good projects regarding the measurement of flatulences. Arduino Fart-O-Meter and Fart Intensity Detector.
My mistake was that I followed the first one, but calm down because I will explain it better. My solution is partially wrong.
So why is it wrong?
Even though a fart may contain 0-10 percent methane in it, not everyone has the bacteria that produces methane in their stomach. In fact, most of adults (2/3) pass farts that contain no methane, vide http://www.heptune.com/farts.html. They have a pretty ugly website, I know, although they have very good sources.
Well, I gotta admit that I tested my fartometer for real. That was for science, ok? I do have the bacteria and it had approximately 110 milliliters (average quantity in a human fart) of CH4 (Methane) vide http://www.salon.com/2000/02/24/farts/.
When did I realize that Methane was odorless?
In one of those nights of non-sleeping my brain reminded me that they add odor to the kitchen gas for that same reason; methane does not smell. The gas that smells like rotten eggs is called Hydrogen Sulfide(H2S) and only represents about 1% of all the concentration of gas in a fart.
That’s to say, if you want to know how stinky a fart is, you should probably get a Hydrogen Sulfide Sensor. Therefore, be aware of that.
In my project, though, I’m measuring the amount of methane in the air and how loud it is with a sound sensor, which I will include on another future post. It would be also interesting if you added a thermal(temperature) sensor, as it is explained on the Fart Intensity Detector project.
Step 3: List of Required Materials
- iPhone 4s or newer with Bluetooth LE (I’m using an iPhone 6 with iOS version 9.0)
- Arduino Uno Board (I’m using SparkFun Arduino Red Board, which is compatible with Arduino Uno)
- USB Mini-B Cable
- 3 Jumper Wires
- A BLE Shield (A shield that will go on the top of the Arduino and will send messages to your device through Bluetooth, I’m using RedBearLab BLE Shield)
- And finally… a gas sensor. I’m using MQ-4 (CH4 sensor)! Although, as I said before, it would’ve been better if I had used MQ-136 (H2S sensor). It is way more expensive, though. You can check the list of MQ gas sensors for arduino here.
I ended up buying the full SparkFun Inventor’s Kit, because it is very convenient for future projects. Thus, I only bought the SparkFun Inventor’s Kit, the RedBearLab BLE Shield and the MQ-4 sensor.
Step 4: Communication Between IPhone and BLE Shield
That was my first project using Arduino. And I got very impressed about how flexible it is for using components and making small projects.
The first thing I did was reading a tutorial about how to implement Bluetooth LE with an Arduino and integrating that with an iPhone.
It would have been way easier to have implemented that if I only had followed that tutorial; however, I decided to buy the RedBearLab BLE Shield instead of the BLE-Shield v2.0.0 based on Bluegiga’s BLE112 Module, and guess what, I don’t regret at all, RedBearLab has a very good documentation and has also open source projects for iOS and Android.
After installing it, you should test it by selecting the library project “Simple Chat”. You will find that on File > Examples > RBL_nRF8001 > SimpleChat
Click on Verify and then on Upload. If everything goes right, your Arduino is already prepared for communicating with your smarthphone. If not, you should probably take a look at https://www.arduino.cc/en/Guide/HomePage, https://www.arduino.cc/en/Guide/Libraries, BLE Shield LibraryManager.pdf, http://redbearlab.com/getting-started-bleshield and http://redbearlab.com/bleshield/. Check also if you have installed your Arduino driver and have selected the correct Arduino Port (the one that your arduino is plugged in, duh!).
Ok, now your Arduino is working and only waiting for pairing a device, which is an iPhone in this case.
Pair your smartphone with your Arduino board through the “Scan” button. After that, everything should be working properly and you can send and receive messages through your devices. In your Arduino, remember to set your Serial Monitor baud rate as 57600 baud, which is the default BLE Shield bauld rate value.
Check the cellphone and Serial Monitor images.
See that I’m using in this project messages up to 16 bytes of length. That’s why the message “But you’re a machine, duh” was cut. Beware of that, then.
Lastly, as you already know how the BLE Shield works, you can download my Arduino’s code here on my GitHub.
My Arduino’s code is based on a simple dual state machine, where canReadSensors can be ON or OFF. If the paired device send a message cmd_start, the Arduino reads its sensors and send the sensors’ messages back to the paired device. The format of the message is something like met:200, which represents the value read by the Methane Sensor. It is important to know that the Arduino will be sending those messages until it receives a message cmd_stop from the paired device (your iPhone, for instance). Knowing when to send cmd_start and cmd_stop is crucial, once it can save lots of battery.
Step 5: Attaching MQ-Sensor to the Arduino
From this point, you shoud have this code uploaded in your Arduino.
Your MQ-sensor has 4 pins:
- AO: Analog Output
- DO: Digital Output
- GND: Ground
- VCC: 5V
Use your wires to make the connection between your breadboard and your BLE Shield. Connect the AO wire to the A0(analog zero) pin in your BLE Shield. After that, connect the GND wire to the BLE Shield’s GND pin. And finally, connect the VCC wire to the BLE Shield’s 5V pin.
You can also check this video for a better comprehension.
Now, if you launch the RedBearLab app for iPhone (HINT: IT ALSO WORK WITH THEIR ANDROID APP!), you will need to send cmd_start to start receiving information from the BLE Shield. Try it (Check the images above).
Step 6: Conclusion
Congratulations!!! Now you have your own fartometer!!! You can customize it the way you want! Don’t forget to calibrate your sensors!
Now that you are receiving the concentration of gas in the air through bluetooth, you can create an app monitor!!!
I made my Fartometer app monitor based on their Simple Chat app, which is open source.
You can download, check and run my iOS app on https://github.com/ideiadoluiz/FartometerIOSProject and the Arduino code on https://github.com/ideiadoluiz/FartormeterArduinoProject.