当前位置:网站首页>Obstacle avoidance sensor module (stm32f103c8t6)

Obstacle avoidance sensor module (stm32f103c8t6)

2022-06-24 19:23:00 Me-Space

This experiment prints the prompt through the serial port debugging assistant , And light up LED The lamp .

One 、 summary

1. brief introduction

The sensor module has strong adaptability to ambient light , It has a pair of infrared transmitting and receiving tubes , The transmitting tube emits infrared rays of a certain frequency , When the detection direction encounters an obstacle ( Reflecting surface ) when , The infrared ray is reflected back and received by the receiving tube , After being processed by the comparator circuit , The output indicator lights up , At the same time, the signal output interface outputs digital signals ( A low level signal ).

2. Parameter description

  1. When the module detects an obstacle ahead , The output indicator on the circuit board will be on , meanwhile OUT Port persistence Output low level signal , The module detects the distance 2-30cm, Detection angle 35 degree , The detection distance can be adjusted by potentiometer , Adjust the potentiometer clockwise , The detection distance will increase , Counter clockwise voltage regulator , The detection distance is reduced .
  2. Sensor active infrared reflection detection , Therefore, the reflectivity and shape of the target are the key to the detection distance . Among them, black The detection distance is small , Large white , Small area and small distance , Large area and large distance .
  3. Sensor module output port OUT It can be directly connected with MCU IO Just connect your mouth , You can also directly drive a 5v Relay .
  4. The comparator adopts LM393, Stable work .
  5. May adopt 3-5v The DC power supply supplies power to the module . When the power is on , The red power indicator is on .
  6. Unable to detect black objects

Two 、 Experimental materials

  1. Minimum system STM32F10SC8T6.
  2. Obstacle avoidance sensor module .
  3. There are several DuPont lines .

3、 ... and 、 Hardware connection

Module pin GPIO
VCCVCC
GNDGND
OUTPA1

notes :0: Object detected ,1: No object detected

Four 、 Implement the program

  1. initialization
void Infrared_Pin_Init(void)
{
    
	GPIO_InitTypeDef GPIO_InitStruct;
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
	
	GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;// Floating input 
	GPIO_InitStruct.GPIO_Pin = GPIO_Pin_1;
	GPIO_Init(GPIOA,&GPIO_InitStruct);
}
  1. data fetch
//0: Object detected 
int Infrared_Value(void) 
{
    
	uint8_t infrared_val = 0;
	
	infrared_val = GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_1);
	
	return infrared_val;
}
  1. The main function
int main(void)
{
    
	Sys_Delay_Init();
	Infrared_Pin_Init();
	Usart1_Pin_Init(115200);
	printf(" Successful initialization \r\n");
	Led_Init();
	
	while(1)
	{
    
		if(!Infrared_Value())
		{
    
			printf(" Objects ahead \r\n");
			GPIO_SetBits(GPIOA,GPIO_Pin_0);// Lighten up led The lamp 
		}
		else
		{
    
			GPIO_ResetBits(GPIOA,GPIO_Pin_0);// close led The lamp 
		}
	}
}

5、 ... and 、 Experimental results  Insert picture description here

Complete procedures and relevant data :
link :https://pan.baidu.com/s/1WSxbwlZuh6QmhmGUC5YIsg
Extraction code :xlin

If there is any mistake, please point out , thank you !

原网站

版权声明
本文为[Me-Space]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202211331529042.html