Robojax

Using two or more Melexis MLX90614 Infrared Thermometer with Arduino

دروس آردوینو به فارسی

Using three Melexis MLX90614 Infrared Thermometer sensors with Arduino

This code is to connect three or more MLX90614 to Arduino.
The sensor is explained, datasheet is reviewed, wiring and code shown and demonstrated by measuring surface temperature, then using heat gun temperature is measured then temperature of a heater is measured. Arduino code is provided. See link below.
If you need to connect only MLX90614 to the same Arduino, See the code here
This code has not been tested. Study it fully and you will understand how it works and you can find the issue and fix it.

I2C address

In the datasheet on page 42 (Melexis MLX90614 Datasheet (pdf)) it says: The MLX90614 supports a 7-bit slave address in EEPROM, thus allowing up to 127 devices to be read via two common wires. With the MLX90614xBx this results in 254 object temperatures measured remotely and an additional 127 ambient temperatures which are also available.
for I2C address I've started with 0x5A, then 5A, 5C you can go to 5E, 5F and because it is Hexadecimal vlaue, use 6A, 6B....etc.
You may learn how to connect multiple item on the same I2C bus from this video

Chapters in this video

Resources for this sketch


 /*************************************************** 
  This is a library example for the MLX90614 Temp Sensor
Original Library and code source: https://github.com/adafruit/Adafruit-MLX90614-Library

 The code has been updated. I have added two funcitons. Also the Kelivin
 value added into the C and F units.
 1-First function to print the temperature on Serial Monitor
 2-2nd Funciton return the temperature so it can be used for Display or other purpose
 
   Want to get full explanation of this code
  and need wiring diagram? 
  Purchase My Arduino course on Udemy.com http://robojax.com/L/?id=62
 * 
 * Watch video instructions for this code: https://youtu.be/cFDSqiEIunw
updated/written by Ahmad Shamshiri on Feb 04, 2021
 
 * in Ajax, Ontario, Canada. www.robojax.com
 * 

 * Get this code and other Arduino codes from Robojax.com
Learn Arduino step by step in structured course with all material, wiring diagram and library
all in once place. Purchase My course on Udemy.com http://robojax.com/L/?id=62

If you found this tutorial helpful, please support me so I can continue creating 
content like this. You can support me on Patreon http://robojax.com/L/?id=63

or make donation using PayPal http://robojax.com/L/?id=64

 *  * This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact.* 
 * This code has been download from Robojax.com
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.

Origin
  Written by Limor Fried/Ladyada for Adafruit Industries.  
  BSD license, all text above must be included in any redistribution
 ****************************************************/

#include <Wire.h>
#include <Adafruit_MLX90614.h>
char *typeName[]={"Object","Ambient"};

Adafruit_MLX90614 mlx1 = Adafruit_MLX90614(0x5A);//defind sensor 1 object mlx1
Adafruit_MLX90614 mlx2 = Adafruit_MLX90614(0x5B);//defind sensor 2 object mlx2
Adafruit_MLX90614 mlx3 = Adafruit_MLX90614(0x5C);//defind sensor 3 object mlx3
//for I2C address I've started with 0x5A, then 5A, 5C you can go to 5E, 5F and because it is Hexadecimal vlaue, use 6A, 6B....etc
// just add the same line and set to mlx4, mlx5 etc.


//change the [3] to 2 or 5 or whatever number you like
float tempObjec[3];//Object Celsius 
float tempAmbient[3];//Ambient Celsius

float tempObjecF[3];//Object Fahrenheit
float tempAmbientF[3];//Ambient Fahrenheit

float tempObjecK[3];//Object Keilven
float tempAmbientK[3];//Ambient Keilven



void setup() {
  Serial.begin(9600);

  Serial.println("Robojax Multiple  MLX90614 test");  

  mlx.begin();  
}

