Contactless Smart Thermometer using Arduino, MLX90615 IR

Antonio M.'s picture

Offline

Joined: Sep 03, 2020

Replies: 4
Contactless Smart Thermometer using Arduino, MLX90615 IR
September 3, 2020 - 3:08pm

Hello, I read with great interest his project and decided to realize it, but I have a problem in compiling the Sketch with Arduino. I'm getting errors in compiling the type: "previous definition of 'class MLX90615' " . Arduino 1.8.14 use. Kindly you could have the full file already filled in? Or a guide to proper compilation? I apologize for the language used.
An early thank you to those who can help me solve this problem.

 

Sourav Gupta's picture

Offline

Joined: Feb 12, 2018

Replies: 360

Find the MLX90615 Class defination. May be in the header file of the same.

Share the code exactly as written when you are getting the compilation error.

Antonio M.'s picture

Offline

Joined: Sep 03, 2020

Replies: 4

I mean, Sourav this is the code that I put in Arduino for compilation and where I get the error:

/*************************************************************************
 * A minimal Arduino library for
 * Melexis MLX90615 Infra-red Temperature Sensor
 * Copyright (C) 2017 Sergey Kiselev
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *************************************************************************/
 
#if (ARDUINO >= 100)
 #include "Arduino.h"
#else
 #include "WProgram.h"
#endif
#include "Wire.h"

// default MLX90615 I2C address
#define MLX90615_I2C_ADDR    0x5B

// ROM - ID number
#define MLX90615_REG_ID_LOW     0x1E
#define MLX90615_REG_ID_HIGH    0x1F
// RAM - ambient temperature register
#define MLX90615_REG_TEMP_AMBIENT 0x26
// RAM - object temperature register 
#define MLX90615_REG_TEMP_OBJECT  0x27

class MLX90615 {
 public:
  MLX90615(uint8_t i2c_addr = MLX90615_I2C_ADDR);
  void begin();
  uint32_t get_id();
  float get_object_temp();
  float get_ambient_temp();

 private:
  uint8_t i2c_addr_;
  uint16_t read_word16(uint8_t reg);
};
float error_correction  = 3.5; //add this to actual value
int Range_sensitivity = 200; //Decrease this value to increase range 
#include <Wire.h> 
#include "MLX90615.h"
MLX90615 mlx = MLX90615();
void setup()
{
Serial.begin(9600);
delay(100);
while (! Serial);
pinMode(2,OUTPUT);
mlx.begin();
}
int Noise;
int Signal;
int Noise_P_Signal;
boolean trigger = true;
float temperature;
float pvs_temperature;
void loop()
{
digitalWrite(2,HIGH);    // Turn on IR LED
delayMicroseconds(500);  // Forward rise time of IR LED
Noise_P_Signal=analogRead(A7);        // Read value from A0 => noise+signal
digitalWrite(2,LOW);     // Turn off IR LED
delayMicroseconds(500);  // Fall time of IR LED
Noise=analogRead(A7);        // Read value from A0 => noise only
Signal = Noise - Noise_P_Signal;
//Serial.print("Noise + Signal = "); Serial.println(Noise_P_Signal);
//Serial.print("Noise ="); Serial.println(Noise);
//Serial.print ("--> Signal ="); Serial.println (Signal);
//temperature = (mlx.get_object_temp()) + error_correction;
//Serial.println(temperature,1);
//delay(100);
if (Signal>Range_sensitivity && Noise >500) //dec. signal to increase rage

  if (trigger == true)
   Serial.println("start");
   digitalWrite(2,LOW); //Turn off IR sensor to avoid interferance. 
   for (int i=1; i<=3; i++)
   {
   temperature = (mlx.get_object_temp()) + error_correction;
   Serial.println(temperature,1);
   delay(150);
   }
  trigger = false; 
}
else
{
  delay(100);
  trigger = true;
  digitalWrite(13,LOW);
  Serial.println("position_error");
}
}

-----------------------------------------------------------------------------------------------------

The error is in the bold line and is written: previous definition of 'class MLX90615'

Unfortunately I'm not very good at programming, but in analog and digital electronics yes. Thank you for your help in solving the problem.

Debasis Parida's picture

Offline

Joined: Aug 22, 2019

Replies: 124

Hi Antonio, It seems there is a conflict in class definition of MLX90615. Check for multiple definition of class. Otherwise kindly share the complete code, to know the exact error you are facing.

Debashis Das's picture

Offline

Joined: Dec 02, 2019

Replies: 109

Download this file and try again

Contactless Smart IR Thermometer

Sourav Gupta's picture

Offline

Joined: Feb 12, 2018

Replies: 360

class MLX90615 {
 public:
  MLX90615(uint8_t i2c_addr = MLX90615_I2C_ADDR);
  void begin();
  uint32_t get_id();
  float get_object_temp();
  float get_ambient_temp();

 private:
  uint8_t i2c_addr_;
  uint16_t read_word16(uint8_t reg);
};

 

Open the #include "MLX90615.h" and try to find the class MLX90615. I think it is allready defined in the MLX90615.h. If it is defined then comment the code in the main source file.

Antonio M.'s picture

Offline

Joined: Sep 03, 2020

Replies: 4

Hi, Parida, Das and Gupta. I tried again to download the file "Contactless Smart IR Thermometer" but I still get the same error. I'm at the point of giving up everything. Since it is a mistake common to many people I think it is appropriate to publish the complete code so that it refers to that, for any resolution of problems. Or make a video explaining step by step what needs to be done. Or do I politely ask those who managed to make this project work to publish the code. I am a teacher and I would like to use this project to detect the temperature of my students entering school. Thanks again for your help
P.s. My programming knowledge is few... Help

I insert in Arduino the .cpp file the .h file and the code present in the site

Debashis Das's picture

Offline

Joined: Dec 02, 2019

Replies: 109

Hi pleas try this link, i have also attached a .hex file in the attachment, if you are having trouble completing it you can also flash the .hex file directly..

Antonio M.'s picture

Offline

Joined: Sep 03, 2020

Replies: 4

Hello Das, thank you for the .hex file. As soon as I can I will try this new file. I've already downloaded the app to my phone and it's all right. I'm going to let you know how it went. Thank you so much and a good day from Italy

Debashis Das's picture

Offline

Joined: Dec 02, 2019

Replies: 109

My pleasure

Antonio M.'s picture

Offline

Joined: Sep 03, 2020

Replies: 4

Hi, finally I tried the code and it went almost all right. The serial monitor always gave "error position". After checking the circuit a thousand times, I notice that there is an error in the code. In the row "Noise_P_Signal = analogRead(A7);// Read value from A0 => noise+signal" the pin is not A7 but A0. I hope it will serve others not to have the error "error position". Thank you all

Debashis Das's picture

Offline

Joined: Dec 02, 2019

Replies: 109

Thank you very much for heads up.