I am fond of cooking and trying different recipes to expand my knowledge about foods. And, as an electronics enthusiast, I enjoy tinkering with gadgets to get more precise measurements while cooking. In that way, I ensure delicious and consistent outcomes with little effort. To measure the internal temperature of foods (roasts, steaks, etc.), I utilize a meat thermometer while cooking. Although meat thermometers can easily monitor the internal temperature to avoid overcooking and serving dried-out food, they lack the ability to measure the surface temperature. Thus, I decided to develop a wireless infrared kitchen thermometer from scratch.
An infrared kitchen thermometer can be employed to verify:
- food and beverage temperatures,
- the oven temperature,
- refrigerator and freezer temperatures,
- boiling and cooled milk temperatures while making yogurt,
- hot oil temperature while deep frying.
I decided to use the Tuya IoT Platform in this project because it allowed me to develop a mobile application interface compatible with various operating systems (Android and iOS). In the following steps, I will explain how I benefited from the Tuya IoT Platform to improve this project in detail.
To get accurate temperature measurements, I utilized a DFRobot TS01 IR temperature sensor. This sensor can measure the surface temperature from -70°C to 380°C while providing a maximum accuracy of 0.5°C.
Finally, I added a 5mm common anode RGB LED to show the connection status between the infrared thermometer and the Tuya Cloud.
On the thermometer's mobile application interface supported by the Tuya Cloud, the user can monitor two different data points regarding the surface temperature:
- Cook_Temperature - Unit: °C
- Cook_Temperature_F - Unit: °F
Huge thanks to DFRobot for sponsoring this project.
Sponsored products by DFRobot:
⭐ DFRobot TS01 Non-contact IR Temperature Sensor | Inspect
Tuya Smart is a global IoT platform that enables smart home products to come to life for brands, OEMs, manufacturers, and retail chains. But, Tuya is not providing its services and APIs for companies only. Tuya has established an IoT cloud platform that delivers a full suite of offerings to developers, including Platform-as-a-Service (PaaS), Software-as-a-Service (SaaS), and other cloud-based services. Tuya Cloud Platform has built a thriving ecosystem providing more than 410, 000 product SKUs in over 1, 100 categories, covering over 220 countries and regions.
Tuya IoT Platform lets the user develop a smart product from scratch and provides built-in functions for different product types. Furthermore, Tuya SDKs allow controlling a registered and authorized product with a development board via serial communication. You can get more information about Tuya SDKs from the Tuya Developer Platform.
While employing the Tuya IoT Platform to create a custom product for this project, I decided to convert a NodeMCU V3 LoLin ESP8266 to a registered and authorized Tuya product. Then, I used an Arduino Nano to communicate with the authorized product (ESP8266). With Tuya's official Arduino library, the Arduino Nano can communicate with the authorized product via serial communication to send data to the Tuya Cloud and receive commands from the Tuya Cloud when connected to the Tuya Smart app.
⭐ First of all, go to the Tuya account registration page and create a developer account.
⭐ Then, go to the Tuya IoT Platform and click:
Create ➡ Can't find the category?
⭐ Enter the required product information:
- Protocol ➡ Wi-Fi
- Power Type ➡ Standard Power Consumption
⭐ After creating the product, select the features you want to add to your product from Standard functions or create new ones (Custom) if not supported by Standard functions.
Standard functions indicate the functions provided by Tuya for their product categories. Since there are lots of built-in products, it is easy to find the functions you need. Also, you can create your specialized functions named Custom functions, depending on your project.
The data point (DP) is the abstract representation of a function, and each function has an ID and data type.
Data Point ID (DP ID): indicates the code of a data point (function). Tuya Cloud sends or receives data through data point IDs.
Data Types: Boolean, Value (Integer), Enum, Fault, Char, and RAW.
Since there are built-in functions (Standard) provided by Tuya for cooking thermometers, I did not have to create custom functions for my product:
- Cook_Temperature - 101 - Value
- Cook_Temperature_F - 102 - Value
⭐ Then, go to the Hardware Development and select the TYWE3S Wi-Fi Module under the Tuya Standard Module SDK. It has an indistinguishable pinout to the ESP-12E (ESP8266) module.
⭐ After creating the product successfully, go to the Device Panel. Then, click the Create Blank Panel under the Visualized DIY Panel.
⭐ Now, design the panel (mobile application interface) with the drag-and-drop components. It is similar to the MIT App Inventor.
⭐ After designing the panel, click the Release button and enter the required information.
⭐ Finally, download the Tuya Smart app on Android or iOS and sign up.
I will show you how to use the Tuya Smart app to connect to the authorized product (ESP8266) in the following steps.
To be able to use the NodeMCU V3 LoLin ESP8266 as a Tuya product for this project, you need to flash and authorize it with the required firmware.
To authorize the ESP8266, you have to elicit a Token ID for your product. After sending the product ID (PID) with your Tuya IoT account name (e-mail) to dev@tuya.com, Tuya developers will provide you with the Token ID. Then, follow the steps below:
⭐ First of all, go to the Tuya Smart PMS system and create a developer account.
⭐ Then, go to Production Manage ➡ Work Order Management ➡ Activation Code Verification. To activate the production certificate for the product, enter the Token ID. When the Token ID is confirmed, the ESP8266 is ready to be flashed and authorized.
⭐ After confirmation, download the latest version of the Cloud Module Test Platform from Knowledge Base Management ➡ Software Download. You can find a copy in the Downloads.
⭐ After downloading the Cloud Module, open it and log in. Then, go to File ➡ Set Up and enter the required settings as shown below:
- Burning Baud ➡ 921600
- Test Baud ➡ 9600
⭐ Click Enter Token ➡ Token and paste the Token ID under the Burning Authorization. Do not forget to select Firmware Download.
⭐ Now, connect the NodeMCU V3 LoLin ESP8266 to the computer via a USB cable and select its port number, such as COM5. If you did not use it with the Arduino IDE or other compilers before, you may need to install its driver.
⭐ Finally, click Run to flash and authorize the ESP8266 as a Tuya product.
After flashing and authorizing the ESP8266 as a Tuya product, it is easy to connect it to the Tuya Cloud via the Tuya Smart app to send and receive data.
The product (ESP8266) must be in the network connection mode to establish a connection with the Tuya Smart app. As explained in the following steps, I assigned a button on the device to deploy the network connection mode when pressed.
⭐ First of all, press the network connection button on the device until the RGB LED blinks green.
⭐ Then, open the Tuya Smart app and log in.
⭐ Go to Add Device ➡ Add Manually ➡ Others ➡ Others (Wi-Fi).
⭐ Connect to a Wi-Fi Network (2.4 GHz).
⭐ When the Tuya Smart app finds a product on the network with the given settings, the app adds that product and connects it to the Tuya Cloud automatically.
⭐ Once connected, open the mobile application interface (device panel) to monitor temperature measurements produced by the infrared kitchen thermometer via the TS01 IR temperature sensor.
Download the Tuya MCU SDK Arduino Library to communicate with the Tuya Device (ESP8266):
Tuya MCU SDK Arduino Library | Library
⭐ Include the required libraries and define the Tuya Device (ESP8266) with its connection settings.
// Include the required libraries.
#include <TuyaWifi.h>
#include <SoftwareSerial.h>
// Define the Tuya Device:
SoftwareSerial conn(8, 9); // RX, TX
TuyaWifi my_device(&conn);
// Define Tuya Device connection status settings:
unsigned char led_state = 0;
int wifi_key_pin = 7;
⭐ Define the data points (DPs) of the Tuya Device (ESP8266).
⭐ Enter the PID (product ID) and MCU software version of the Tuya Device.
// Define data points (DPs) of the Tuya Device:
#define DPID_Cook_Temperature 101
#define DPID_Cook_Temperature_F 102
// Stores all DPs and their types. PS: array[][0]:dpid, dp type(TuyaDefs.h) : DP_TYPE_RAW, DP_TYPE_BOOL, DP_TYPE_VALUE, DP_TYPE_STRING, DP_TYPE_ENUM, DP_TYPE_BITMAP
unsigned char dp_array[][2] =
{
{DPID_Cook_Temperature, DP_TYPE_VALUE},
{DPID_Cook_Temperature_F, DP_TYPE_VALUE},
};
// Define the Tuya Device Information:
unsigned char pid[] = {"Enter_PID"};
unsigned char mcu_ver[] = {"3.1.4"};
⭐ Define the TS01 IR temperature sensor and RGB LED pins:
// Define the IR Temperature Sensor pin:
#define IR_Sensor A0
// Define RGB pins:
#define redPin 3
#define greenPin 5
#define bluePin 6
⭐ Initialize networking keys and set the required functions for the Tuya Device.
// Initialize networking keys.
pinMode(wifi_key_pin, INPUT_PULLUP);
// Enter the PID and MCU software version:
my_device.init(pid, mcu_ver);
// Incoming all DPs and their types array, DP numbers:
my_device.set_dp_cmd_total(dp_array, 2);
// Register DP download processing callback function:
my_device.dp_process_func_register(dp_process);
// Register upload all DP callback function:
my_device.dp_update_all_func_register(dp_update_all);
// Define the last time:
last_time = millis();
⭐ Start the serial communication (software serial) with the Tuya Device.
⭐ Activate the network connection mode when the network connection button (Wi-Fi Key Pin) is pressed.
⭐ RGB LED blinks green while the Tuya Device is attempting to connect to the Wi-Fi network.
⭐ If the Tuya Device (ESP8266) is connected successfully to the cloud server (Tuya Cloud), RGB LED turns blue.
// Start the serial communication with the Tuya Device:
my_device.uart_service();
// Activate the network connection mode when the network connection button (WiFi Key Pin) is pressed.
if (digitalRead(wifi_key_pin) == LOW) {
delay(80);
if (digitalRead(wifi_key_pin) == LOW) {
my_device.mcu_set_wifi_mode(SMART_CONFIG);
}
}
// RGB LED blinks green when the Tuya Device is attempting to connect to the network:
if((my_device.mcu_get_wifi_work_state() != WIFI_LOW_POWER) && (my_device.mcu_get_wifi_work_state() != WIFI_CONN_CLOUD) && (my_device.mcu_get_wifi_work_state() != WIFI_SATE_UNKNOW)) {
if(millis()- last_time >= 500){
last_time = millis();
// Adjust:
if(led_state == LOW){ led_state = HIGH; adjustColor(0,255,0); } else{ led_state = LOW; adjustColor(0,0,0); }
}
}
// If the Tuya Device (ESP8266) is connected to the cloud server:
if(my_device.mcu_get_wifi_work_state() == WIFI_CONN_CLOUD){
adjustColor(0,0,255);
}
delay(10);
⭐ Elicit temperature measurements generated by the TS01 IR sensor.
⭐ Then, update Cook_Temperature (°C) and Cook_Temperature_F (°F) data points of the Tuya Device.
// Get temperature measurements from the IR sensor and update the Tuya Cloud.
get_data_from_IR_sensor();
my_device.mcu_dp_update(DPID_Cook_Temperature, tem_celsius, 1);
my_device.mcu_dp_update(DPID_Cook_Temperature_F, tem_fahrenheit, 1);
⭐ In the get_data_from_IR_sensor function, get the signal value (ADC) produced by the TS01 IR sensor and elicit the temperature measurement in Celsius with this formula:
tem_celsius = ((double)ADC_Value*450/614.4-70)
⭐ Then, convert Celsius to Fahrenheit and print the temperature measurement (°C) on the serial monitor.
tem_fahrenheit = (tem_celsius * 1.8) + 32
void get_data_from_IR_sensor(){
unsigned int ADC_Value = analogRead(IR_Sensor);
tem_celsius = ((double)ADC_Value*450/614.4-70);
tem_fahrenheit = (tem_celsius * 1.8) + 32;
Serial.print("Temperature: ");
Serial.print(tem_celsius);
Serial.println("\u2103");
delay(100);
}
⭐ In the dp_update_all function, update all data points (DPs) with default values - 1, 50:
void dp_update_all(void){
// Update all DPs with default values:
my_device.mcu_dp_update(DPID_Cook_Temperature, 1, 1);
my_device.mcu_dp_update(DPID_Cook_Temperature_F, 50, 1);
}
// Connections
// Arduino Nano :
// NodeMCU V3 LoLin ESP8266
// D8 --------------------------- TX
// D9 --------------------------- RX
// DFRobot TS01 Non-contact IR Temperature Sensor
// A0 --------------------------- S
// 5mm Common Anode RGB LED
// D3 --------------------------- R
// D5 --------------------------- G
// D6 --------------------------- B
// Network Connection Button
// D7 --------------------------- S
First of all, I connected all components to the Arduino Nano by using jumper wires and two mini breadboards, including the NodeMCU V3 LoLin ESP8266 (Tuya Device). I utilized a 12V external battery to supply the device (infrared kitchen thermometer).
Then, I placed the Arduino Nano and the ESP8266 in a raspberry-shaped ceramic sugar bowl to hide abundant wirings.
Finally, I fastened all parts with a hot glue gun.
🥘🍳 The device activates the network connection mode if the network connection button is pressed. Then, the RGB LED blinks green while the NodeMCU V3 LoLin ESP8266 (Tuya Device) is attempting to connect to the Wi-Fi network via the Tuya Smart app.
🥘🍳 If the NodeMCU V3 LoLin ESP8266 (Tuya Device) connects to the Tuya Cloud via the Tuya Smart app successfully, the device turns the RGB LED to blue.
🥘🍳 Once initiated, the device updates the data points in the Tuya Cloud automatically. Then, the Tuya Smart app allows the user to observe the temperature measurements in Celsius and Fahrenheit on the mobile application interface (Device Panel):
🥘🍳 Also, the device displays the temperature measurements (°C) on the serial monitor.
Comments