Introduction: Arduino Tailpipe Filter and Sensor

This tutorial shows how to make a tailpipe sensor and filter that connects to an app via bluetooth. A Tinyduino stack measures carbon monoxide from a tailpipe and sends the data via BLE to an App.

Step 1: Acquire Parts

Step 2: 3D Print Parts

Each of the pieces should be printed to the highest possible resolution. Infill should be at around 20%.

Piece 1 and 2 should have 2 shells. Piece 3 should be have 3 shells

Step 3: Building the Tinyshield Stack

  1. Start by soldering 3 wires to the Sparkfun Breakout Board (A1, B1 and H1)
  2. Solder a 10k resistor to ground on the Tinyshield Protoboard
  3. H1 should be soldered to the 5v on the Tinyshield
  4. Twist A1 and B1 together and solder it to the A0 pin
  5. Open one sugru pack and use the sugru to hold the gas sensor vertically above the proto board
  6. Let the sugru cure
  7. Solder the spring to the negative terminal of the tinyduino processor board
  8. Strip a 5 inch wire completely of the insulation
  9. Solder the wire to the positive terminal of the processor board

Step 4: Paint Cap

  1. Use the Conductive Paint and paint the outside of piece 3 to create a conductive surface
  2. Also paint the inner cylindrical section of piece 2 to create a conductive layer for the positive terminal

Step 5: Carbon Monoxide Sensor

The carbon Monoxide sensor is a complex Analog sensor.

Calculate Gas Sensor PPM
Each of the gas sensors outputs an analog value from 0 to 4095. To convert this value into voltage, use the following equation: COPY CODE Sensor Voltage = AnalogReading * 3.3V / 4095 Once you have the sensor voltage, you can convert that into a parts per million (“PPM”) reading using the sensitivity calibration curve on page 5 of the gas sensor datasheets. To do this, recreate the sensitivity curve by picking data points from the graph or using a graphical analysis software like Engauge Digitizer. Plot PPM on the y-axis and V_RL on the x-axis, where V_RL is the sensor voltage. There is a lot of room for error with this method, but it will give us enough accuracy to identify dangerous levels of hazardous gases. Estimated error bars are around 20 PPM for the LPG and Methane sensors, and about 5 PPM for the CO sensor.

The MQ gas sensors have light to no polarity, so the gas sensor will work with the board any way it fits into the 6 pins.

Next, find an approximate equation for the PPM vs. V_RL curve. I used an exponential fit (e.g. y = ex) and got the following equations: sensor: PPM = 26.572*e^(1.2894*V_RL)

CO sensor: PPM = 3.027*e^(1.0698*V_RL)

double ppm = 3.027*exp(1.0698*(rawValue*3.3/4095))

Use this to help get a reading from the MQ-7 Gas Sensor.

Source: Sparkfun

Step 6: Tinyduino and IOS Bluetooth Handshake

To write software for Arduino you’ll need to install Arduino IDE, it’s available for Mac, so you can just go to their website, and download it. They have a great guide on their website on how to set up your IDE. Once you installed the IDE, you’ll need to install the Adafruit libraries. Adafruit has a great tutorial on how to do this, so go and check it out.
Now we have the hardware wired up, and all the libraries we need. The only thing that’s left is to write some code and upload it to our Arduino board.

These instructions were sourced from Adafruit and a tutorial on BLE Handshakes. You will need to adapt some of the code for the MQ-7 sensor.

In this code, we’re handling two things. BLE breakout circuit and the temperature sensor. Let’s go over the BLE code first. At the top of the class, we create an instance of the BLE UART with the corresponding pins. In the setup method, we set the device name, and start our BLE chip. On Arduino, the setup method is executed once when the Arduino is started, and the loop method is executed constantly. So all our processing is done within the loop method. In this method, we get the current state of the BLE, and if it’s connected we send our temperature data. We can only send 20 bytes at a time, and once we get our temperature data (formatted as a string), we write it into our object. This will be our notifying RX characteristic that our iOS app will read from. Our temperature sensor is connected to the analog A0 input, and since we’ll be sampling the data at a very high frequency we need to smooth out the data, in order to prevent spiking. To smooth the data we’ll be using the ‘averageValue’ function. This function will take the last 50 measurements and give you an average value. We’ll be sampling the data many times a second, so this will give us a smooth sample. Once we get the smoothed out data, we need to convert the raw sensor value to the actual temperature. We’ll do this in the ‘temperature’ method. This method will take the sensor input value, convert it to the voltage, and then into the temperature. This string is what we’re writing into our BLE RX characteristic. That’s pretty much it on the Arduino side, we have a piece of hardware that’ s transmitting sensor data over BLE. The only thing left to do is to read that data in the iOS app.

Step 7: IOS Project

The whole Xcode project is attached on this step.

The units will obviously need to be changed.

The screen will be red if the bluetooth is disconnected.