Introduction
Covid-19 have been declared as pandemic. One of the early symptoms of corona virus was fever, and we are advised to reduce the direct contact. So, I try to develop a portable contactless temperature reader using ESP32 and Arduino platform. Later, you can improve the code to implement IoT in the application.
Before proceed to the tutorial, please go through following tutorial first on how to install and edit the library.
- Interface LSM9DS1 9DOF IMU With TTGO T-Display ESP32 – Install TFT_eSPI library and edit.
- Send Sensor Data to Adafruit IO Using ESP32 – Install MLX90614 library.
Video
This video shows how to build your own Portable Contactless Temperature Reader using Arduino platform.
Hardware Preparation
This is the list of items used in the video.
If you have Snapmaker or Ender3, you can access ? TinkerCAD 3D file,
export to .stl and print your casing.
Sample Program
This is Arduino sample program for ESP32 board. Before compile, please install following libraries through Library Manager:
- TFT_eSPI by Bodmer Version 1.4.20
- MLX90614 Library by Adafruit Version 1.0.1
/* | |
Tutorial: Build Your Own Portable Contactless Temperature Reader | |
Hardware: | |
– TTGO T-Display ESP32 | |
https://my.cytron.io/p-ttgo-t-display-esp32-1.14-display-module-presolder-header?tracking=idris | |
– MLX90614 Non-Contact Infrared Temperature Sensor | |
https://my.cytron.io/p-mlx90614-non-contact-infrared-temperature-sensor?tracking=idris | |
External libraries: | |
– TFT_eSPI by Bodmer Version 1.4.20 | |
– Adafruit MLX90614 Library by Adafruit Version 1.0.1 | |
Created by: | |
18 Mar 2020 Idris Zainal Abidin, Cytron Technologies | |
*/ | |
#include <TFT_eSPI.h> | |
#include <SPI.h> | |
#include <Wire.h> | |
#include <Adafruit_MLX90614.h> | |
#define ADC_PIN 34 | |
#define VREF 1100 | |
#define BUTTON1 35 | |
#define BUTTON2 0 | |
#define FF17 &FreeSans9pt7b | |
#define FF21 &FreeSansBold9pt7b | |
#define ROW1 0,16 | |
#define ROW2 0,38 | |
#define ROW3 0,60 | |
#define ROW4 0,82 | |
#define ROW5 0,104 | |
#define ROW6 0,126 | |
Adafruit_MLX90614 mlx = Adafruit_MLX90614(); | |
TFT_eSPI tft = TFT_eSPI(); | |
float ambientCelsius = 0.0; | |
float objectCelsius = 0.0; | |
float objectCelsiusTotal = 0.0; | |
long prevMillis = 0; | |
int interval = 1000; | |
void setup() | |
{ | |
pinMode(BUTTON1, INPUT_PULLUP); | |
pinMode(BUTTON2, INPUT_PULLUP); | |
Serial.begin(115200); | |
Serial.println(); | |
Serial.println("Build your own Portable Contactless Temperature Reader for Covid-19"); | |
Serial.println(); | |
tft.init(); | |
tft.setRotation(1); | |
tft.fillScreen(TFT_BLACK); | |
tft.fillRect(0, 0, 240, 43, TFT_DARKGREY); | |
tft.setFreeFont(FF21); | |
tft.setTextColor(TFT_BLACK); | |
tft.setCursor(ROW1); | |
tft.print(" Portable Contactless"); | |
tft.setCursor(0, 35); // Row 2 | |
tft.print(" Temperature Reader"); | |
tft.setTextColor(TFT_WHITE); | |
tft.setCursor(ROW3); | |
tft.print(" Battery:"); | |
tft.setTextColor(TFT_CYAN); | |
tft.setCursor(ROW4); | |
tft.print(" < Press button to read >"); | |
tft.setTextColor(TFT_WHITE); | |
tft.setCursor(ROW5); | |
tft.print(" Celsius:"); | |
tft.fillRect(0, 112, 240, 23, TFT_MAROON); | |
tft.setTextColor(TFT_BLACK); | |
tft.setCursor(0, 128); // Row 6 | |
tft.print(" #Covid19 by Idris"); | |
mlx.begin(); | |
} | |
void loop() | |
{ | |
if (millis() – prevMillis > interval) { | |
int adc = analogRead(ADC_PIN); | |
float batteryVoltage = ((float)adc/4095.0)*2.0*3.3*(VREF/1000.0); | |
tft.fillRect(140, 48, 100, 20, TFT_BLACK); | |
if (batteryVoltage > 4.2) { | |
tft.setTextColor(TFT_BLUE); | |
tft.setCursor(140, 60); | |
tft.print("Charge"); | |
} | |
else { | |
batteryVoltage = constrain(batteryVoltage, 3, 4); | |
float batteryPercent = ((batteryVoltage – 3) / 1) * 100; | |
if (batteryPercent < 50) { | |
tft.setTextColor(TFT_RED); | |
} | |
else if (batteryPercent < 80) { | |
tft.setTextColor(TFT_YELLOW); | |
} | |
else { | |
tft.setTextColor(TFT_GREEN); | |
} | |
tft.setCursor(150, 60); | |
tft.print((int)batteryPercent); | |
tft.print(" %"); | |
} | |
prevMillis = millis(); | |
} | |
if (digitalRead(BUTTON2) == LOW) { | |
objectCelsiusTotal = 0.0; | |
for (int i = 0; i < 20; i++) { | |
// ambientCelsius = mlx.readAmbientTempC(); | |
objectCelsius = mlx.readObjectTempC(); | |
objectCelsiusTotal += objectCelsius; | |
delay(50); | |
} | |
objectCelsius = objectCelsiusTotal / 20; | |
tft.fillRect(140, 92, 100, 14, TFT_BLACK); | |
tft.setTextColor(TFT_GREEN); | |
tft.setCursor(150, 104); | |
tft.print(objectCelsius); | |
} | |
} |
Thank You
References:
Thanks for reading this tutorial. If you have any technical inquiries, please post at Cytron Technical Forum.
“Please be reminded, this tutorial is prepared for you to try and learn.
You are encouraged to improve the code for better application.“