cjmcu-mlx90614 IR temperature sensor can't read

Hi everyone,

I’m doing a project for school with the Arduino (UNO R3). I’m trying to connect an Infrared Temperature sensor (cjmcu-mlx90614) to it. Now my problem is, it works with RX, TX, VCC, GND, GND, NRS, SWI, VCC. Since I’m not the most technical person, I asked a friend how to connect this. He told me to just use the RX, TX, VCC and GND on one side and that should work. Since apparently you can’t use the RX and TX (port 0 and 1) of the Arduino itself. I decided to use SoftwareSerial and use port 10 and 11. GND is connected to GND (ofc) and VCC is connected to 5V. Now when I run my code (that I assembled during my many google searches) it gives me highly unlikely data. Also it never changes…
I can’t find a lot about this sensor online and like no one that seems to have made a tutorial about it with Arduino.

This is the code I use:

#include <Wire.h>
#include <SoftwareSerial.h>
#include <Adafruit_MLX90614.h>
Adafruit_MLX90614 mlx = Adafruit_MLX90614();

SoftwareSerial mySerial =  SoftwareSerial(10, 11);
//SoftwareSerial mySerial(10, 11); // RX, TX
//int analogValue;

void setup() {
    // Open serial communications and wait for port to open:
  Serial.begin(115200);
  mySerial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Native USB only
  }
  
  Serial.begin(115200);
  Serial.println("Adafruit MLX90614 test");  
  mlx.begin();  
}

void loop() {
  //analogValue = analogRead(A0);
  
  Serial.print("Ambient = "); Serial.print(mlx.readAmbientTempC()); 
  Serial.print("*C\tObject = "); Serial.print(mlx.readObjectTempC()); Serial.println("*C");
  Serial.print("Ambient = "); Serial.print(mlx.readAmbientTempF()); 
  Serial.print("*F\tObject = "); Serial.print(mlx.readObjectTempF()); Serial.println("*F");
  Serial.println();
  //Serial.print(mySerial.read()); 
  //Serial.print(analogValue, DEC);
  //Serial.readBytes();
  Serial.println();
  delay(1000);
}

So I anyone could tell me if my wiring is wrong or my code or both…
Thanks in advance.

Anouck

@nouckie's MLW90614_CJMCU-IR.jpg:


nouckie:
Now my problem is, it works with RX, TX, VCC, GND, GND, NRS, SWI, VCC. Since I'm not the most technical person, I asked a friend how to connect this. He told me to just use the RX, TX, VCC and GND on one side and that should work. Since apparently you can't use the RX and TX (port 0 and 1) of the Arduino itself. I decided to use SoftwareSerial and use port 10 and 11. GND is connected to GND (ofc) and VCC is connected to 5V.

I think you and your friend are on the right track here, though I'm not sure what the situation is with the supported voltage levels. It seems there is essentially no information available about this module. What I have found indicates there is an STM8S003F3 microcontroller on the bottom of the module. I'm guessing this converting the "repeated-start" I2C communication of the MLX90614 to UART (serial)?

Does the chip on the bottom of the board have writing that includes the letters "8S003F3" on it?

Can you provide a link to where you bought the MLX90614 module?


nouckie:
Now when I run my code (that I assembled during my many google searches) it gives me highly unlikely data.

Here's where you went very wrong. You were on the right track to use software serial, but your code doesn't actually do anything with the software serial. Instead, it uses the Adafruit_MLX90614 library. That library is intended to be used for when you have a MLX90614 directly connected to your Arduino board and are communicating with it via I2C, but that's not the case with your module. So the Adafruit_MLX90614 library won't do you any good.

Instead, what you need to do is run a "passthrough" sketch on your Arduino board, which simply reads from the software serial port (mySerial) and then prints that data to the hardware serial port attached to your computer (Serial). The SoftwareSerial library comes with a sketch that does this. You can find it at File > Examples > SoftwareSerial > SoftwareSerialExample. It's probably a good idea to remove this line:

  mySerial.println("Hello, world?");

since who knows what the STM8S003F3 microcontroller on the MLX90614 module would think of that.

The tricky thing is that, without documentation, we don't know what the configuration of the STM8S003F3's serial communication is (most importantly, baud rate), whether you need to send it commands, and even if it's actually using serial communication. What you can do is just keep uploading that SoftwareSerialExample sketch, checking Serial Monitor, then if you don't see anything, try a different baud rate on this line of the sketch:

  mySerial.begin(4800);

