void setup() { Serial.begin(9600); } void loop() { float sensor_volt; float RS; // Get the value of RS via in a clear air float R0; // Get the value of R0 via in Alcohol float sensorValue; for(int i = 0 ; i < 100 ; i++) { sensorValue = sensorValue + analogRead(A0); } sensorValue = sensorValue/100.0; //get average of reading sensor_volt = sensorValue/1024*5.0; RS = (5.0-sensor_volt)/sensor_volt; // R0 = RS/60.0; // 60 is found using interpolation Serial.print("R0 = "); Serial.println(R0); delay(1000); }
void setup() { Serial.begin(9600); } void loop() { float sensor_volt; float RS_gas; // Get value of RS in a GAS float ratio; // Get ratio RS_GAS/RS_air float BAC; int sensorValue = analogRead(A0); sensor_volt=(float)sensorValue/1024*5.0; RS_gas = (5.0-sensor_volt)/sensor_volt; // omit *RL /*-Replace the name "R0" with the value of R0 in the demo of First Test -*/ ratio = RS_gas/R0; // ratio = RS/R0 BAC = 0.1896*ratio^2 - 8.6178*ratio/10 + 1.0792 //BAC in mg/L Serial.print("BAC = "); Serial.println(BAC*0.0001); //convert to g/dL Serial.print("\n\n"); delay(1000); }