Measure Temperature non-contact with Melexis MLX90614 with NodeMCU D1 Mini over Wifi (Ajax)
Measure Temperature non-contact with Melexis MLX90614 with NodeMCU D1 Mini over Wifi (Ajax)
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
1-Introduciton to MLX906142Browser Screenshot Gallery
Click on the images below:
Resources for this sketch
- MLX90614 with ESP8266 without Ajax
- Adafruit MLX90614 Library (from GitHub)
- Adafruit MLX90614 Library (from Robojax)
- Melexis MLX90614 Datasheet (pdf)
- Melexis Website Official Web Site
- Robojax Crash Course on Arduino: Learn Arduino in 30 Minutes (code and video)
- Robojax Arduino Course on Udemy
- Get Early Access to my videos via Patreon
/***************************************************
This is a library example for the MLX90614 Temp Sensor
Original Library and code source: https://github.com/adafruit/Adafruit-MLX90614-Library
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 needs your router to be connected to the Internet in order for Ajax to work.
if your router is not connected to the internet then use the other code linked in this page.
Related Videos:
Introdution to MLX90614: https://youtu.be/cFDSqiEIunw
Display temperature from MLX90614 on LCD1602/LCD2004: https://youtu.be/_iO2L4P_irw
Display temperature over WiFi using ESP32 on mobile phone:https://youtu.be/HpsvNIAtjm4
Want to get full explanation of this code
and need wiring diagram?
Purchase My Arduino course on Udemy.com http://robojax.com/L/?id=62
*
* Watch video instructions for this code: https://youtu.be/OuD7K_f7hDg
updated/written by Ahmad Shamshiri on Mar 30, 2020 at 21:51
* in Ajax, Ontario, Canada. www.robojax.com
*
* Get this code and other Arduino codes from Robojax.com
Learn Arduino step by step in structured course with all material, wiring diagram and library
all in once place. Purchase My course on Udemy.com http://robojax.com/L/?id=62
If you found this tutorial helpful, please support me so I can continue creating
content like this. You can support me on Patreon http://robojax.com/L/?id=63
or make donation using PayPal http://robojax.com/L/?id=64
* * 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 Robojax.com
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
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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 <https://www.gnu.org/licenses/>.
Origin
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, all text above must be included in any redistribution
****************************************************/
#include <Wire.h>
#include <Adafruit_MLX90614.h>
char *typeName[]={"Object: ","Ambient: "};
float tempC, tempF, tempK, tempCA, tempFA, tempKA;
char *url[] ={"/c", "/f", "/k"};
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#ifndef STASSID
#define STASSID "Robojax"
#define STAPSK "YouTube2020"
#endif
const char *ssid = STASSID;
const char *password = STAPSK;
ESP8266WebServer server(80);
void handleRoot() {
//Robojax.com MLX90614 wiht ESP8622
String HTML ="<!DOCTYPE html>\
<html>\
<head>\
<title>Robojax MLX90614 Infrared Temperature</title>\
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\
<style>\
html,body{
width:100%\;
height:100%\;
margin:0}
*{box-sizing:border-box}
.colorAll{
background-color:#90ee90}
.colorBtn{
background-color:#add8e6}
.angleButtdon,a{
font-size:30px\;
border:1px solid #ccc\;
display:table-caption\;
padding:7px 10px\;
text-decoration:none\;
cursor:pointer\;
padding:5px 6px 7px 10px}a{
display:block}
.btn{
margin:5px\;
border:none\;
display:inline-block\;
vertical-align:middle\;
text-align:center\;
white-space:nowrap}
";
HTML +=".button {
";
HTML +=" border: none\;
color: white\;
padding: 15px 32px\;
";
HTML +=" text-align: center\;
";
HTML +=" text-decoration: none\;
";
HTML +=" display: inline-block\;
";
HTML +=" font-size: 25px\;
";
HTML +=" margin: 4px 2px\;
";
HTML +=" cursor: pointer\;
";
HTML +="}
";
HTML +="</style>
";
HTML +="<script src=\"https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js\"></script>
";
HTML +="<script>
";
HTML +="$(document).ready(function(){
";
HTML +=" $(\"\#tempC\").click(function(){
";
HTML +=" $(\"\#div1\").load(\"\/c\")\;
";
HTML +=" })\;
";
HTML +=" $(\"\#tempF\").click(function(){
";
HTML +=" $(\"\#div1\").load(\"\/f\")\;
";
HTML +=" })\;
";
HTML +=" $(\"\#tempK\").click(function(){
";
HTML +=" $(\"\#div1\").load(\"\/k\")\;
";
HTML +=" })\;
";
HTML +="})\; </script>
";
HTML +="</head>
<body>
<h1>Robojax MLX90614 Infrared Temperature </h1>
";
HTML +="<span style=\"font-size: 28px\">Temperature</span><br/>
";
HTML +="<div id=\"div1\"><h2>Temp</h2></div>
";
HTML +="<button id=\"tempC\" class=\"button\" style=\"background-color: #4CAF50\">Get °C</button>
";
HTML +="<button id=\"tempF\" class=\"button\" style=\"background-color: #4389fa\">Get °F</button>
";
HTML +="<button id=\"tempK\" class=\"button\" style=\"background-color: #fa5e43\">Get °K</button>
";
HTML +="
</body>
</html>
";
server.send(200, "text/html", HTML);
//Robojax.com MLX90614 wiht ESP8622
}//handleRoot()
void handleNotFound() {
//Robojax.com MLX90614 wiht ESP8622
String message = "File Not Found
";
message += "URI: ";
message += server.uri();
message += "
Method: ";
message += (server.method() == HTTP_GET) ? "GET" : "POST";
message += "
Arguments: ";
message += server.args();
message += "
";
for (uint8_t i = 0; i < server.args(); i++) {
message += " " + server.argName(i) + ": " + server.arg(i) + "
";
}
server.send(404, "text/plain", message);
//Robojax.com MLX90614 wiht ESP8622
}//handleNotFound()
void setup() {
//Robojax.com MLX90614 wiht ESP8622
Serial.begin(115200);
Serial.println("Robojax MLX90614 ESP8266 test");
mlx.begin();
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: http://");
Serial.println(WiFi.localIP());
//multicast DNS //Robojax.com 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");
});
server.onNotFound(handleNotFound);
server.begin();
Serial.println("HTTP server started");
//Robojax.com MLX90614 wiht ESP8622
}
void loop() {
//Robojax.com MLX90614 wiht ESP8622
server.handleClient();
MDNS.update();
//Robojax Example for MLX90614
getTemp();
delay(1000);
//Robojax Example for MLX90614
}
/*
* @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
* www.Robojax.com
*/
void getTemp()
{
// Robojax.com 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
// Robojax.com MLX90614 Code
}//getTemp
void displayTempC()
{
//Robojax.com MLX90614 wiht ESP8622
String HTML ="<span style=\"font-size: 28px\">
";
HTML +=typeName[0];
HTML +=tempC;
HTML +="°C</span><br/>
";
HTML +="<span style=\"font-size: 28px\">
";
HTML +=typeName[1];
HTML +=tempCA;
HTML +="°C</span>
";
server.send(200, "text/html", HTML);
}//displayTemp()
void displayTempF()
{
//Robojax.com MLX90614 wiht ESP8622
String HTML ="<span style=\"font-size: 28px\">
";
HTML +=typeName[0];
HTML +=tempF;
HTML +="°F</span><br/>
";
HTML +="<span style=\"font-size: 28px\">
";
HTML +=typeName[1];
HTML +=tempFA;
HTML +="°F</span>
";
server.send(200, "text/html", HTML);
}//displayTemp()
void displayTempK()
{
//Robojax.com MLX90614 wiht ESP8622
String HTML ="<span style=\"font-size: 28px\">
";
HTML +=typeName[0];
HTML +=tempK;
HTML +="°K</span><br/>
";
HTML +="<span style=\"font-size: 28px\">
";
HTML +=typeName[1];
HTML +=tempKA;
HTML +="°K</span>
";
server.send(200, "text/html", HTML);
}//displayTemp()