loading

The idea for this project came when I found a cheap sensor online that claimed to measure alcohol concentration in the air. Who hasn't at some point wanted to use a breathalyzer, to see to a scientific degree just how intoxicated they were?

Police around the world use breathalyzers to obtain suspected drunk drivers' BAC. These breathalyzers give accurate and reproducible readings, but cost hundreds of dollars.

The MQ3 sensor only costs a couple bucks, but it does not give accurate, nor reproducible BAC readings. In other words, don't use this sensor to decide if you can drive or not. However, we can still have fun comparing relative values between friends.

The Cayenne platform and an ESP8266 are used to connect the MQ-3 sensor to the internet so data can be viewed and gathered over time.

Step 1: Prototyping

First step is to make sure that the hardware components all work together. A breadboard and jumper wires are invaluable for any sort of prototyping work unless you want to spend hours soldering connections. This was my first time working with a stripped down esp8266 chip, and I couldn't get the thing to program via FTDI until I realized that pin 0 *and* 15 have to be grounded to enter flash mode.

Important to remember is that the esp8266 runs off 3.3v while the sensor runs at 5v, so two separate regulators are required. The power supply is a 11.1V lipo battery. With the sensor powered continuously, (which you'll want to do because the sensor takes a while to give stable readings) it should give about 8 hours runtime.

The ESP-8266 only has one analog input, labelled ADC. It accepts voltages from 0-1V and converts it to a 10 bit value. A resistor voltage divider circuit lowers the 5v signal coming from the sensor.

Having run some basic sketches to make sure everything works properly, it's time to program this thing to start sending data to the cayenne IoT dashboard.

** Circuit diagram coming **

Step 2: Arduino Sketch and Cayenne Integration

The arduino sketch is pretty straightforward. The template provided in the cayenne dashboard when you add a sensor provides a very good starting point. The only change is that sensor data is obtained through analogRead(A0) since this corresponds to the ADC pin on the ESP8266. The first virtual input sends current readings from the sensor to the dashboard. I added a second channel/input to keep track of the highest reading obtained, aka the "high score". On the cayenne dashboard side, there are two "value" blocks that show current and highest readings, and a graph that plots readings with respect to time. Lastly, there's an http server running so that the board firmware can be updated over the air. Just merge the code from the webupdater.ino sketch into your sketch and you should be set. I would have preferred to update via the ArduinoOTA method, but unfortunately my router/modem combo blocks mDNS packets so I have to do it over a web server.

The sketch is available at https://github.com/dpeters1/IoT-Breathalyzer

Step 3: Hardware Finalization

The final step is to shrink everything into a small package and ensure it can survive being handled by individuals under the influence.

I stacked the voltage regulators and soldered everything as close to each other as possible. All the components are stuck to the battery pack with thick double sided tape. I hope this provides some shock absorption in case of drops. The enclosure is made of two 3mm aluminum plates bolted together. Aluminum is a great material to work with because it cuts and drills easily, but that also means that it is easily scratched as seen by the pictures. Regardless, it will protect the battery and electronics in most situations and I think it gives the device a rugged feel.

I'm pretty happy with how the project turned out considering it went from scratch to fully built in only a day. It lacks a few features and isn't as well polished as I'd like, but nevertheless it's a fun little gadget that introduced me to the Cayenne platform and IoT in general. If you have any questions feel free to leave a comment or email me.

<p>This is an interesting build. :) </p>
<p>Thanks! I just finished the device and updated the project page with the finished product pictures and related schematic, code, etc if you're interested.</p>

About This Instructable

1,657views

23favorites

More by DominicP21:Light, Fan, and Dimmer Control With ESP8266 and Cayenne IoT Breathalyzer with Cayenne, ESP8266, and MQ3 Sensor 
Add instructable to: