CWPiJIr

Based on the [LCSC Liangshanpai Development Board] Smart Curtain Project

 
Overview
The question requires
a smart curtain project based on Liangshanpai.
Question analysis:
The expected functions are:
In automatic mode,

the curtains are opened or closed based on the air humidity (high priority); In automatic/manual mode,
the curtains are opened or closed based on the light intensity . Infrared remote control and voice command control are used in automatic/manual mode. Schematic diagram design description : (1) Temperature and humidity sensor module: used to detect air temperature and humidity; Since I only have this DHT11 temperature and humidity detection module on hand, I used it to replace the raindrop detection module, which saved me some money. The humidity is mainly used in this project. Schematic diagram: My module physical diagram looks like this, as shown in the figure below. The physical products of this module on the market should be similar, and the code should be universal. For specific porting methods and code, please refer to the part about the DHT11 module in the link below: [Lichuang·Liangshanpai] Module Porting Manual (2) Light intensity sensor module: used to detect light intensity; This project solution follows the official case and uses a simplified solution, that is, directly using a voltage divider resistor plus a photoresistor. Schematic diagram: (3) Infrared receiver module, used for remote control; Schematic diagram: An infrared receiver head is connected in series with a 10KΩ chip resistor. In addition, a remote control is also needed to send commands. (4) Stepper motor module: used to drive the curtains; schematic diagram: the stepper motor selected is the same two-phase four-wire stepper motor and driver chip as the official case, used for display. Stepper motor physical picture: Stepper motor driver chip: (5) Voice recognition module, used for voice control. Schematic diagram: Voice recognition module physical picture: Hailing Technology V20 module, for specific usage methods and tutorial details, please refer to: Hailing Technology Voice Recognition Module Voice Firmware Creation and Download Speaker physical picture: Hmm, a pretty big speaker Microphone physical picture: Pay attention to inventory, the microphone in the official example is out of stock, the PCB was modified overnight, and a smaller microphone was replaced, the function is not different. DIP switch physical picture: used to independently control whether to power the voice control module, convenient for downloading the voice module SDK firmware. PCB design instructions and precautions: When drawing the PCB, pay attention to the width of the power line; the circuit of the motor part should pay attention to the power line passing through the capacitor before connecting to the motor driver chip; for aesthetic purposes, the wiring can be routed to the bottom layer or hidden. Software Description (Code Explanation): This project uses the DHT11 module for numerical detection of air humidity, so the macro definition in the raindrop sensor interface can be commented out. Temperature and humidity thresholds have been added. Additionally, the temperature, humidity, and light intensity thresholds need to be determined through testing in your own environment. /*file:bsp_adc.h*/ #ifndef _BSP_ADC_H__ #define _BSP_ADC_H__ #include "gd32f4xx.h" /* Rain sensor interface PF8 ADC2_IN6 */ #define BSP_RAINDROP_GPIO_RCU RCU_GPIOF #define BSP_RAINDROP_GPIO_PORT GPIOF #define BSP_RAINDROP_GPIO_PIN GPIO_PIN_8 /* Light sensor interface PF6 ADC2_IN4 */ #define BSP_LIGHT_GPIO_RCU RCU_GPIOF #define BSP_LIGHT_GPIO_PORT GPIOF #define BSP_LIGHT_GPIO_PIN GPIO_PIN_6 #define BSP_ADC_RCU RCU_ADC2 #define BSP_ADC ADC2 #define BSP_LIGHT_ADC_CHANNEL ADC_CHANNEL_4 #define BSP_RAINDROP_ADC_CHANNEL ADC_CHANNEL_6 // The smaller the raindrop threshold, the heavier the rain #define RAINDROP 60 // Temperature and humidity threshold #define HUM_MIN 60 #define HUM_MAX 75 // The smaller the light threshold, the brighter the light #define LIGHT_MIN 600 #define LIGHT_MAX 3900 void raindrop_and_light_config(void); unsigned int get_adc_value(uint8_t adc_channel_x); #endif The test code is directly written in the function of automatic mode, which makes it convenient to observe the changes in values ​​by receiving data through the serial port in automatic mode, and to modify the relevant thresholds in the macro definition later. void automatic_mode(void) { uint16_t light_value = 0; uint16_t raindrop_value = 0; uint16_t temperature_value = 0; uint16_t humidity_value = 0; DHT11_Read_Data(); // Read temperature and humidity values ​​temperature_value=Get_temperature(); humidity_value=Get_humidity(); // Read light intensity value























































































