Breathalyzer running on the MBED 1768 Platform; EE4427 Group 3 Spring 2018

Dependencies:   4DGL-uLCD-SE mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers convertToBAC.cpp Source File

convertToBAC.cpp

00001 //Written by Todd Clark
00002 #include "convertToBAC.h"
00003 
00004 float getBAC(float input){
00005     float voltage = input * 3; //Conversion from input resistance to voltage.
00006     float calibratedVoltage = voltage / 0.6; //Convert voltage to work with our 3 volt output signal.
00007     float ppm = 1033.992 + (55.84479 - 1033.992)/(1 + pow((calibratedVoltage/4.540421), 8.423297)); //Calculate ppm from our voltage values based on specs for MQ-3 gas sensor.
00008     float bac = (ppm * 0.21) / 100; //Calculate BAC from ppm. Formula taken from http://nootropicdesign.com/projectlab/2010/09/17/arduino-breathalyzer/
00009     float calibratedBac = bac - 0.12; //Calibrate sensor based on value at 0% alcohol.
00010     return (calibratedBac < 0.0) ? 0 : calibratedBac;
00011 }