Infrared Temperature Sensor

I purchased a MLX90614ESF-BAA infrared sensor from Sparkfun. I used the hardware I2C support to read both the infrared object temperature and the ambient temperature registers. The sensor works very well. The wiring details are shown in the product datasheet. I have the sensor mounted about 15 feet from a Cerbuino. I had to use shielded cable to get the sensor to work at this distance. The sensor allows you to set the emissivity to get accurate measurements off different surfaces. I have not set values in the sensor yet.

3 Likes

Ok :wink:

Is there a hidden question in your post, or are you just happy and wanted to share your success? :think:

I am happy and wanted to let the community know about a sensor that is easy to use and performs well. The hardware I2C made it possible for me to get the sensor working pretty quickly. I am not an electronics guy so gadgeteer and .netmf have made it possible for me to deploy a variety of sensors.

1 Like

Exactly what Gadgeteer is about. Good job!

Awsome, do you have code to share?

Here is the code I used to talk to the infrared sensor. I lifted this right out of the documentation for I2C. All I had to change was the address, the communication frequency, and the registers I wanted to read.

I found the address by reading all the addresses up to 127. 0 and 90 worked. The documentation for the sensor gave me the frequency of 100 kHz as well as the two registers, 6 and 7, for temperature values.

Note that the temperature values come out with MSB first and LSB second.

using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Presentation.Shapes;
using Microsoft.SPOT.Touch;
using System.Text;

using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;

namespace IR_Thermometer_I2C
{
    public partial class Program
    {
        static I2CDevice.Configuration con = new I2CDevice.Configuration(90, 100);
        static I2CDevice tempI2C = new I2CDevice(con);  

        void ProgramStarted()
        {
            Debug.Print("Program Started");
            GT.Timer timer = new GT.Timer(1000);
            timer.Tick += new GT.Timer.TickEventHandler(timer_Tick);
            timer.Start();
        }

        void timer_Tick(GT.Timer timer)
        {
            TempMeas();
        }

        void TempMeas()
        {
            // Create transactions
            // First transaction is writing the "read command"
            // Second transaction is reading the data
            I2CDevice.I2CTransaction[] xActions = new I2CDevice.I2CTransaction[2];

            // create write buffer (we need one byte) value of 7 indicate we will read Register 7 for object temperature
            byte[] RegisterNum = new byte[1] { 7 };
            xActions[0] = I2CDevice.CreateWriteTransaction(RegisterNum);
            // create read buffer to read the register - could read 3 bytes with the third byte containing error information
            byte[] RegisterValue = new byte[2];
            xActions[1] = I2CDevice.CreateReadTransaction(RegisterValue);

            // Now we access the I2C bus using a timeout of one second 
            // if the execute command returns zero, the transaction failed (this 
            // is a good check to make sure that you are communicating with the device correctly
            // and dont have a wiring issue or other problem with the I2C device)
            if (tempI2C.Execute(xActions, 1000) == 0)
            {
                Debug.Print("Failed to perform I2C transaction");
            }
            else
            {
                double objtemp = ((((RegisterValue[1] & 0x007f) << 8) + RegisterValue[0]) * 0.02) - 0.01;
                Debug.Print("Object temperature = " + objtemp.ToString("F2") + " K");
            }
            // create write buffer (we need one byte) value of 6 indicate we will read Register 6 for ambient temperature
            RegisterNum = new byte[1] { 6 };
            xActions[0] = I2CDevice.CreateWriteTransaction(RegisterNum);
            // create read buffer to read the register
            RegisterValue = new byte[2];
            xActions[1] = I2CDevice.CreateReadTransaction(RegisterValue);
            if (tempI2C.Execute(xActions,1000) ==0)
            {
                Debug.Print("Failed to perform I2C2 transaction");
            }
            else
            {
                double ambtemp = ((((RegisterValue[1] & 0x007f) << 8) + RegisterValue[0]) * 0.02) - 0.01;
                Debug.Print("Ambient temperature = " + ambtemp.ToString("F2") + " K");
            }
        }
    }
}
1 Like

You can add it to code share. That’s where anyone would be looking for this.

1 Like

Do I hear a possible IR Temperature Gadgeteer Module coming??