#include #include #include #include #define ONE_WIRE_BUS 7 OneWire oneWire(ONE_WIRE_BUS); DallasTemperature sensors(&oneWire); DeviceAddress insideThermometer; LiquidCrystal lcd(13, 6, 0, 1, 9, 10); /* Reading from a MPX5010DP sensor 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.) The sketch outputs the number of applied pascals and the sample number. // Adapted from Reading from a MPX5010 sensor by Kevin Bralten */ int offset=39; float tempC, tempF; int tmp; void setup() { // Serial.begin(9600); //setup the offset value and print it for reference offset=EEPROM.read(0); offset<<=8; offset|=EEPROM.read(1); // Serial.print("Offset: "); // Serial.println(offset); //set the aref to internal(1.1V), you could use the 3.3V regulator too analogReference(DEFAULT); sensors.begin(); sensors.getAddress(insideThermometer, 0); lcd.begin(16, 2); // wait while everything stabalizes. delay(1000); } int number = 0; //number of iterations int x; //fresh value from sensor float pascals; //after multiplication /* * 10bit AtoD converter, giving us 2^10=1024 possible values. (b=1024) * * sensor sensitivity to be 450mV/kPa or 0.450V/kPa. (c=0.45) * * (1.1 volts / 1024) / (450 millivolts/kilopascal) in kilopascal. * Working out to about 0.00238715278 kilopascal/value or 2.38715278 pascals/value * * based on 10bit AtoD, 1.1V reference, and 450mV/kPa * we get 1bit = ~2.38715278pascals */ void loop() { //read the sensor x=analogRead(0); //convert to pascals // 1.1V //pascals = (x-offset)*2.38715278; // 5V //pascals = (x-0.23)*1.1935764; pascals = (x-offset)*10.85; sensors.requestTemperatures(); tempC = sensors.getTempC(insideThermometer); tempF = DallasTemperature::toFahrenheit(tempC); tmp = int(tempF*100); //output the number of pascals and the iteration number /* Serial.print(pascals, DEC); Serial.print(" pascals @"); Serial.print(number,DEC); Serial.print(" Analog: "); Serial.println(x,DEC); */ lcd.clear(); lcd.setCursor(0,0); lcd.print(tempF); lcd.print(" Fahrenheit"); lcd.setCursor(0,1); lcd.print(" "); lcd.print(pascals); lcd.print(" Pascals"); /*if someone sends a 'c' update the offset value if(Serial.available() > 0){ if(Serial.read()=='c'){ offset=x; EEPROM.write(1,offset & 0xFF); x>>=8; EEPROM.write(0,x); } } */ //update the iteration and pause a bit. number++; // to the next character delay(100); }