Guest User

Untitled

a guest
Jul 18th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. void setup()
  2. {
  3. Serial.begin(9600);
  4. }
  5.  
  6. void loop()
  7. {
  8. float sensor_volt;
  9. float RS; // Get the value of RS via in a clear air
  10. float R0; // Get the value of R0 via in Alcohol
  11. float sensorValue;
  12.  
  13. for(int i = 0 ; i < 100 ; i++)
  14. {
  15. sensorValue = sensorValue + analogRead(A0);
  16. }
  17.  
  18. sensorValue = sensorValue/100.0; //get average of reading
  19. sensor_volt = sensorValue/1024*5.0;
  20. RS = (5.0-sensor_volt)/sensor_volt; //
  21. R0 = RS/60.0; // 60 is found using interpolation
  22. Serial.print("R0 = ");
  23. Serial.println(R0);
  24. delay(1000);
  25.  
  26. }
  27.  
  28. float R0= 0.28;
  29. void setup() {
  30. Serial.begin(9600);
  31.  
  32. }
  33.  
  34. void loop() {
  35. float sensor_volt;
  36. float RS_gas; // Get value of RS in a GAS
  37. float ratio; // Get ratio RS_GAS/RS_air
  38. float BAC;
  39. int sensorValue = analogRead(A0);
  40. sensor_volt=(float)sensorValue/1024*5.0;
  41. RS_gas = (5.0-sensor_volt)/sensor_volt; // omit *RL
  42.  
  43. /*-Replace the name "R0" with the value of R0 in the demo of First Test -*/
  44. ratio = RS_gas/R0; // ratio = RS/R0
  45. float a = pow(ratio, 2);
  46. float b = ratio/10;
  47. BAC = (0.1896*a) - (8.6178*b) + 1.0792 ; //BAC in mg/L
  48. Serial.print("BAC = ");
  49. Serial.println(BAC*0.0001); //convert to g/dL
  50. Serial.print("nn");
  51. delay(1000);
  52.  
  53. }
Add Comment
Please, Sign In to add comment