Want more features on Pastebin? Sign Up, it's FREE!
Guest

Arduino MPX5010DP pressure and DS18B20 temp

By: a guest on Jan 7th, 2013  |  syntax: C  |  size: 2.94 KB  |  views: 23  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <EEPROM.h>
  2. #include <OneWire.h>
  3. #include <DallasTemperature.h>
  4. #include <LiquidCrystal.h>
  5.  
  6. #define ONE_WIRE_BUS 7
  7.  
  8. OneWire oneWire(ONE_WIRE_BUS);
  9. DallasTemperature sensors(&oneWire);
  10. DeviceAddress insideThermometer;
  11.  
  12. LiquidCrystal lcd(13, 6, 0, 1, 9, 10);
  13.  
  14.  
  15. /*
  16.  
  17. Reading from a MPX5010DP sensor
  18.  
  19. sample Analog #0, multiply by resolution, and get a number in pascals. Sensor has some offset voltage, so 0 pascals actually occurs at around 0.6V. The software stores the offset value and subtracts it from all readings. For longevity, this value is stored and read from EEPROM. (To set the offset, open both sensor ports to free air, wait for the sensor to stabalize, and send a 'c' over the serial port.)
  20.  
  21. The sketch outputs the number of applied pascals and the sample number.
  22.  
  23.  
  24. // Adapted from Reading from a MPX5010 sensor by Kevin Bralten <http://spiffie.org>
  25.  
  26. */
  27.  
  28. int offset=39;
  29.  
  30. float tempC, tempF;
  31. int tmp;
  32.  
  33. void setup()
  34. {
  35. // Serial.begin(9600);
  36.  
  37. //setup the offset value and print it for reference
  38. offset=EEPROM.read(0);
  39. offset<<=8;
  40. offset|=EEPROM.read(1);
  41. // Serial.print("Offset: ");
  42. // Serial.println(offset);
  43.  
  44. //set the aref to internal(1.1V), you could use the 3.3V regulator too
  45. analogReference(DEFAULT);
  46.  
  47.   sensors.begin();
  48.   sensors.getAddress(insideThermometer, 0);
  49.  
  50.   lcd.begin(16, 2);
  51.  
  52.  
  53. // wait while everything stabalizes.
  54. delay(1000);
  55. }
  56.  
  57. int number = 0; //number of iterations
  58. int x; //fresh value from sensor
  59. float pascals; //after multiplication
  60.  
  61. /*
  62. * 10bit AtoD converter, giving us 2^10=1024 possible values. (b=1024)
  63. *
  64. * sensor sensitivity to be 450mV/kPa or 0.450V/kPa. (c=0.45)
  65. *
  66. * (1.1 volts / 1024) / (450 millivolts/kilopascal) in kilopascal.
  67. * Working out to about 0.00238715278 kilopascal/value or 2.38715278 pascals/value
  68. *
  69. * based on 10bit AtoD, 1.1V reference, and 450mV/kPa
  70. * we get 1bit = ~2.38715278pascals
  71. */
  72.  
  73.  
  74. void loop()
  75. {
  76. //read the sensor
  77. x=analogRead(0);
  78.  
  79. //convert to pascals
  80.  
  81. // 1.1V
  82. //pascals = (x-offset)*2.38715278;
  83.  
  84. // 5V
  85. //pascals = (x-0.23)*1.1935764;
  86. pascals = (x-offset)*10.85;
  87.  
  88.   sensors.requestTemperatures();
  89.   tempC = sensors.getTempC(insideThermometer);
  90.   tempF = DallasTemperature::toFahrenheit(tempC);
  91.   tmp = int(tempF*100);
  92.  
  93. //output the number of pascals and the iteration number
  94. /* Serial.print(pascals, DEC);
  95. Serial.print(" pascals @");
  96. Serial.print(number,DEC);
  97. Serial.print(" Analog: ");
  98. Serial.println(x,DEC);
  99. */
  100.     lcd.clear();
  101.     lcd.setCursor(0,0);
  102.     lcd.print(tempF);
  103.     lcd.print(" Fahrenheit");
  104.     lcd.setCursor(0,1);
  105.     lcd.print(" ");
  106.     lcd.print(pascals);
  107.     lcd.print(" Pascals");
  108.  
  109. /*if someone sends a 'c' update the offset value
  110. if(Serial.available() > 0){
  111. if(Serial.read()=='c'){
  112. offset=x;
  113. EEPROM.write(1,offset & 0xFF);
  114. x>>=8;
  115. EEPROM.write(0,x);
  116. }
  117. }
  118. */
  119. //update the iteration and pause a bit.
  120. number++; // to the next character
  121. delay(100);
  122. }
clone this paste RAW Paste Data