LM75 Temperature Sensor On Arduino
Wire the LM75 in the above way. SDA goes on A4 and SCL on A5.
Get the I2C library for arduino
Here is an example code which reads the temperature to the full degree C.
//for lm75
#include <Wire.h>
#define SensorAdresse 0x48 // I2C address of the LM75
#define TEMP 0 // temperature register
char dataString[7]; // temp as string: (-xx)x.x
double temp; // temp as double
int tgtemp; //val to store temperature
//---------- setup devices----------------
void setup()
{Serial.begin(9600); //turn on serial port
Wire.begin(); //turn on I2C
}
//----------temperature measure section-----------------
double get_LM75_temperature(int device, int regx)
{
int8_t msb;
int8_t lsb;
int8_t msb1;
Wire.beginTransmission(SensorAdresse + device);
Wire.write(regx);
Wire.endTransmission();
Wire.beginTransmission(SensorAdresse + device);
Wire.requestFrom(SensorAdresse + device, 2);
if (Wire.available()) {
msb1 = Wire.read();
msb = msb1 << 1;
lsb = Wire.read();
}
lsb = (lsb & 0x80 ) >> 7;
Wire.endTransmission();
tgtemp = (msb /2);
}//-------------end temp measure section------------
void loop()
{
temp = get_LM75_temperature(0, TEMP);
Serial.println(tgtemp);
delay (500);
}