Quickie: Working with IR (Infra Red) Temperature Sensors – easier than you think!

IR sensors for temperature detection are extremely easy to set up and use with our microcontrollers, only 4 wires needed and two of them of for power! If you’re a video kind of person then here’s the accompanying video, otherwise read on below for more textual instructions!


Affiliate links
Various Amazon links for items shown in the video;
Sensor without shroud: https://amzn.to/46Cl9pY
Sensor with approx 1cm shroud: https://amzn.to/3S7VuBo
Sensor (long shroud): https://amzn.to/47aAXjW (warning expensive)
Arduino Uno: https://amzn.to/3S8rXYk
Arduino Nano: https://amzn.to/3tMzeCH

IR Sensors – How do they work
Just as solar cells convert visible light into a voltage/current, IR sensors convert a different part of the electromagnetic spectrum, namely the Infra-Red part (what a surprise). The more intense the IR energy hitting the sensor the greater the voltage generated. Simple circuitry can then convert this to a value representing this IR energy. As the temperature of an object is directly proportional to the amount and intensity of the IR emitted we can easily determine an objects temperature. That’s the broad “gist” of it all anyway….

The commonly available sensors
Most sensors you will find for sale will be based on the GY-906 sensor and you will find them in different forms as shown below. GY-906 Sensor Collection
The difference you can see is the additional shroud, starting with no shroud to one approx 2cm in height. These enable you to sense greater differences. With no shroud the max range for accurate sensing is around 2cm, beyond this and the sensor picks up to much background radiation, reporting a sort of average of the radiation that is hitting it’s sensor area. The Shrouds help to block out everything else but the objects radiation that you want. The longer the shroud the further away your object can be and report accurate results. The smaller shroud one above is good up to around 12-15cm. So I would imagine the longest shroud is probably good for at least 30cm (although I haven’t got one to test this). I tried making my own shrouds but there is something special about them, homemade ones just weren’t effective. So why not always purchase the one with the longest shroud? Well, 2 reasons, cost and space available. The longest shroud versions are considerably more expensive than the no shroud or lesser shroud versions. You may also have space concerns for your own particular project.

Why use IR instead of another type of sensor? There are a couple of reasons I can think of. First they are none touch, you can sense the temperature of something from a distance (albeit you need the longer shroud). They are also extremely fast compared to say a traditional contact based sensor such as the DS18B20. If you want to monitor fast changing temperatures then this is what you need, the video demo’s this.

Connecting to an MCU The sensor only has 4 connections, 1 for Vcc, 1 for ground and two for connection to an I2C bus. Very simple. Any MCU that supports I2C should be able to work with these devices (as long as a library has been written) as this sensor will work with 3.3v and 5v devices without any adjustment. I wish more sensors were like this! The video describes the connections for Arduino Uno, Nano and ESP32. Here’s a table outlying the connections;
Board connection Uno Nano ESP32
VIN 5v 5v 3v3
GND Gnd Gnd Gnd
SCL SCL A5 Any GPIO*
SCA SDA A4 Any GPIO*

*Virtually all can be used with just a very few exceptions, for example, 34,35,36,39 are input only. Thus page is a good source: https://randomnerdtutorials.com/esp32-pinout-reference-gpios/

Library Using the Arduino IDE search for GY-906 (the hyphen is important) in the libraries manager. At time of writing only one library was available “VEGA_MLX90614 by CDAC”.

Testing With the library installed go to “File->Examples->VEGA_MLX90614->GY906_IR_tempSensor”. The code is very short and easy to follow. Compiling and running will display two temperatures, the ambient temperature and the temp of the radiation hitting your sensor. Yes, you get two temperature sensors. One reports the ambient (surrounding temperature) and the other is the IR sensor. This can help if you want to sense an object that is not ambient, which could be a creature/human. It can also help when calculating an internal body temperature based on skin temp.

Wrap up That completes this quickie. I hope it has been of some use and inspired you to create something with these sensors yourself.

2 Comments

  1. Hey would you mind stating which blog platform you’re using? I’m going to start my own blog in the near future but I’m having a tough time choosing between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your design seems different then most blogs and I’m looking for something unique. P.S Sorry for getting off-topic but I had to ask!

    • No problem, I use WordPress but with a third party theme, I can’t for the life in me remember which one it is now. I’ve used it for around 5 years and had no problems. Hardest thing was adding in some of my own JavaScript once but it could be done. Updates are often and there are loads of plugins for everything I’ve ever needed to do. I’ve no experience with the others so cannot fairly compare. But at moment I see no reason to change.

Leave a Reply

Your email address will not be published.


*