Originally posted in
diyusthad.com
In this project, we are going to make an IoT-connected device using the tuya IoT platform and ESP8266 module.
What is Tuya IoTTuya is a leading global IoT Cloud Platform that connects the intelligent needs of brands, OEMs, developers, and retail chains. The platform provides developers with a one-stop IoT PaaS-level solution that contains hardware development tools, global cloud services, and smart business platform development, Tuya offers comprehensive ecosystem empowerment from technology to marketing channels to build the world’s leading IoT Cloud Platform.
Accounts neededLet’s build it!Step 1: Create a product and get the PID- Signup or login to tuya IoT from https://iot.tuya.com/
- Then click on “Product” and choose “Development“.
- From “Product” page, click on the “Create” button.
- Now click on the “Lighting” tab and then select “Light Source”.
- Then select “Custom Solution” and choose “Light Source“.
- Now enter a name for your product, check the option “WI-FI” under protocols.
- After this process, the system will ask you to configure the default device control functions. Leave these 3 functions as default and click ok.
- Copy and save your PID.
- Send the PID of the device we just created in the tuya IoT platform and the Tuya Account email ID to devops@tuya.com.
- After some time(may take some long hours) you will receive your token code in reply to the email.
- Now Signup or login into pms.tuya.com.
- After login click on Production Manage -> Work order Manage -> Activation Code.
- Now paste the Token we received in the email to the form on “ActivationCode” page and click confirm.
- Now a popup will appear saying “Production certification confirmation“.
- That’s it now the Token is activated.
- Download and install the Tuya firmware burner from here.
- Then login with using your PMS account detail and then click Online Login. You can choose Automatic Login and Remember The Password if needed.
- Then from the menu File -> Setup under BasicSettings, you must set up Burning Baud to 921600 and click Ok.
- Now click Enter Token and select Token from the Popup window.
- Paste your Token ID to the provided field, select the Firmware Download check box, and from the Select work station,dropdown list selects Burning Authorization.
- Click OK.
- Now connect the ESP8266 board to your computer and choose the right com port.
- Now click RUN. The burning process will take a few seconds, wait for it to finish and a “Success” message will be displayed.
Follow the circuit diagram to connect your ESP8266 with Arduino.
Note: Here I’m using NodeMUC but any other ESP8266 development boards will work
Arduino ProgramingFor making things easier for beginners in this tutorial we are going to use an example code provided by the TUYA_WIFI_MCU_SDK library for Arduino.
Sign up and join the Tuya Developer Arduino Beta Test
Installing the TUYA_WIFI_MCU_SDK library- Open your Arduino IDE.
- From menus go to Sketch -> Include library -> Manage Libraries.
- When the dialog box appears search for TUYA_WIFI_MCU_SDK & click install.
We need to change the PID given in the example code to the PID of our device which we created from the tuya IoT platform. Find the below line in the code and change the PID & also we need to change the MCU version.
Note: Check your MCU version in the tuya firmware burning app.
unsigned char pid[] = {"ma67l9sgmdyg3d2k"};
unsigned char mcu_ver[] = {"1.0.0"};
Note: While uploading the code remove the RX connection from Arduino.
After making the changes upload the code to your Arduino, don’t forget to choose the right board and port. If you are using Arduino Nano also choose the right bootloader version otherwise the uploading process will fail.
Adding device into tuya smart appAfter uploading the code connect back the RX connection of Arduino and turn on the power. Now press and hold the push button for 3-4 seconds. After releasing the inbuilt LED on the Arduino will start to blink.
- Now open the Tuya Smart App on your phone, For testing, you can use the app as a guest user (click on Try now).
- Now click on “Add Device“.
- There will be a bunch of devices listed as categories. For us, we are choosing “Light Source(WiFi)” from “Lighting” tab.
- Now choose your WiFi network and enter the password and click next.
- Select “Confirm the light is blinking rapidly” and click next.
- Now the app will scan and add the device to your app dashboard, it may take a while.
Open the device from the dashboard and try clicking the ON/OFF button, the inbuilt LED of your Arduino with toggle accordingly in sync with the smart app button state.
That’s it guys we have successfully made an IoT device with ESP8266 and Tuya IoT. Instead of the inbuilt LED on the Arduino now you can change the code to control any pin of the Arduino and use relays to control any appliances in your home like fan, TV, oven, lights, RGB lights, etc…
- If you are facing any problem in burning the firmware to ESP8266
- Check the baud rate and the port.
- Remove cables from TX and RX.
- If you are facing any problem in burning the firmware to ESP8266Check the baud rate and the port. Remove cables from TX and RX.
- If device initialization fails, Check your network connection. If you are using a hotspot connection from a laptop or mobile sometimes it won't work so change to another 2.5GHz network.
- If some other device is showing instead of your device in the app dashboard, check the PID which you gave in the Arduino code.
- If uploading code to Arduino fails then check the port and device, in case of Arduino nano also check the bootloader version.
- Remove the connection from RX.
If you want to build a commercial automation product or provide a great and easy tool for your customer to integrate any technology into the internet of things with ESP8266 or If you want an app with a simple interface and a great experience for the users. The answer to all these is Tuya IoT Smart technology.
Comments