There are too many curtains at home, which is laborious and laborious; the elderly at home usually have inconvenient legs and feet, and it is difficult to open the curtains; they want to close the curtains but cannot open their hands because of busyness; there are multiple curtains in the home, which is time-consuming and laborious!
In a flash of light, the small curtain robots currently on the market can transform ordinary curtains into smart curtains in seconds. Why not do it yourself DIY one~
Realize function points
Function and Function description
App control supports
normal control mode and percentage control mode.
Normal mode: support open, close and stop control functions
Percentage control: control according to the percentage of curtain length
Illumination control: Support the setting of the minimum light value and the maximum light value. When the strong enemy of light is lower than the minimum value or higher than the maximum value, the curtain will automatically close
Light detection function can display the current light intensity
Self-start function detects manual opening, opens all curtains; detects manual closing, closes all curtains
Power display Display the current power of the motor
Hardware solution introduction
Use Tuya Smart Low Energy Embedded Bluetooth LE module as the control unit and wireless connection unit. The illuminance sensor detects the light intensity of the current environment, the acceleration sensor recognizes the state of manually pulling the curtain and the motor drives the curtain to move to realize the intelligent opening and closing of the curtain.
1. Core control unit
Tuya Smart Low Energy Embedded Bluetooth module is developed based on SoC, which can realize Bluetooth LE direct connection, motor control and sensor data collection.
2. Power Management Unit
Selecting 4000mHA rechargeable lithium battery (3.7V) as the main power supply, while providing stable operation guarantee, there is no need for additional wiring, and when the power is insufficient, it can also be removed for charging.
3. Illumination sensor
Devices that can sense light intensity mainly include photoresistors, photodiodes, and illuminance sensor chips. The photoresistor and photodiode collect analog quantities. The light sensor selects TI’s OPT3004 sensor chip, which can directly output the current light intensity value through the digital interface, which is suitable for real-time display of light intensity value on the App terminal.
4. Acceleration sensor
ST's LIS2DW12 acceleration sensor is a 3-axis acceleration sensor that can compare the force in the horizontal direction that accurately recognizes the curtain-drawing action.
5. Motor drive
The power principle of the curtain robot is to move the charged robot and the curtain through the friction force of the runner and the curtain guide rail, which requires a relatively large torque and does not require a high speed of movement. Using high-speed and low-torque to drive the engine through gear deceleration and torque increase, not only can generate a large torque, but also consumes less power, which meets the power requirements of the curtain robot.
Schematic diagram of curtain robot:
Curtain robot PCB diagram:
Software implementation scheme
The curtain robot source code has been open sourced to GitHub:
Note: The specific address of GitHub can be obtained by following "Graffiti Developer" and replying to "Curtain"~
The following is a brief description of the realization principle of each function:
1. Function realization: normal control and percentage control
Both normal control and percentage control need to be carried out when the length of the curtain is already known. Since the speed of the motor is fixed, when measuring the length of the curtain, it is actually testing how long it takes to go from 0% to 100%, and then calculate the running time according to the current position of the motor and the position to be reached, so as to achieve this. Control the curtain robot to move to the specified position.
Implementation method: After receiving the DP point issued by the app, the percentage control first calls the void curtain_percent_control(unsigned char current_position, unsigned char target_position) function to make the curtain robot run in the corresponding direction, and save the running time into a global variable for Stop using the task function. The void curtain_percent_control_stop_task(void) function needs to be executed all the time. When it is detected that the running time has been reached, the motor is stopped, the current position is stored in FLASH, and the current motor position is reported.
2. Function realization: automatic measurement of curtain length
Automatically measuring the length of the curtain is actually measuring the length of the curtain rod, so how to judge whether the curtain robot reaches the end is the key to the measurement at both ends. The function of controlling the movement of the motor is realized by obtaining the total time measured.
To judge that the curtain robot has reached the end, there are two ways to judge on this hardware:
One is to measure the MOCUR pin in the motor drive chip. When the motor is locked, the MOCUR pin will be higher than the voltage during normal operation. By judging whether the pin voltage has changed, you can know whether the motor is locked. Confirm whether you have reached the end.
The second is to use the three-axis acceleration sensor lis2dw12 to determine whether it has reached the end point. According to the placement position of lis2dw12 on the hardware, judging the running state of the curtain robot mainly depends on the x-axis in the three-axis acceleration sensor.
The following picture shows the data of the x-axis of the three-axis acceleration sensor during the operation of the curtain robot. There is basically no fluctuation in the static state. After starting to reach the end point, the up and down fluctuations are large. The x-axis data is obviously a bump at the moment of the collision at the end point. When the motor does not stop running after reaching the end point, it can be seen that the data of the x-axis is higher than the average at rest, and the fluctuation of the data is smaller than that in the running process.
From the above two methods, it can be seen that it is easier to use the voltage comparison method to judge whether the end point is reached than to use lis2dw12 to judge. But using the three-axis accelerometer lis2dw12, you can clearly know what operating state the current motor is in.
3. Function realization: motion detection
By observing the waveform, you can know that when you pull the curtain in a certain direction, although the overall situation is fluctuating, the value at the beginning is related to the pulling direction, so the realization of this part of the function is by judging that the curtain robot is pulled After the first part of the value to determine the direction to run.
4. Function realization: light intensity display
The sensor used to detect the light intensity is opt3004. Through the IIC protocol, the current light value can be obtained by reading the result register of opt3004.
5. Panel UI
The App panel uses the public version single-curtain panel provided by the Tuya IoT platform.
You can turn ordinary curtains into smart curtains in seconds. You can remotely control the switch and automatically turn on and off according to the intensity of the light, which brings a convenient life to your family~ it's not that difficult! Fans are moving~