Created
March 17, 2020 23:12
-
-
Save IdrisCytron/9d13b1bd6e3f4701fb74c7e6f1fb598d to your computer and use it in GitHub Desktop.
Build your own Portable Contactless Temperature (celsius) Reader for #Covid19
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment