MLX90614 Infrared temperature sensor with Arduino & LoRa
Arduino MLX90614 and Lora Based wireless temperature monitoring system
Table of Contents
MLX90614 with Arduino & LoRa:
MLX90614 Infrared temperature sensor with Arduino & LoRa– In this article, you will learn how to make a long-range wireless temperature monitoring system using MLX90614 Infrared contactless temperature sensor, a pair of Arduino boards, SX1278 LoRa Transceiver modules, SSD1306 I2C supported Oled display module, a potentiometer, and a 5V buzzer.
This is my third article on the MLX90614 Temperature sensor and is entirely based on my previous two tutorials. In my first article on the MLX90614, I covered the extreme basics including the MLX90614 IR temperature sensor technical specifications, its calibration using the Emissivity value, how to use it with Arduino, and display the temperature readings on the Oled display module. So, if you are just getting started with the MLX90614 non-contact infrared temperature sensor then I must say, you should definitely read my first article on the MLX90614 temperature sensor.
In my 2nd article, I used the MLX90614 infrared temperature sensor with the Nodemcu ESP8266 WiFi module. So, if you are thinking of monitoring the temperature from any part of the world using the MLX90614 temperature sensor then you should read my 2nd article. Now, let’s get back to our original topic.
Here is a prototype model of my long-range wireless temperature monitoring system. On the right side is the transmitter, along which the MLX90614 temperature sensor and SX1278 LoRa transceiver module are connected. The Arduino reads the MLX90614 temperature Sensor and sends the temperature readings to the remote side Arduino using the SX1278 LoRa module.
And on the Left side is the Receiver. It has been connected with a Potentiometer, an Oled display module, a 5V buzzer, and an SX1278 LoRa transceiver module. We use the potentiometer to set the threshold value. This way when the temperature exceeds the set value the Buzzer will turn ON. Now, let’s kick off our practical demonstration.
I have powered up the transmitter as well as the receiver’s side. You can view temperature readings in Celsius along with the set value on the Oled display module. Right now, the buzzer is OFF because the temperature reading is below the set value. Now, let’s go ahead and measure the temperature.
You can see, on the Oled display, I have changed the set value “threshold value”, when the MLX90614 temperature sensor was focused on the fire, the temperature increased and at the same time the buzzer was also turned ON. For the practical demonstration watch the video tutorial given at the end of this article.
Since this project is based on the Long-range LoRa transceiver modules, and the MLX90614 itself is a non-contact temperature sensor; so, because of these outstanding features this project can be used for monitoring the temperature of any particular object or human, etc. All you need is to focus the sensor and set the threshold value.
The receiver side is completely portable, you can keep it with yourself, or you can fix it inside your room, or office. It obviously depends on you how you plan to use it. I am sure by now, you might have got an idea of how does this system work. So, without any further delay let’s get started!!!
Amazon Links:
Arduino Nano USB-C Type (Recommended)
MLX90614 Infrared Temperature Sensor
*Disclosure: These are affiliate links. As an Amazon Associate I earn from qualifying purchases.
MLX90614 Infrared Temperature Sensor:
This sensor consists of four pins as shown in the figure.
- VCC
- GND
- SDA
- SCL
Specification
SEN0206 (MLX90614-BBC)
- Operating Voltage: 3.3V – 5V
- Operating Current: 1.2mA
- Temperature: -70.01℃ to +382.19℃, (0.01 ℃ resolution)
- Interface Type: IIC
- Interface Line Sequence: VCC, GND, SCL, SDA
- FOV: 35°
- Dimensions: 31.5*18 mm/1.24 x 0.7 inches
SEN0263 (MLX90614-DCI)
- Operating Voltage: 3.3V-5V
- Operating Current: 1.2mA
- Temperature: -70.01℃ to +270℃,(0.01 ℃ resolution)
- Interface Type: IIC
- Interface Line Sequence: VCC,GND,SCL,SDA
- FOV: 5°
- Dimensions: 31.5*18mm/1.24 x 0.7 inches
SX1278 LoRa Module:
In this project we are using the same SX1278 LoRa modules for the transmitter and receiver. In order to use it as a receiver and transmitter we will make change in the code. Lora SX1278 long distance wireless transceiver module integrates Semtech RF transceiver chip SX1278, which adopts LoRa TM Spread Spectrum modulation frequency hopping technique. The features of long distance and high sensitivity (-139dBm) make this module perform better than FSK and GFSK module. Multi-signal won’t affect each other even in crowd frequency environment; it comes with strong anti-interference performance. This module is 100mW and ultra-small size, widely used in AMR , remote industrial control filed.
Features:
- Frequency Range: 868 / 915 MHz
- Sensitivity up to -139dBm @Lora
- Maximum output power: 20 dBm
- 13mA@receiver mode
- Sleep current <200 nA
- Data transfer rate: @FSK,1.2-300 Kbps
- @Lora TM, 0.018-37.5 Kbps
- Lora TM, FSK, GFSK & OOK Modulation mode
- Built-in ESD Protection
- 127 dB Dynamic Range RSSI
- Packet engine up to 256 bytes with FIFO and CRC
- Hopping frequency
- Built-in temperature sensor and low battery indicator
- Excellent blocking immunity
- Operating Temperature Range:-40 ~ + 85 °C
Applications:
- Remote control
- Remote meter reading
- Home security alarm and remote keyless entry
- Industrial control
- Home automation remote sensing
- Individual data records
- Toys control
- Sensor network
- Tire pressure monitoring
- Health monitoring
- Wireless PC peripherals
- Tag reading and writing
MLX90614, Arduino, & LoRa; Tx Side:
This is the transmitter side circuit diagram. The VCC of the LoRa module is connected with 3.3V of the Arduino. The MISO Pin of the LoRa module is connected with the Arduino pin 12. The MOSI pin is connected with pin 11. The SCK pin of the LoRa module is connected with pin 13. The NSS pin is connected with the Arduino’s pin 10 and the ground pin of the LoRa module is connected with the Arduino’s GND.
The VCC and GND pins of the MLX90614 Infrared temperature sensor are connected with the 3.3V and GND pins of the Arduino. While the SDA and SCL pins of the MLX90614 temperature sensor are connected with the A4 and A5 pins of the Arduino. A4 is the SDA and A5 is the SCL.
On the left side, you can see a 5V regulated power supply based on the LM7805 voltage regulator. We use this regulated 5 volts to power up the Arduino and all the other electronics.
MLX90614, Arduino, & LoRa; Rx Side:
This is the receiver side circuit diagram. The Lora module connections with the Arduino and the 5V regulated power supply wiring remain exactly the same.
The SDA and SCL or SCK pins of the SSD1306 Oled display module are connected with the A4 and A5 pins of the Arduino. While the VCC and GND pins of the Oled display module are connected with the Arduino’s 3.3 volts and GND pins.
A potentiometer is connected with the Analog pin A0 of the Arduino.
Digital pin D3 on the Arduino is used to control the 5V buzzer. We use a 10K ohm resistor and 2n2222 NPN transistor to control the buzzer. The 10K ohm resistor and transistor make the driver circuit. Now, let’s take a look at the programming.
Wireless temperature monitoring Programming:
This Arduino, LoRa, and MLX90614 sensor based wireless temperature monitoring system is based on two programs. This program is written for the transmitter side, whereas this program is written for the receiver’s side.
Before, you start the programming, first of all, make sure you download all the necessary libraries.
First of all we will install the MLX90614 library for which we will click on the library manager and write MLX90614 and install the library.
You will also need libraries for the SSD1306 Oled display module.
Arduino, LoRa, & MLX90614 Tx Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
//Lora MLX Transmitter arduino nano #include <SPI.h> // include libraries #include <LoRa.h> #include <DFRobot_MLX90614.h> DFRobot_MLX90614_IIC sensor; // instantiate an object to drive our sensor String outgoing; // outgoing message byte msgCount = 0; // count of outgoing messages byte MasterNode = 0xFF; byte Node1 = 0xBB; float ambientTemp; float objectTemp; float ftemp; long lastSendTime = 0; // last send time int interval = 50; // interval between sends String Mymessage = ""; void setup() { Serial.begin(9600); // initialize serial if (!LoRa.begin(433E6)) { Serial.println("LoRa init failed. Check your connections."); while (true); // if failed, do nothing } while( NO_ERR != sensor.begin() ){ Serial.println("Communication with device failed, please check connection"); delay(3000); } // Serial.println("LoRa init succeeded."); sensor.enterSleepMode(); delay(50); sensor.enterSleepMode(false); delay(200); } void loop() { if (millis() - lastSendTime > interval) { ambientTemp = sensor.getAmbientTempCelsius(); /** * get temperature of object 1, unit is Celsius * return value range: -40 C ~ 85 C */ objectTemp = sensor.getObjectTempCelsius(); // print measured data in Celsius Serial.print("Ambient celsius : "); Serial.print(ambientTemp); Serial.println(" C"); Serial.print("Object celsius : "); Serial.print(objectTemp); Serial.println(" C"); // print measured data in Fahrenheit Serial.print("Ambient fahrenheit : "); Serial.print(ambientTemp*9/5 + 32); Serial.println(" F"); ftemp=objectTemp*9/5 + 32; Serial.print("Object fahrenheit : "); Serial.print(ftemp); Serial.println(" F"); Mymessage = Mymessage + ambientTemp +"," + objectTemp + "," + ftemp; sendMessage(Mymessage,MasterNode,Node1); delay(100); Mymessage = ""; //Serial.println("Sending " + message); lastSendTime = millis(); // timestamp the message interval = random(50) + 100; } } void sendMessage(String outgoing, byte MasterNode, byte otherNode) { LoRa.beginPacket(); // start packet LoRa.write(MasterNode); // add destination address LoRa.write(Node1); // add sender address LoRa.write(msgCount); // add message ID LoRa.write(outgoing.length()); // add payload length LoRa.print(outgoing); // add payload LoRa.endPacket(); // finish packet and send it msgCount++; // increment message ID } |
I developed this code by combining the codes of my previous two projects. So, for a detailed explanation read my article on the LoRa SX1278 two-way communication, and my getting started video on the MLX90614 temperature sensor.
I didn’t change anything, I am using the same LoRa nodes addresses.
The code inside the setup() function remains exactly the same. I am using the same code which I previously used for reading the MLX90614 temperature sensor. This time I am sending the temperature readings using the LoRa transceiver module. I must remind you once again, if you want to learn things in detail then you should watch my other videos on LoRa and MLX90614 temperature sensor. Now, let’s take a look at the receiver’s side programming.
Arduino, LoRa, & MLX90614 Rx Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
/* LoRa MLX receiver */ #include <SPI.h> // include libraries #include <LoRa.h> #include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 64 // OLED display height, in pixels // Declaration for an SSD1306 display connected to I2C (SDA, SCL pins) #define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin) Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); byte MasterNode = 0xFF; byte Node1 = 0xBB; String SenderNode = ""; String outgoing; // outgoing message byte msgCount = 0; // count of outgoing messages String incoming = ""; float ambientTemp; float objectTemp; float ftemp; int pot1=A1; int pretemp; //this variable is use to set the value of the temperature int buzzer=4; int potvalue; long lastSendTime = 0; // last send time int interval = 50; // interval between sends void setup() { Serial.begin(9600); // initialize serial if (!LoRa.begin(433E6)) { // initialize ratio at 915 MHz Serial.println("LoRa init failed. Check your connections."); while (true); // if failed, do nothing } // Serial.println("LoRa init succeeded."); display.begin(SSD1306_SWITCHCAPVCC, 0x3C); delay(2000); display.clearDisplay(); display.setTextColor(WHITE); } void loop() { if (millis() - lastSendTime > interval) { potvalue = analogRead(pot1); pretemp = map(potvalue,0,1023,-70,383); // To set the temperature value // parse for a packet, and call onReceive with the result: lastSendTime = millis(); // timestamp the message interval = random(50) + 100; // 2-3 seconds } onReceive(LoRa.parsePacket()); } void onReceive(int packetSize) { if (packetSize == 0) return; // if there's no packet, return // read packet header bytes: int recipient = LoRa.read(); // recipient address byte sender = LoRa.read(); // sender address if( sender == 0XBB ) SenderNode = "Node1:"; byte incomingMsgId = LoRa.read(); // incoming msg ID byte incomingLength = LoRa.read(); // incoming msg length while (LoRa.available()) { incoming += (char)LoRa.read(); } if (incomingLength != incoming.length()) { // check length for error //Serial.println("error: message length does not match length"); ; return; // skip rest of function } // if the recipient isn't this device or broadcast, if (recipient != Node1 && recipient != MasterNode) { // Serial.println("This message is not for me."); ; return; // skip rest of function } // if message is for this device, or broadcast, print details: //Serial.println("Received from: 0x" + String(sender, HEX)); //Serial.println("Sent to: 0x" + String(recipient, HEX)); //Serial.println("Message ID: " + String(incomingMsgId)); // Serial.println("Message length: " + String(incomingLength)); // Serial.println("Message: " + incoming); //Serial.println("RSSI: " + String(LoRa.packetRssi())); // Serial.println("Snr: " + String(LoRa.packetSnr())); // Serial.println(); String q = getValue(incoming, ',', 0); String r = getValue(incoming, ',', 1); String s = getValue(incoming, ',', 2); ambientTemp = q.toFloat(); objectTemp = r.toFloat(); ftemp = s.toFloat(); display.clearDisplay(); display.setCursor(25,0); display.setTextSize(1); display.setTextColor(WHITE); display.println(" Temperature"); display.setCursor(10,20); display.setTextSize(2); //display.print("C: "); display.print(objectTemp); display.print((char)247); display.print("C"); display.setCursor(10,45); display.setTextSize(2); display.print("ST: "); display.print(pretemp); display.display(); if(objectTemp>pretemp) { digitalWrite(buzzer,HIGH); } else { digitalWrite(buzzer,LOW); } incoming = ""; } String getValue(String data, char separator, int index) { int found = 0; int strIndex[] = { 0, -1 }; int maxIndex = data.length() - 1; for (int i = 0; i <= maxIndex && found <= index; i++) { if (data.charAt(i) == separator || i == maxIndex) { found++; strIndex[0] = strIndex[1] + 1; strIndex[1] = (i == maxIndex) ? i+1 : i; } } return found > index ? data.substring(strIndex[0], strIndex[1]) : ""; } |
Maximum of the code I have already explained in my previous videos. The only addition is that, this time I am using the potentiometer to select the threshold value. I simply read the potentiometer and then I map its value to define the range.
The temperature reading received from the transmitter side is printed on the Oled display module and is also compared with the set value and then accordingly the buzzer is turned ON or turned OFF. So, that’s all about the programming.