Building your own IR Thermometer Part 1
- February 3rd, 2010
- Posted in Electronics projects
- Write comment
How about building your own infra-red (IR) Thermometer?
Instead of buying a finished product, you might be interested in building your own IR Thermometer instead. This way, you can learn how it works and you are able to design it exactly the way you want it to be. For example, how about building wireless sensors which transmit data to a central receiver unit?
In this article, I’ll show you the basics. Components which I’ll be using for this are:
- IR temperature sensor: I’ll be using the MLX90614 (this version to be precise). It has a range from -70 up to +380 C and a resolution of 0.02 C.
- Microcontroller: I’ll be using a 8-bit microcontroller from Microchip: PIC16F690, but the program included in this article can easily be ported to any other 8bit microcontroller.
- Display: You can use any HD44780 compatible display; I’ll be using the EAW162B-N3LW
You will also need a programmer (I recommend using the PICKit2) to write your program into the micro-controller and an oscilloscope might came in handy for analyzing and debugging. For source code development, I used the Microchip MPLAB IDE, which you only need if you want to compile your own binary.
The test setup
To test the sensor and the assembly code, I use the following setup. A 9V battery is used for the power supply and the 78L05 voltage regulator converts this to a 5V power rail. If you rather want to use a 5V supply directly, you can of course skip the regulator. For the pull-up resistors R1 and R2 I choose 10KOhm. R3 is a 10KOhm potentiometer which is used to regulate the display contrast. R4 is needed for the LED background light built into the LCD display planet. You should check the datasheet of your display for the correct value. C1 and C2 are for filtering and have a value of 100nF.
(Please note that the display module shown in the drawing is not the same one which I used for my setup)
Reading the temperature from the sensor
The IR sensor, which is a digital sensor with it’s own microcontroller on board, provides two temperature readings: A) the sensors own (body) temperature and B) the object-in-sight temperature, measured using infra-red. For this project, I’ll be reading and showing both values.
The sensor (when not in sleep mode) will constantly measure the current temperature and store the result into it’s own internal memory. The already calibrated and ready to use temperature measurements can then be fetched from the sensor’s memory using the SMBus protocol. Using the sensor’s documentation and my oscilloscope, I developed the assembly code needed to read the measurements from the sensor. The source-code for this is provided below and is located in the smbus.asm module.
Converting the data to degrees Celcius
In order to convert the temperature values received from the sensor to degrees celcius, the raw value has to be multiplied by 0.02 according to the documentation. The result is the temperature in degrees Kelvin with two decimal precision. Substract 273.15 from that and you have the temperature in degrees celcius. To do this calculation on the microcontroller, I first subtract 27315 (273.15 x 100) from the raw value and then divided the result by 100. This way, I don’t have to worry about the comma until the very last step. The code for this conversion can be found in main.asm. The code makes use of this excellent assembly math library.
Showing the result
I first sent the readings via the serial port (using rs232) to my PC, but I quickly realized that using this method doesn’t really promote the idea of making a portable thermometer. So I replaced the rs232 output with an LCD display (HD44780 based) instead. Both the rs232 code and the LCD code is included in the source-code package though and can be found in the rs232.asm and display.asm modules.
Main loop
Now, to see the thermometer in action, I created a tiny main loop in main.asm which clues together the above mentioned modules. It basically configures the microcontroller after power-on-reset and then goes into an infinitive loop performing: A) 1 second delay, B) read latest temperature from the sensor using the smbus.asm module, C) convert to degrees celcius and finally D) show the value on the display using display.asm module.
The source & binary
Download the source code and the binary hex file (compiled for the PIC16F690) here:
Sensor in action:

