Measure Temperature non-contact with Melexis MLX90614 with NodeMCU D1 Mini over Wifi (using Ajax)

Project Video
Project Details

In this tutorial you will learn how to display temperature in C, F and K on using MLX90614 and ESP8266 NodeMCU and D1 Mini over WiFi.

Chapters of this video

  • 00:45 Introduction
  • 03:54 Preparing Arduin IDE to work with NodeMCU and D1 Mini
  • 06:12 Wiring for MLX90614 with ESP8266 Explained
  • 08:01 Code Explained
  • 10:06 Demonstration with NodeMCU and MLX90614 on Desktop
  • 12:51 Demonstration with NodeMCU and MLX90614 on Mobile Phone
  • 13:43 Demonstration with D1 Mini and MLX90614 on Desktop
  • 14:42 Demonstration with D2 Mini and MLX90614 on Mobile Phone

This video requires the following Tutorial. This code is using Ajax. 

1-Introduciton to MLX906142

Please download the arduino code zip file.




Project Code

  This is a library example for the MLX90614 Temp Sensor
Original Library and code source:

This is Arduino code for MLX90614 to display temperature over Wifi using ESP8266 NodeMCU and D1 Mini
on browser of desktop, tablet or mobile phone. 
this code works without need of connection to the internet (wihtout Ajax). Check the Ajax version from the link above.

Related Videos:
Introdution to MLX90614:
Display temperature from MLX90614 on LCD1602/LCD2004:
Display temperature over WiFi using ESP32 on mobile phone:

   Want to get full explanation of this code
  and need wiring diagram? 
  Purchase My Arduino course on
 * Watch video instructions for this code: 
written by Ahmad Shamshiri on Jun 29, 2020 
 * in Ajax, Ontario, Canada.

 * Get this code and other Arduino codes from
Learn Arduino step by step in structured course with all material, wiring diagram and library
all in once place. Purchase My course on

If you found this tutorial helpful, please support me so I can continue creating 
content like this. You can support me on Patreon

or make donation using PayPal

 *  * This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact.* 
 * This code has been download from
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see .

  Written by Limor Fried/Ladyada for Adafruit Industries.  
  BSD license, all text above must be included in any redistribution

char *typeName[]={"Object: ","Ambient: "};
float tempC, tempF, tempK, tempCA, tempFA, tempKA;
char type='C';//default temperature type C

Adafruit_MLX90614 mlx = Adafruit_MLX90614();


#ifndef STASSID
#define STASSID "Robojax"//your Wifi SSID (case sensitive)
#define STAPSK  "YouTube2020"//your WiFi password

const char *ssid = STASSID;
const char *password = STAPSK;

ESP8266WebServer server(80);
void handleRoot() {
   // MLX90614 wiht ESP8622 with Ajax
 String HTML ="\\\
  \t\nRobojax MLX90614 Infrared Temperature\
 \nhtml,body{\t\nwidth:100%\;\nheight:100%\;\nmargin:0}\n*{box-sizing:border-box}\n.colorAll{\n\tbackground-color:#90ee90}\n.colorBtn{\n\tbackground-color:#add8e6}\n.angleButtdon,a{\n\tfont-size:30px\;\nborder:1px solid #ccc\;\ndisplay:table-caption\;\npadding:7px 10px\;\ntext-decoration:none\;\ncursor:pointer\;\npadding:5px 6px 7px 10px}a{\n\tdisplay:block}\n.btn{\n\tmargin:5px\;\nborder:none\;\ndisplay:inline-block\;\nvertical-align:middle\;\ntext-align:center\;\nwhite-space:nowrap}\n";
    HTML +=".button {\n";
    HTML +=" border: none\;\n  color: white\;\n  padding: 15px 32px\;\n";
    HTML +="  text-align: center\;\n";
    HTML +="  text-decoration: none\;\n";
    HTML +="  display: inline-block\;\n";
    HTML +="  font-size: 25px\;\n";
    HTML +="  margin: 4px 2px\;\n";
    HTML +="  cursor: pointer\;\n";
    HTML +="} \n";
  HTML +="\n\n";
   HTML +="\n\n

Robojax MLX90614 Infrared Temperature

  HTML +="Temperature
  if(type =='C'){
  HTML +="\n";  
  HTML +=typeName[0];
  HTML +=tempC;
  HTML +="°C

  HTML +="\n";  
  HTML +=typeName[1];
  HTML +=tempCA;
  HTML +="°C\n";

  if(type =='F')
  HTML +="\n";  
  HTML +=typeName[0];
  HTML +=tempF;
  HTML +="°F

  HTML +="\n";  
  HTML +=typeName[1];
  HTML +=tempFA;
  HTML +="°F\n";


  if(type =='K')

  HTML +="\n";  
  HTML +=typeName[0];
  HTML +=tempK;
  HTML +="°K

  HTML +="\n";  
  HTML +=typeName[1];
  HTML +=tempKA;
  HTML +="°K\n";

  HTML +="

  HTML +="Get °C\n";
  HTML +="Get °F\n";
  HTML +="Get °K\n";  


  HTML +="\t\n

  server.send(200, "text/html", HTML);  
   // MLX90614 wiht ESP8622 with Ajax  

void handleNotFound() {
   // MLX90614 wiht ESP8622 with Ajax
  String message = "File Not Found\n\n";
  message += "URI: ";
  message += server.uri();
  message += "\nMethod: ";
  message += (server.method() == HTTP_GET) ? "GET" : "POST";
  message += "\nArguments: ";
  message += server.args();
  message += "\n";

  for (uint8_t i = 0; i < server.args(); i++) {
    message += " " + server.argName(i) + ": " + server.arg(i) + "\n";

  server.send(404, "text/plain", message);


void setup() {
   // MLX90614 wiht ESP8622 with Ajax

  Serial.println("Robojax MLX90614 test");  

  WiFi.begin(ssid, password);

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {

  Serial.print("Connected to ");
  Serial.print("IP address: http://");

//multicast DNS   // Tutorial
  if (MDNS.begin("robojaxESP8266")) {
    Serial.println("MDNS responder started");
    Serial.println("access via http://robojaxESP8266");

  server.on("/", handleRoot);
  server.on("/c", displayTempC);  
  server.on("/f", displayTempF);  
  server.on("/k", displayTempK);      
  server.on("/inline", []() {
    server.send(200, "text/plain", "this works as well");
  Serial.println("HTTP server started");  
     // MLX90614 wiht ESP8622 

void loop() {
     // MLX90614 wiht ESP8622 
  //Robojax Example for MLX90614



       // MLX90614 wiht ESP8622 

 * @brief returns temperature or relative humidity

 * @return returns one of the values above
 * Usage: to get Fahrenheit type: getTemp('F')
 * to print it on serial monitor Serial.println(getTemp('F'));
 * Written by Ahmad Shamshiri on Mar 30, 2020. 
 * in Ajax, Ontario, Canada
void getTemp()
   // MLX90614 Code

    tempC = mlx.readObjectTempC();//in C object
    tempCA = mlx.readAmbientTempC();

    tempF = mlx.readObjectTempF(); //Fah. Object
    tempFA = mlx.readAmbientTempF();//Fah Ambient

    tempK = tempC + 273.15;// Object Kelvin
    tempKA =  tempCA + 273.15;//Ambient Kelvin

    // MLX90614 Code

void displayTempC()
     // MLX90614 wiht ESP8622 
  type ='C';


void displayTempF()
     // MLX90614 wiht ESP8622 
 type ='F';


void displayTempK()
     // MLX90614 wiht ESP8622 
  type ='K';