void loop() {
  //Robojax Example for MLX90614
  //keep getTemp(); to read temperature
  getTemp(1);//this reads the temperature in C, K and F units for both object and ambient
  getTemp(2); for sensor 1
  getTemp(3); for sensor 3 
  
  //now the lines above have read the temperature, you can print them or use them.
  
  printTemp('C', tempObjec[0]);//Object Celsius, sensor 1
  printTemp('C', tempAmbient[1]);// Ambient Celsius, Sensor 1
  
  printTemp('F', tempObjecF[1]);//Object Fahrenheit sensor 2
  printTemp('F', tempAmbientF[1]);// Ambient in Fahrenheit for sensor 2

  printTemp('K', tempObjecK[2]);//Object Keliven  sensor 3
  printTemp('K', tempAmbientK[2]);//Ambient in Keilvensensor 3
    
	//to do something with object temperature in C (take action when temperature is greator than 38.1 for sensor 1
	//for object 
  if( tempObjec[0]>18.1)
  {
    //do something here
  }


	//to do something with temperature  in F (take action when temperature is greator than 110.4  for sensor 2
	//for object 
  if( tempObjecF[1]>110.4)
  {
    //do something here
  }  

  Serial.println("======");

  delay(3000);
  //Robojax Example for MLX90614
}

/*
 * @brief reads temperature

 * 
 * Written by Ahmad Shamshiri on Feb 4, 2021
 * in Ajax, Ontario, Canada
 * www.Robojax.com 
 */
void getTemp(int senso )
{

	   // Robojax.com MLX90614 Code
	   
	   //read temperature for sensor 1
	if(sensor ==1)
	{

    float tempObjec[0] = mlx1.readObjectTempC();// object Celsius
    float tempAmbient[0] = mlx1.readAmbientTempC();//	Ambient	Celsius
	
    float tempAmbientF[0] =  mlx1.readObjectTempF(); //Fah. Object	
    float tempAmbientF[0] = mlx1.readAmbientTempF();//Fah Ambient


    float tempObjecK[0] = tempObjec[0] + 273.15;// Object Kelvin	
    float tempAmbientK[0] =tempAmbient[0]+ 273.15;//Ambient Kelvin

	}
	

	   //read temperature for sensor 2
	if(sensor ==2)
	{

    float tempObjec[1] = mlx2.readObjectTempC();// object Celsius
    float tempAmbient[1] = mlx2.readAmbientTempC();//	Ambient	Celsius
	
    float tempAmbientF[1] =  mlx2.readObjectTempF(); //Fah. Object	
    float tempAmbientF[1] = mlx2.readAmbientTempF();//Fah Ambient


    float tempObjecK[1] = tempObjec[1] + 273.15;// Object Kelvin	
    float tempAmbientK[1] =tempAmbient[1]+ 273.15;//Ambient Kelvin

	}
	

	   //read temperature for sensor 3
	if(sensor ==3)
	{

    float tempObjec[2] = mlx3.readObjectTempC();// object Celsius
    float tempAmbient[2] = mlx3.readAmbientTempC();//	Ambient	Celsius
	
    float tempAmbientF[2] =  mlx3.readObjectTempF(); //Fah. Object	
    float tempAmbientF[2] = mlx3.readAmbientTempF();//Fah Ambient


    float tempObjecK[2] = tempObjec[2] + 273.15;// Object Kelvin	
    float tempAmbientK[2] =tempAmbient[2]+ 273.15;//Ambient Kelvin

	}
		
   

    // Robojax.com MLX90614 Code
}//getTemp

/*
 * @brief nothing

 * Written by Ahmad Shamshiri on Fbe 4, 2021
 * in Ajax, Ontario, Canada
 * www.Robojax.com 
 */
void printTemp(char type, float tmp)
{
  // Robojax.com MLX90614 Code
  float tmp =getTemp(type);

  if(type =='C')
  {
    Serial.print(typeName[0]);
    Serial.print(" ");    
    Serial.print(tmp);
    Serial.print("°");      
    Serial.println("C");
  }else if(type =='D')
  {
    Serial.print(typeName[1]);
    Serial.print(" ");     
    Serial.print(tmp);
    Serial.print("°");      
    Serial.println("C");
  }else if(type =='F')
  {
    Serial.print(typeName[0]);
    Serial.print(" ");     
    Serial.print(tmp);
    Serial.print("°");      
    Serial.println("F");
  }else if(type =='G')
  {
    Serial.print(typeName[1]);
    Serial.print(" ");     
    Serial.print(tmp);
    Serial.print("°");      
    Serial.println("F");
  }

  else if(type =='K')
  {
    Serial.print(typeName[0]);
    Serial.print(" ");     
    Serial.print(tmp);  
    Serial.print("°");       
    Serial.println(" K");
  }  
  else if(type =='L')
  {
    Serial.print(typeName[1]);
    Serial.print(" ");     
    Serial.print(tmp);  
    Serial.print("°");       
    Serial.println(" K");
  }

// Robojax.com MLX90614 Code
}//printTemp(char type)