Amiable brief and this mail helped me alot in my college assignement. Say thank you you seeking your information.
Oh mankind that you so much for your send at beneficial time. It helped me in my assignment. Thanks Alot
Hello!
I used made similar thermometer and used your code to make it working. Now I would like to add en function like alarm: To PORTA,1 connected LED. If the object’s temperature is ;ver 40 degree LED lights up. Could you please help me I tried to make “if” for variable Temp, but it doesn’t work.
I would appreciate if you explain for me which variable contain data of T i Celsius.
Regards
Inna K
thank you for sharing this knowledge.
this blog is very thoughtful and selfless, not afraid of sharing to others what they have. thank you so much
Hi! nice project!
i have one question. How did u configure the Configurations Bits in MPLAB?? XT? RC?
thxs
Thank you so much! This is really helping me in one of my college assignments. Really appreciate you sharing!
Hi, thank you very much for posting this. I was hoping you could help me answer a question..
I am want to implement three of these sensors using the same bus line. Could you please help me find how to change the address from the factory default (0x5A)?
Thank you very much.
Sincerely,
Nick
Hi Nick,
What you want to do is to change the devices SMBus address (also called slave address). This address is stored in the device’s EEPROM memory at memory-address: 0x00E. According the the datasheet, this memory location is writable. So I guess you just take a single device on your SMBus first and change it’s the SMBus address by sending a WRITE command to EEPROM address 0x00E containing the new SMBus address. Once changed, you can then using it together with other devices. Have a look at paragraph 8.4.3.1.2 in the datasheet.
hi
at first i want to thank you very much for this project . a lot of thank .
second i want to ask about the way you convert the temperature values received from the sensor to degrees celcius . as what i study about this project u must take some voltage reading from the sensor and find the relation between the voltage u get from sensor an the body temp then u programming the pic as the relation u get
third : the file with the name documentation could not be open
if u can to send it to me plz
hi ibrahim,
The datasheet contains an example of how to convert the temperature to degrees celsius. It’s very easy, because the sensor provides the temperature already in Kelvin. See chapter 8.7.2 in the datasheet.
Hope this helps.
@admin
thank u very much
i am sory for asking u another question i t is about the distanco of the object in front of the sensor . so if it was far it will give a wrong tempreture . so what is the relation between the reading temp on the LCD and the distance
and thank again
Hi ibrahim.
Please check out the datasheet of the sensor. If I remember correctly, it will give you the average temperature of all objects which are currently in the field-of-view.
hi friend
at first i am realy need to thank u very much…
realy i was study the contactless thermometer depending on infrared radiated from the bodies but my study was for another sensor and it was analog….
but now i decided to make the same project which u made here…
now i have a prpblem of getting the component … especialy the pic … i have visit the website u put for the pic but i don’t know the package of the pic . then also if u have a website that i can buy the LCD display from it plz send it to me.
thank u
Hi Sebastian,
You mentioned above a version of this circuit
where the o/p was into a PC via RS232.
I have right now a urgent need for such
a circuit, It will save me time and effort
if you could send me the code + diagram
for MLX90614-> RS232 O/P asap.
to…
mario.peiris@gmail.com
Many thanks for your excellent work.
Kind Regards,
Mario Peiris.
Hey there,
Thanks for sharing us the project. It is very cool. I’m on the same project too. However I could not a digital like the MLX90614 which would make my life much easier.
I wonder if there is a way that we could use analog detector like ztp135sr and using amplifier like the LT1126 to get the gain, the convert to digital with the TMEGA328 to create the it? would the code work the same with this combination?
How would u connect it thought? I’ve read couple articles but none would really show how to hook it up.
Thanks you very much.
Hey
Nice work,
could you tell me what distances could you measure the temperature over with MLX90614 ?
please,,,How can I transmit data which were displayed on LCD from PIC 16F690 by Bluetooth transmitter to a mobile phone ???
please,,,if you can provide me with code and the pins connections between bluetooth transmitter and the PIC 16F690 , and which types of bluetooth transmitters do you prefer to use?,,, and what is the name of the program which I have to download to my mobile to receive data.
Thank you very much
Hi, thank you for the circuit.
May I ask if your code is compatible with the display module in the fig.? Do I need to change anything?
yes, the provided code speaks to the display module shown in the picture / video.
Hi,
I am working on a similar project, but I am using MLX90615 with midical accuracy of 0.02C .
I believe that the operation of both sensors is very similar.
I am using PIC18F4550 and programming in C. I managed to interface the sensor and PIC. When a “read” is requested by the PIC, the sensor returns three bytes according to the datasheet. I managed to get those three bytes and display them continuously on GLCD.
The problem is that none of these values is the temperature ! . I have tried heating up the sensor, but the values do not change.
( I am sure that I requested the “read” from the correct register (0×07) for To)
I have spent a lot of time trying to figure out what is wrong. The conclusion I have arrived to is:
Since the PIC and the sensor can talk, the problem is not from the connection of the two devices, because otherwise there will be no communication. Also, the problem is not form the code because it is so straight forward. So, the sensor must be damaged !.
I really hope I am wrong because the sensor is new.
I would really appreciate it if you can help me figure out what could be wrong.
Regards,
Hi,
Thanks for sharing us the project.
I want to buy other similar sensor, but I need measurement to 2000 C.
Do you know similar sensor to MLX90614
Thanks.
@jun
Hey,
I am working on this project of designing an Infrared Thermometer with the same components and microcontroller. Still having some issues, would u b able to help us with some question.
Thank You
Annam
Jei bro….
can u help me?
I have the mlx90614 but i have no idea how to star to use this device…
i dont know how to make some test whit this device!!
Pleas help me im getting crazy
what program do you use to open the file called ir_sensor?
tnx!!!
The hex file is the firmware for the pic.
this program works with mikroc?
im using this program with a bigpic6!!
Hi I have melexis 90614 and an atmega16 microcontroller, I want to connect him to pc via RS232 can you hel me?
hi, Can i know if the source code is compatible with LPC1769 as well?
how to send data to serial port rs232 . can u help me in a project
hey nice work ..
i am also using mlx90614esf-dci on avr atmega32 . but getting problem in reading temperature . the algorithm i used is
i2c_init();
i2c_start();
i2c_write(180); //as the address is 5A(hex)==90==1011010
//180==10110100(slave address + 0 (write))
i2c_write(7); // command to acess Ram location 07(hex)==7(dec)
i2c_start(); //repeat start
i2c_write(181); //(slave address + 1(read))
a=i2c_read();
b=i2c_read();
c=i2c_read();
i2c_stop();
the functions are correct because i have copied it from MAZIDI`s book .
now the issue is , as i call i2c_read() first time then slave doesnt ACK .
my questions are
-are start and repeat start same ??
-am i using right slave address ??(its a new sensor)
and please tell me wherever you find i m wrong ..
others could also help me .
altaf1148@hotmail.com
waiting for reply
This code would work for a PIC16F1936 correct?
Hey please is it possible to send me the cc code?