Hey there, I am using a TMP275 sensor that I have connected with Arduino. The pin connection are as followed: -
TMP275 - Arduino
SCL - SCL
SDA -SDA
Vcc - 5V
GND - GND
A0-A2 - GND
I have written the following code to obtain the data from the sensor:-
#include <Wire.h>
#define break_out_config 0x48// standard breakout configuration of TMP275
#define temperature_register 0x00 // standard register of temp sensor
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Wire.begin();
}
void loop() {
double temp = sensorRead();
Serial.print("Temperature detected is:");
Serial.print(temp);
Serial.println(" Celsius");
delay(500); // value presented in every 30 sec
}
double sensorRead(void){
// temp hold 2 bytes of data read back from TMP275
uint8_t temp[2];
// tempc will hold the modifies combination of the bytes
int16_t tempc;
// pointing to the device (sensor)
Wire.beginTransmission(break_out_config);
// Pointing to the temperature register
Wire.write(temperature_register);
// Removing the master control to the Sensor
Wire.endTransmission();
// Requesting the temperature data
Wire.requestFrom(break_out_config,2);
// Serial.print("Code runs till here ");
// Checking if 2 bytes are returned
if (Wire.available() <= 2){
// reading out the data
temp[0] = Wire.read();
temp[1] = Wire.read();
// ignore the lower 4 bits of byte 2
temp[1] = temp[1] >> 4;
// combining to make one 12 bit binary number
tempc = ((temp[0]<<4|temp[1]));
// Converting the temperature to celcius(0.0625 oC resolution) and return
return tempc*0.0625;
}
}
}
I have got pull-up resistors attached to SCL AND SDA as mentioned in the datasheet.
The code uploads fine. But I obtain a constant temp= 255.94 oC in the serial monitor. What seems to be wrong?