Hi, I'm using the Parallax MLX90614 temperature sensor for a project with an Arduino Uno, with connections as follows:
Uno - MLX90614
5V - 5V
GND - GND
2 & 3 - SIG
12 - RST
Here is the code I'm using, adapted from TC_Chu's Point: Arduino to MLX90614 Infrared Thermometer Modules
#include <SoftwareSerial.h>
SoftwareSerial Temp90(2, 3);
int LED = 13;
int RESET = 12;
void setup()
{
pinMode(LED,OUTPUT);
pinMode(RESET,OUTPUT);
digitalWrite(LED,HIGH);
digitalWrite(RESET,LOW);
delay(10);
pinMode(RESET,INPUT);
Temp90.begin(4800);
Serial.begin(115200);
delay(100);
Temp90.print((byte)0);
Temp90.print("!TEMc");
Temp90.print((byte)0x5A);
Temp90.print((byte)7);
delay(1000);
digitalWrite(LED,LOW);
pinMode(3,INPUT);
}
void loop()
{
checkTemp();
}
int checkTemp()
{
static char rByte[10] ;
char rChar;
static int Read = 0;
static int rcount=0;
int Temp1;
int Temp2;
int Temp3;
while (Temp90.available() > 0) {
rChar = Temp90.read();
if (rChar == 'T') {
Read = 1;
rcount = 0;
}
if (Read == 1) {
rByte[rcount] = rChar;
rcount++;
}
}
if (rcount >= 6) {
if ((rByte[0] == 'T') && (rByte[1] == 'E') && (rByte[2] == 'M')) {
Temp1 = rByte[4] + rByte[5]*256;
Temp2 = (Temp1/100);
if (Temp1*2 < 27315) {
Temp3 = ((27315-(Temp1*2))/100);
}
else
{
Temp3 = (Temp1/100*2)-273;
}
Serial.print(rcount); Serial.print("/");
Serial.print(Temp1,DEC);Serial.print(" ");
Serial.print(Temp2,DEC);Serial.print(" ");
Serial.println(Temp3,DEC);
rcount = 0;
Read = 0;
digitalWrite(LED,HIGH);
delay(500);
digitalWrite(LED,LOW);
delay(500);
}
}
}
(I have tested the code with the addresses 0x35 and 0x5A)
However, there is no output at all. Could someone with experience using this sensor help me find where I went wrong? Thank you very much.