Created
February 6, 2011 23:46
-
-
Save csete/813836 to your computer and use it in GitHub Desktop.
Arduino code to read TMP102 temp sensor and MPX4115A pressure sensor.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* The setup for this code: | |
http://www.oz9aec.net/index.php/arduino/343-mpx4115a-pressure-sensor-with-arduino | |
*/ | |
#include <LiquidCrystal.h> | |
#include <Wire.h> | |
#define kpa2atm 0.00986923267 | |
// initialize the LCD library with the numbers of the interface pins | |
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); | |
// pin defs | |
int pressurePin = 0; | |
int ledPin = 13; | |
// variables | |
byte res; | |
byte msb; | |
byte lsb; | |
int val; | |
float tC; // temperature in Celsius | |
float tF; // temperature in Fahrenheit | |
float pkPa; // pressure in kPa | |
float pAtm; // pressure in Atm | |
unsigned long time; | |
void setup() | |
{ | |
// set up led pin as output | |
pinMode(ledPin, OUTPUT); | |
// set up the LCD's number (col,row): | |
lcd.begin(20, 2); | |
lcd.print("Temp"); | |
Serial.begin(9600); | |
Wire.begin(); | |
} | |
void loop() | |
{ | |
/* turn led ON */ | |
//digitalWrite(ledPin, HIGH); | |
lcd.clear(); | |
/* get and print current time */ | |
time = millis()/1000; | |
//lcd.print(time); | |
Serial.print(time); | |
Serial.print(": "); | |
/* get the pressure */ | |
val = analogRead(pressurePin); | |
pkPa = ((float)val/(float)1023+0.095)/0.009; | |
pAtm = kpa2atm*pkPa; | |
/* show pressure in kPa on LCD */ | |
lcd.setCursor(0,0); | |
lcd.print(pkPa); | |
lcd.print("kPa"); | |
lcd.setCursor(0,1); | |
lcd.print(pAtm); | |
lcd.print(" Atm"); | |
/* send pressure to serial port */ | |
Serial.print(pkPa); | |
Serial.print("kPa "); | |
Serial.print(pAtm); | |
Serial.print("Atm "); | |
/* get temperature from TMP102 */ | |
res = Wire.requestFrom(72,2); | |
if (res == 2) { | |
msb = Wire.receive(); /* Whole degrees */ | |
lsb = Wire.receive(); /* Fractional degrees */ | |
val = ((msb) << 4); /* MSB */ | |
val |= (lsb >> 4); /* LSB */ | |
/* calculate temperature */ | |
tC = val*0.0625; | |
tF = (tC * 9/5) + 32; | |
/* show temperatures on display */ | |
lcd.setCursor (12,0); | |
lcd.print(tC); | |
lcd.print("\xdf""C"); | |
lcd.setCursor(12, 1); | |
lcd.print(tF); | |
lcd.print("\xdf""F"); | |
Serial.print(tC); | |
Serial.print("C "); | |
Serial.print(tF); | |
Serial.println("F"); | |
} | |
else { | |
lcd.print("ERR"); | |
Serial.println("ERROR"); | |
} | |
/* turn led off */ | |
//digitalWrite(ledPin, LOW); | |
delay(1000); | |
} |
it prompt up an error ? Wire.receive() has been renamed Wire.read(). may you please help me how to solve this problem ?
thanks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@7thupranger I dont know if this will be to any help or not but here is a setup using this code. https://www.youtube.com/watch?v=wiv1eBAGVok