Software apps and online services
This tutorial aims at making a Smart Door Bell using TuyaOS Link SDK on Raspberry Pi.Introduction
There are a number of Smart DoorBells available on the market, most of them are classic and others are smart with cameras and speakers. Like this SmartDoor Bell showcased by Tuya in their expo.
What features does a smart doorbell have?
- It should be securely connected to the internet.
- It should take a picture or show a live video of the person pressing the doorbell button.
- The live camera feed should be accessible from a smartphone or should be visible on a LCD screen in the house.
Based on the above features, we can make a DIY smart doorbell.
This tutorial is a step-by-step instruction on how to build a prototype of such a smart doorbell using Tuya platform, Tuya Link SDK and off-the-shelf hardware components.Tutorial Parts
- What is Tuya
- Why Tuya Link SDK?
- Components Used
- System Architecture
- Circuit Diagram
- Firmware and Configurations
Tuya is an international company that provides IoT and AI solutions along with compatible hardware so that the developers don’t have to spend much time sourcing, testing, and debugging a lot of components before reaching a final BOM. While end-users can instantly get their new Tuya device ready and running in a matter of minutes. Tuya Sandwich Evaluation kit is an example of a powerful merger of hardware along with an easy-to-use SDK.Why Tuya Link SDK?
Tuya is not only a hardware company, in fact, but it also provides a full-fledged cloud IoT platform and easy to use SDKs,
Tuya also provides a RTOS based operating system called TuyaOS and the amazing fact about TuyaOS is that it is a cross-platform OS so that you can run it on Linux, MCUs and even on non-OS based devices.
TuyaLink SDK is also provided which can be compiled and easily be used in Python or C programs on Linux SBCs like Raspberry Pi. You can find more about Tuya Link SDK on Tuya Github Repository.
Using the Tuya Cloud Development platform, you can add, remove, update and manage your fleet of IoT devices very easily and can even run analytics on real-time data. To make the life of the IoT developers easier, Tuya provides its easy-to-use SDK which has pre-built templates, a lot of tutorials, well-written documentation and a large community of developers using Tuya. All of these features make Tuya an ideal choice for new IoT products.How Do Traditional IoT Systems Work?
The traditional IoT systems work as shown in the picture above. An IoT solution architect has to manage each and every part of the system in order to roll out a product and it spans over 1-2 years of development.Typical Tuya Workflow
A typical Tuya solution workflow looks something like shown in the picture above. You need to have an MCU and a Tuya module connected over UART. This configuration makes things very easy as you don’t have to worry about the WiFi configurations, communications taking place between the Tuya module and Tuya Cloud Platform and data delivery as all of these things are handled by a black box which we can call Tuya Module. You just need to send simple instructions from your MCU to Tuya Module and the rest is handled by Tuya Module. Tuya Module communicates with the Tuya Cloud Development Platform and you can connect a number of the different devices to the Cloud Development Platform including your custom-built smartphone and web app.Components Required
The list below is a suggested list of components.
Raspberry Pi 4 Kit
- Raspberry Pi 4 Kithttps://www.amazon.com/Vilros-Raspberry-Basic-Cooled-Case/dp/B07TKFKKMP/ref=sr_1_4?crid=NROVRBGDLRLC&keywords=raspberry+pi+4&qid=1640163767&sprefix=raspberry+pi+3b%2Caps%2C320&sr=8-4
Green Color Big Dome Push Button with LED
- Green Color Big Dome Push Button with LEDhttps://www.amazon.com/Big-Dome-Push-Button-Green/dp/B00K7IEIJ4/ref=sr_1_37?crid=3BDBWTM0Z1FI6&keywords=big+dome+push+button&qid=1640163802&sprefix=big+dome+pu+button%2Caps%2C322&sr=8-37
Raspberry Pi Camera
- Raspberry Pi Camerahttps://www.amazon.com/Arducam-Raspberry-Camera-Module-Megapixel/dp/B083BHJZ16/ref=sr_1_1?crid=3VLQAFYLKE9TE&keywords=raspberry+pi+cam&qid=1640163879&sprefix=raspberry+pi+ca%2Caps%2C343&sr=8-1
12V Power Supply
- 12V Power Supplyhttps://www.amazon.com/100-240V-Transformers-Switching-Applications-Connectors/dp/B077PW5JC3/ref=sr_1_2?crid=2T8CZQ9TJV7GR&keywords=12v+power&qid=1640163845&sprefix=12v+powe%2Caps%2C330&sr=8-2
- Buck Converterhttps://www.amazon.com/Adjustable-Converter-1-25-36v-Efficiency-Regulator/dp/B079N9BFZC/ref=sr_1_12?crid=5YBEMC4W4G01&keywords=buck+converter&qid=1640163916&sprefix=buck+convert%2Caps%2C346&sr=8-12
We will connect the Big Dome button, speaker and Pi Camera with Raspberry Pi and Raspberry Pi will be powered with 12V power supply via Buck Converter.
Main components of the smart doorbell.ArchitectureSensor Node
Above shown is the sensor node architecture of our smart DoorBell. Raspberry Pi is acting as a mainboard to which the camera, bell button and speakers are connected.System Architecture
The complete architecture of our system is shown in the picture above. When a person presses the smart doorbell button, the live camera feed will be displayed on the HDMI monitor and the notification will be sent to the Tuya IoT Cloud using TuyaOS Link SDK. The Tuya IoT Management App can then see the doorbell notifications by connecting to the Tuya Cloud.Setting-up Tuya IoTStep1: Configuring Device
Create an account at http://iot.tuya.com/and log-in to the account
Then click on Create
Then again click on Create
Find Standard Category, scroll down to the bottom of the page, and click Can’t find the category? hyperlink.Raspberry Pi is a non-standard category in Tuya Platform, you will need to select Can’t find the category? when you create a product.
Type-in the product information(Link SDK Demo) and select Wi-Fi as the protocol type, choose Standard Power Consumption, and click Create Product.
Get the PID information of your newly created device.
Tuya devices communicate with the cloud through data points (DPs). We need to add the DP ID according to product functions, and then configure related information.Note:
Only custom functions can be added in this step because we are using Raspberry Pi.
In the Function Definition > Custom Functions section, click Create Functions.
In the Newly created custom function pop-up window, enter the relevant information of the DP and click Confirm.
The created function will be displayed in the Custom Functions section.
You can view the data that is transmitted between the device and the cloud on the app. Select the DIY Style Panel for better debugging experiences.Step 4: Getting licenses
In the Hardware Development tab, select the Self-Developed Module SDK, and set the required fields.
In the Develop SDK section, keep the default settings for Chipset Platform, Operating System, and Toolchain, enter a module name, and then click OK.Wait a minute. The page will refresh and the free licenses will be displayed.
On the right side of the Selected Module section, get free licenses.
Navigate to Cloud from the left sidebar and press the “Create Cloud Project” button. Then fill-in the details shown in the picture below.
In the next screen click “Authorize”. In the Configuration Wizard, enter your email address and password
Connect your Raspberry Pi to an HDMI LCD Screen and then connect USB keyboard and mouse to the USB ports of the Raspberry Pi.
- Power on your Raspberry Pi
- Download Raspberry Pi Imager from this link https://www.raspberrypi.com/software/
- Put the SD Card in your laptop SD Card port or use a USB SD Card reader.
- Install and Open Raspberry Pi Imager
- Click on Choose OS
- Choose Raspberry Pi OS (32-bit)
- Then Choose Storage(sd-card)
- Click on the Write button so that it can Download and Write Raspberry Pi OS to the SD Card.
- Once done, put the SD Card in the Raspberry Pi SD Card port and power on your Raspberry Pi.
- Then open Raspberry Pi Terminal.
Once the terminal on your Raspberry Pi is opened, execute the following commands one-by-one.
- sudo apt update
- sudo apt upgrade -y
- sudo apt install curl git -y
- sudo apt install aplay
- cd ~
- git clone https://github.com/Nauman3S/Smart-Doorbell.git
- git clone https://github.com/tuya/tuya-iot-link-sdk-embedded-c.git --recurse-submodules
nano tuya-iot-sdk-embedded-c/examples/switch_demo to edit tuya_config.h
- Change the parameter of TUYA_PRODUCT_KEY to the PID of your product created on the Tuya IoT Platform.
- Change the parameter of TUYA_DEVICE_UUID to the UUID provided in the license list.
- Change the parameter of TUYA_DEVICE_AUTHKEY to the key provided in the license list.
- cd tuya-iot-sdk-embedded-c
- mkdir build && cd build
More details can be found here https://developer.tuya.com/en/demo/link-sdk-demo-raspberry-pi
The commands stated above will update your Raspberry Pi OS, download curl and git and then download the smart doorbell firmware from github repository.Circuit DiagramRaspberry Pi Pinout
Complete circuit diagram is shown above. You just need to connect an ordinary speaker and a PiCam to the raspberry pi to the respective ports. Then connect a big dome button to the raspberry pi on pin number 18. Optionally, you can also connect the big dome button LED pins to the 12v power supply.App
- Download the Tuya IoT Management App. Scan the QR Code below to download it.
- Once you have the app installed, log in using the QR code of the project, the username, and the password you used when you created the asset and the user.
You can find the QR code of the project by navigating to Cloud > Development > My Cloud Project > Devices > Add Device > Add Device with IoT Device Management App
Then from the Devices section of the Cloud menu, add a new device
Once the device is added, scan the QR code with your app and enter your username and password to log in.
You will be automatically redirected to a page where you can see all your assets. Click on the asset that we created and navigate to the Devices section.Testing
To test it, turn on your raspberry pi and execute the following commands
Once you run the program, two c++ programs will run simultaneously.
- The first program is the camera, sound and button handler. When you press the button it will start the live preview and play the bell sound.
- The second program is the cloud program which connects with the Tuya IoT Cloud using TuyaOS Link SDK. When the buttons is pressed, the notification is sent to the smartphone app so that the user should know that someone pressed the smart doorbell button.
Smart Doorbell powered on. If you are using a big dome button with LED in it, the LED will light up. If you don’t have a speaker but have an HDMI monitor, you can skip the speaker connection as HDMI monitors already have speakers in them so pressing the big dome button will play the bell sound from the HDMI speaker.
When the system connects to the Tuya platform over WiFi you will see Blue LED lights up on your ESP32 or Arduino.Short Demo Video
Demo Video: https://youtu.be/pV5ueSZfrf8
Github Repository: https://github.com/Nauman3S/Smart-DoorbellConclusion
In conclusion, we developed a Smart Doorbell using the TuyaOS Link SDK which connects to the Tuya IoT Platform. The Smartphone app also gets notifications from Tuya IoT Platform. Following the whole tutorial yields a working smart Doorbell.
In order to learn more about the Tuya ecosystem, have a look at the articles below.
Tuya IoT Platform: http://iot.tuya.com/
Tuya Developer Platform:https://developer.tuya.com/en/
Tuya Arduino Developer Program:https://pages.tuya.com/develop/