Arduino Tutorials

How to measure the temperature by infrared with the GY-906

Infrared Thermometer

With most sensors you can measure the temperature of the environment – one step further is the GY-906: This sensor measures the temperature of an object from a distance via infrared.And it also measures the ambient temperature at the same time. 🙂

In this tutorial you will learn how to connect the GY-906 and measure temperatures with it.

Bestseller Nr. 1
ARCELI GY-906 MLX90614 ESF-BAA-000-TU-ND Infrarot-Thermometer IR-Sensor für Arduino
  • 1.MLX90614ESF-BAA-000-TU-ND berührungsloses Infrarot-Thermometer zur Verwendung mit (für) Arduino oder jedem Mikrocontroller, der über die I2C-Schnittstelle mit ihm kommunizieren kann.
  • 2.Dieser Sensor wird mit einer Breakout-Platine mit allen für den Betrieb notwendigen Komponenten und zwei Arten von Pins geliefert. Sie sind abgelötet. Bitte geben Sie an, ob Sie das eine oder andere gelötet haben möchten.
  • 3.Es gibt zwei Lötbrücken für die I2C-Schnittstelle, die je nach Anwendung gelötet werden können oder auch nicht, für die meisten Anwendungen jedoch nicht.

How to connect the sensor

You can connect this sensor in no time at all via I²C. Besides Plus and Minus you only need two more connectors for SDA (Data) and SCL (Clock). The corresponding pins on your Arduino are A4 for SDA and A5 for SCL.If you want to learn more about I²C, Wikipedia will help you.

Connect the pins VIN and GND on the sensor with the 5V and GND on the Arduino. Then connect SDA to A4 and SCL to pin A5. That’ s it already.

The code for the GY-906

For your first experiments it is enough to display the temperature in the serial monitor. If this is not good enough for you, you can find out here how to connect a TFT display to the Arduino.

But before you can get started, you need a library for the GY-906. You can install it with your

Search there for Adafruit_MLX90614 and install the library in the latest version:

Library Adafruit_MLX90614

Now you can start: First, include two libraries in your sketch. The one you just loaded to read the sensor data and another one (Wire.h) for communication via I²C.

#include <Adafruit_MLX90614.h>
#include <Wire.h>

Then you create an instance of the library named mlx:

Adafruit_MLX90614 mlx = Adafruit_MLX90614();

In the void setup() function you only start the Serial Monitor and the instance of the library you just created. That’s all you need.

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

Now the heart of your sketch, the void loop() function. Here you let your GY-906 measure the ambient temperature and the temperature of any object in front of the sensor every 500 milliseconds. The results are displayed on the serial monitor:

void loop() {
  Serial.print("Umgebung = "); Serial.print(mlx.readAmbientTempC()); 
  Serial.print("*C\tObjekt = "); Serial.print(mlx.readObjectTempC()); Serial.println("*C");

  Serial.println();
  delay(500);
}

Conveniently, the Adafruit_MLX90614 library has two functions for this purpose, readAmbientTempC() and readObjectTempC(), which you can call and output directly to the serial monitor. The former outputs the ambient temperature, the latter that of the object directly in front of the sensor.

Unlike the popular temperature sensor TMP36 you don’t have to do any conversions from voltage to degrees Celsius.

Here the whole sketch:

#include <Adafruit_MLX90614.h>
#include <Wire.h>

Adafruit_MLX90614 mlx = Adafruit_MLX90614();

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

void loop() {
  Serial.print("Umgebung = "); Serial.print(mlx.readAmbientTempC()); 
  Serial.print("*C\tObjekt = "); Serial.print(mlx.readObjectTempC()); Serial.println("*C");

  Serial.println();
  delay(500);
}

What’s next?

Of course, it’s not a long way from the serial monitor to the display – you can easily create a mobile infrared thermometer with it and a battery.

If you prefer it old school, maybe this analog thermometer is right for you. In this project a TMP36 is used for measuring, but you can easily replace it with the GY-906 after this tutorial.

Letzte Aktualisierung am 2020-11-26 / Affiliate Links / Bilder von der Amazon Product Advertising API

You may also like

Comments are closed.