`light_value = get_adc_value( BSP_LIGHT_ADC_CHANNEL );

// Serial port printout of light, temperature, and humidity values
​​printf("light_value=%d
",light_value);
printf("temperature_value=%d
",temperature_value);
printf("humidity_value=%d
",humidity_value);

delay_1ms(1000);

if( humidity_value >= HUM_MAX )
{
printf("Humidity is very high
");
// Open the curtains (high priority)
open_curtain();
return;
}

// If high light is detected
if( light_value < LIGHT_MIN )
{
printf("Light intensity is very high
");
// Open the curtains
open_curtain();

}

// If low light is detected
if( light_value >= LIGHT_MAX )
{
printf("Light intensity is very low
");
// Close the curtains
close_curtain();
}` The project uses a clock frequency of 200MHz.
Therefore
, the relevant 240MHz macro definitions need to be commented out in the file "system_gd32f4xx.c", and the 200MHz macros need to be uncommented.
/* select a system clock by uncommenting the following line */ //#define
__SYSTEM_CLOCK_IRC16M (uint32_t)(__IRC16M) //#define __SYSTEM_CLOCK_HXTAL (uint32_t)(__HXTAL) //#define __SYSTEM_CLOCK_120M_PLL_IRC16M (uint32_t)(120000000) //#define __SYSTEM_CLOCK_120M_PLL_8M_HXTAL (uint32_t)(120000000) //#define __SYSTEM_CLOCK_120M_PLL_25M_HXTAL (uint32_t)(120000000) //#define __SYSTEM_CLOCK_168M_PLL_IRC16M (uint32_t)(168000000) //#define __SYSTEM_CLOCK_168M_PLL_8M_HXTAL (uint32_t)(168000000) //#define __SYSTEM_CLOCK_168M_PLL_25M_HXTAL (uint32_t)(168000000) //#define __SYSTEM_CLOCK_200M_PLL_IRC16M (uint32_t)(200000000) //#define __SYSTEM_CLOCK_200M_PLL_8M_HXTAL (uint32_t)(200000000) #define `__SYSTEM_CLOCK_200M_PLL_25M_HXTAL (uint32_t)(200000000) ` //#define `__SYSTEM_CLOCK_240M_PLL_IRC16M (uint32_t)(240000000) ` //#define `__SYSTEM_CLOCK_240M_PLL_8M_HXTAL (uint32_t)(240000000) ` //#define `__SYSTEM_CLOCK_240M_PLL_25M_HXTAL (uint32_t)(240000000)` The rest of the code is largely the same as the official tutorial; please refer to the official instructions for details. Physical demonstration: The completed soldered device looks like this: (Please ignore the microphone I accidentally melted a small portion of). Soldering precautions: Some small rules I figured out myself; I'm not sure if they're correct. First, solder some smaller surface-mount components (a soldering tool and hot air gun work well), then solder the medium-sized through-hole components that you don't solder too many of, and finally solder the largest and most complex ones. The motor chip in this project is located close to the pins of the bottom-level socket, so it's best to use solder paste and a hot air gun for soldering. Also, I want to especially thank Engineer Li, who helped me find the bug for several days, finally discovering that a pin on the motor chip wasn't soldered on. I used a hot air gun and solder paste to resolder it. Yes, that's when the microphone melted from the heat, sob sob. For more details, click here: Smart Curtain Demo Video




















参考设计图片
×
 
 
Search Datasheet?

Supported by EEWorld Datasheet

Forum More
Update:2026-03-26 17:38:08

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
community

Robot
development
community

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号