Table of Contents
This tutorial aims at making a Smart Door Bell using TuyaOS Link SDK on Raspberry Pi.
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.
- What is Tuya
- Why Tuya Link SDK?
- Components Used
- System Architecture
- Circuit Diagram
- Firmware and Configurations
What is Tuya?
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.
The list below is a suggested list of components.
- Raspberry Pi 4 Kit
- Green Color Big Dome Push Button with LED
- Raspberry Pi Camera
- 12V Power Supply
- Buck Converter
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.
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.
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 IoT
Step1: 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.
Step 2: Functions Definition
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.
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.
Step 3: Selecting a panel
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.
Step 5: Creating Cloud Development Environment
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
Configuring Raspberry Pi
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.
Firmware and Configurations
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
- cmake ..
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.
Raspberry 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.
- 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.
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
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-Doorbell
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/