I am using an infrared sensor called OTI301. In its data sheet it says that in order to obtain object temperature and ambient temperature values I need to extract the binary information from the sensor and use the binary information in given formulas. I have done all that but for some reason I am not getting the right values for the object temperature. The ambient temperature seems to work well but when I put a hot object, more than 320 F, the formula returns a random negative number. Also the the sensor can go up to 780 F so I know the temperature has not been capped. Please see pictures for important data sheet information, or here are the links for the complete data sheets https://drive.google.com/file/d/1XMRDCNzY3fn0q6lkGejs5D-pqksfRuZ8/view?usp=sharing. https://drive.google.com/file/d/1mmdkHkNbwC5VgQxGMrq07XolajNvgBkN/view?usp=sharing. Lastly, here is the part of the code where I extract the information and apply formulas.
void loop()
{
if (Wire.read()) // On success, read() will return 1, on fail 0.
{
buttonState = digitalRead(button);
//Serial.println(buttonState);
Wire.beginTransmission(DEVICE_ADDRESS);
Wire.write(0x80); // readout command
Wire.endTransmission(false);
Wire.requestFrom(DEVICE_ADDRESS, 6); // request 6 bytes
uint8_t data[6];
for (int i = 0; i < 6; i++) {
data[i] = Wire.read();
}
//Calculate Object Temperature
if(data[5] < 0x80) {
TA = (data[3]+ data[4]*256+data[5]*65536)/200;
}
else {
TA = (((data[3]+ data[4]*256+data[5]*65536)) - 16777216) /200;
}
//Calculate Ambient Temperature
if(data[2] < 0x80) {
TA = (data[0]+ data[1]*256+data[2]*65536)/200;
}
else {
TA = (((data[0]+ data[1]*256+data[2]*65536)) - 16777216) /200;
}
TA
?TA
you are doing integer math. Try as DataFiddler wrote and cast the numbers to long, so that the result cannot overflowlong int
.