and repeat.

The common baud rates are 9600, 57600, and 115200, but it could be something else.

@pert

This is the site where I bought it:

For the “8S003F3”, I have attached a pictures of the only other info that I could find on the sensor. It seems like it says:
“…78349
8S003F3P6
PHL 524 Y”

I have removed the “Hello, world one”. And I will try your suggestion on the SoftwareSerialExample.

This is the only information I have find about the cjmcu-mlx90614 IR on the internet:

Module vorm met RX/TX seriele communicatie
informatie (ENG):
CJMCU-90614 is a low-cost infrared temperature module and its operating voltage is 3-5V.
Its working principle is read through the MCU infrared temperature data, serial (TTL level)
Communication output (baud rate can be set): The serial port baud rate is 9600bps, 57600 and 115200bps
There are 2 output method including continuous output and query output, can adapt to different working environments, and connect to all the microcomputer and computer.
Communication protocol:
Serial communication parameters (default baud rate 115200 bps, can be set by software)
Baud rate: 9600bps, Parity bit: N, Data bits: 8, Stop bits: 1
Baud rate: 57600bps, Parity bit: N, Data bits: 8, Stop bits: 1
Baud rate: 115200bps, Parity bit: N, Data bits: 8, Stop bits: 1
Module output format:
Instruction length: 9
Data output format:
Byte1 Header Flags 0x66
Byte2 Header Flags 0x66
Byte3 data output mode (0x01 continuous output; 0x02 query output, the default for continuous output mode)
Byte4 Measured data length (counted by Byte)
Byte5 Data 1 Upper 8 bits
Byte6 Data 1 Lower 8 bits
Byte7 Data 2 Upper 8 bits
Byte8 The lower 8 bits of data2
Byte9 data parity (all data accumulation, take the low 8-bit)
Data calculation method:
Temperature = Data High 8 bits << 8 | Lower 8 bits of data, the result is the actual temperature multiplied by 100.
Command instructions:
Byte1 Header Flags 0x66
Byte2 Header Flags 0x66
Byte3 Sets the command:
0x01 Continuous output mode
0x02 Query output mode
0x11 Set the baud rate to 9600
0x12 Set the baud rate to 57600
0x13 Set the baud rate to 115200
Byte4 End of frame flag 0x56
Using method:
The module uses serial to output data, the module connected to the power, connect the serial port (default baud rate 115200, continuous send mode), the serial directly output. If you want to change the send mode, you can send a command 66 66 02 56 to the module, and once the command is sent, the module will return the temperature data once. If you want to change the baud rate to 9600 you can send 66 66 11 56 to the module, and if you want to change the baud rate to 57600 you can send 66 66 12 56 to the module.

It doesn’t mean a lot to me (except for the baudrates), but maybe you know what this might mean…

Thanks a lot!

Great information! That helps a lot.

This:

nouckie:
Serial communication parameters (default baud rate 115200 bps, can be set by software)

means that you need to change this line of the sketch:

mySerial.begin(4800);

to:

mySerial.begin(115200);

However, there is a problem: the SoftwareSerial library doesn't work reliably at 115200 baud. You can configure the module to communicate at a lower baud rate which is supported by the SoftwareSerial library. So my advice is to start with communication at 115200 for long enough to send the command to the module to switch to 57600 (which is supported by the SoftwareSerial library). Fortunately, my experiments indicate the SoftwareSerial library does work reliably at 115200 for sending, just not for receiving. So you can send the command to the module at the default of 115200 with no problems. So you add this to your setup() function:

mySerial.begin(115200);  // communicate at the module's default baud rate
byte changeBaudCommand[]={0x66, 0x66, 0x12, 0x56};  // command to switch the module's communication to 5700 baud (from the documentation at http://domoticx.com/arduino-thermometer-ir-contactloos-mlx90614/)
mySerial.write(changeBaudCommand, sizeof(changeBaudCommand) / sizeof(changeBaudCommand[0]));  // send the command to change the baud rate
mySerial.begin(57600);  // communicate at the new baud rate

Information on the SoftwareSerial library here:
https://www.arduino.cc/en/Reference/SoftwareSerial

The "sizeof(changeBaudCommand) / sizeof(changeBaudCommand[0])" thing is telling the compiler to calculate the length of the changeBaudCommand array. You could simply replace that with the number 4, but it's nice to programmatically determine lengths so that the code will automatically adapt if you were to change the length of the array (which actually isn't very likely in this specific case).