Soil Moisture Data Retrieval Application using Tuya Link SDK


In this article, we will develop a Soil Moisture Data Retrieval system using Tuya Link SDK, Tuya Smart Android App, Python and Arduino IDE. A Moisture sensor is connected to the ESP32 board to implement this application.

The moisture data will be logged in a .csv file and also displayed on the Tuya Smart App. This can prove very useful for home plantations, floriculture, horticulture, agriculture etc. where optimum soil moisture needs to be maintained for proper growth of plants.



  1. ESP32 board
  2. Soil Moisture Sensor
  3. Micro-USB cable and connecting wires


  1. A Tuya Account
    1. Tuya IoT Platform (Web)
    2. Tuya Smart Application (Android)
  2. Python 3.x
  3. Arduino IDE

GitHub Link:

Hardware Connections for Tuya Link SDK

Connections are pretty simple. The Pin 32 of the ESP32 board receives the Analog Signal from the moisture sensor. Connect the Vcc and GND of the ESP32 board and the Moisture Sensor.

Tuya Link SDK_hardware_connections

If you have a moisture sensor like this, connections are the same but some extra jumper cables might be needed.

Tuya Link SDK Application Setup

First of all, create an account on Tuya Platform.

Tuya Link SDK Web Login Page

Install tuyaos-link-sdk in Python.

git clone
python -m pip install ./tuyaos-link-sdk-python

tuyaos-link-sdk install python

Tuya IoT Platform(Web)

Once logged in, create a new product (follow this simple tutorial as a getting started guide on Tuya) to get the following screen.

Tuya IoT Platform Web Dashboard

Now add the following functions by clicking the ‘Add’ button with the following attributes.

Tuya IoT Platform Web Custom Functions

Next, complete the UI Studio Design. The UI Design should look like this. Test and Release it to resolve any errors.

Tuya Link SDK UI Design

Note: To refresh the Tuya server, the switch button is provided and every toggle of the button will register the current moisture reading in the MS.csv file.

Open the file from the GitHub repo in the editor. Edit and change the productid, uuid, authkey (obtained by license generation for Link SDK) and the COM port of your connected ESP32 device in the file. Save this edited file, for the output section of this article.

Tuya Smart Application (Android)

After installing and setting up the Tuya Smart App, just click the scanner button to scan the QR code generated by the file.

Tuya Smart Add device

Tuya Smart Add device Options

Tuya Smart Scan

Now the MoistureApp will be added to the All Devices section of the Tuya Smart App.

Arduino IDE for Configuring Tuya Link SDK

The Arduino IDE Program in the GitHub repo sends the moisture reading received from the moisture sensor by the ESP32 board to the python program via the serial port. Simply add your ESP32 board in Arduino IDE, compile and flash the sensorapp.ino program.

Adjust the percentage value in the code to suit the sensor configuration.

Arduino IDE Boards

Board Manager URL:


Run the file using the command

python ./

Soil Moisture Data Retrieval App Output

MS.csv file content (Timestamp, Soil Moisture Reading)

Leave a Reply