Tuya Smart: Smart Home Automation

by Harsh Dethe in Circuits > Microcontrollers

7723 Views, 11 Favorites, 0 Comments

Tuya Smart: Smart Home Automation

Introdution To Tuya IoT Platform..png

In search of new IoT platforms similar to Blynk and RemoteMe, I stumbled upon Tuya. An IoT platform for industrial products. In this Instructable, I will share how to set up and use a smart switch using the Tuya IoT platform. So without any further delay, let's get started.

Supplies

  1. Hardware Requirements:
  2. Software Requirement:

Making a Device on Tuya.

1.png
2.png
3.png
4.png
5.png
6.png
7.png

First things first, we need to create an account on Tuya’s IoT platform. To do that, head over to Tuya.com and sign up to create your account. Once you have created an account, log into it and follow the steps given below.

You will be greeted by an overview page. On the top, you will notice a “Create” button. This click on it to create a new device.

1. You will be greeted by an overview page. On the top, you will notice a “Create” button. This click on it to create a new device.

2. Then in the Standard category, select Electrical and then select Switch. As we are making a smart switch here.

3. Now select the Custom solution and click on the available Switch.

4. Now fill in the product information.

  • First, give your product a unique name.
  • The product model is optional. You can leave it empty.
  • The protocol is the communication method. As we are using ESP8266, select WiFi (WiFi and Bluetooth for ESP32).

5. Soon as you click create, a popup will appear for selecting switch functions. Here you can select the number of switches you need for your application. As we are going to toggle only one LED/Relay, select one switch and click ok.

6. You will notice 6 tabs namely Function Definition, Device Panel, Hardware Development, Product Configuration, Device Debugging, and Testing Service. We will skip the device panel for now as we will be using Tuya’s smartphone app to make the panel.

7. Moving further, you first need to get a token to activate your device, to do that copy the PID and send it to dev@tuya.com. Make sure you send the mail from the email account you used to register with the Tuya platform.

With that being done, all the device setup is now ready. It’s now time to activate the device through Tuya PMS.

Activation on Tuya PMS.

8.png
9.png
10.png

You will receive a token from the developers from Tuya. Copy this token, and head over to the Tuya PMS site, and create an account there. Once an account is created, log in to your account. Follow the steps:

1. On the Sidebar go to Production Management >> Work Order Management >> Activation Code Verification. Paste the token here and click on Confirm.

2. You will get a popup of successful activation. This indicates your device is registered.

3. Now download the TYDA app for burning the Firmware.

Burning Firmware on ESP8266.

11.png
12.png
13.png
14.png
15.png
16.png

Now it’s time to work with the code. But don’t worry, you don’t have to be an expert at it. Follow these steps and you should be good to go.

1. Download and unzip the Tuya burning authorization package. You will find two files in it.

2. First, install the CP210x driver as it will allow your ESP boards to communicate with your PC. Then install the TYDA application. Just like any software, follow the onscreen instructions.

3. After successfully installing the TYDA app, launch it and you will be greeted with a home screen that might be in Chinese. But don’t worry, it is very easy to switch languages. Refer to the image above.

4. Now that the app is set in English, first, go to File >> Setup and check of the baud rates are set as in the image.

5. After that, click on the Enter token button. Here make sure that the download firmware box is checked and in the workstation dropdown, you have selected “Burning Authorization”.

6.The next step is to connect your ESP8266 board (in this case Wemos D1 mini) to the computer using a USB cable. Now click on the COM port menu and select the COM port available for your ESP.

(If you have multiple COM ports and don’t know which one to use, just disconnect the ESP board and restart the TYDA app. Now check the list of COM ports and then connect the ESP board to see which new port appears. This will be the Port you need to burn firmware).

7.Click on the Run button on the top right. And wait for a few seconds. This might take a couple of minutes sometimes. Do not unplug the board from your computer until you get a success message.

After a successful burning process, you should see the Yellow colour of the TYDA app turn green indicating the burning process has been completed. Now unplug your ESP and move to the Arduino.

Programming the Arduino.

17.png
18.png
19.png

Now comes the Arduino part, many of you might be familiar with the Arduino IDE, but for beginners, Arduino IDE is software used to develop and burn Codes into an Arduino microcontroller.

1. Download and install Arduino IDE if you don’t have it already.

2. After installing the IDE, you need to install a library by Tuya. It is very easy to install a library in Arduino IDE. First, open the IDE and click on Tools >> Manage Libraries. This will open a pop-up window, in this window type in the search bar “Tuya” and hit enter. Install the library marked in the image above. This will take just a few seconds, after it is installed, close the window and restart the IDE.

3. Now click on File >> Example >> Tuya_WiFi_MCU_SDK >> Start. This will open a pre-built sketch.

4. Next, connect your Arduino UNO to the PC. If you are using a clone board, make sure you install the CH341 USB driver. Then click on Tools and make sure you have selected the right port.

5. When the port is selected, you can now click on the upload button on the top left side below the menu indicated by the right arrow. Wait patiently as the uploading process completes, after successful upload, you will see the message “uploaded” at the bottom left.

With that, the Arduino is programmed and ready to be used. The next step is to make the right connections.

Connections.

circuit.png

The connections for this project are very simple. All you will need is 4 male-to-male jumper wires, ESP8266, and Arduino UNO. Follow the connections given in the diagram below. But make sure you disconnect the boards before.

After the connections are made, let’s proceed to the app which will control the LED.

Making the App.

SS1.png
SS2.png
SS3.jpg
SS4.png
SS5.jpg
SS6.png

1. Head over to the Play Store or App Store and download the Tuya Smart app.

2. Click on Add Device button. This will take you to the next page where we will create a switch.

3. In the switches section, Select Switch(Wi-Fi).

4. Next, enter your WiFi credentials. Make sure it is a 2.4GHz network. 5Ghz does NOT work.

5. Now for this step, Power the Arduino and connect Pin 7 to GND for 3-4Sec. This will put the board in pairing mode. You will see the onboard LED blink rapidly. Now click on “Confirm the indicator is blinking” Radio button and click on Next.

6. Now the device adding will take a couple of minutes. So wait patiently for the process to complete. Once the connection is established. Click on Done.

7. Refer to the image above for the final look of the app. You can toggle the LED using the button at the bottom.

Testing and Conclusion.

Tuya-gif.gif

The device works seamlessly without any lags or delays. What you can do now is replace the LED with a relay to control appliances.

In the future, I will share more projects based on this amazing platform and maybe design a commercial product with it. If you like this instructable, check more projects on ProjectHub.in

If you are looking for custom projects, product design, PCB design, manufacturing, or sourcing. Contact us at Contact@projecthub.in