yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
Human Body Infrared Module📖
1.Introduction of module
  • Introduction
2.Tutorial
Arduino
  • body induction lamp
Micro:bit
  • Welcome device
STM32
  • Control LED_GPIO input/output
Download ZIP

Welcome to Human Body Infrared Module repository

Control LED_GPIO input/output

Human_body_infrared_module

Human infrared sensing module: control LED_GPIO input/output

Hardware wiring

1

Human infrared sensing moduleSTM32F103RCT6
VCC5V/3.3V
OUTPA1
NC 
GNDGND

Brief principle

Circuit schematic

2

The LED is connected to the PB4 pin, you need to pay attention to the pin configuration of PB4 (see the code for the specific configuration):

PB4 output high level, LED on;

The PB4 output is low and the LED is off.

When the human infrared sensing module detects an obstacle:

OUT outputs a high level and the LED lights up.

When the human infrared sensor module does not detect an obstacle:

OUT outputs a low level and the LED goes off.

Main code

main.c

​x
#include "stm32f10x.h"
#include "Human_Body_Infrared_Moudle.h"
#include "LED.h"


int main(void)
{
    LED_Init();//LED初始化(PB4)
        Human_Body_Infrared_Moudle_Init();//人体红外模块初始化(PA1)
    
    while(1)
    {
            if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_1) == Bit_SET)//判断人体红外模块是否检测到人
        {
            
            GPIO_WriteBit(GPIOB, GPIO_Pin_4, Bit_SET);//LED 亮
        }
        else
        {
            GPIO_WriteBit(GPIOB, GPIO_Pin_4, Bit_RESET);//LED 灭
        }
    }
}

LED.c

xxxxxxxxxx
#include "LED.h"

void LED_Init(void)//LED初始化(PB4)
{
    GPIO_InitTypeDef GPIO_InitStructure;
    
    /* Enable GPIOB and AFIO clocks */
    /* 使能GPIOB和功能复用IO时钟 */
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE); 
    
    /* JTAG-DP Disabled and SW-DP Enabled */
    /* 禁用JTAG 启用SWD */
    GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);
    
    /* Configure PB4 in output pushpull mode */
    /* 配置PB4 推挽输出模式 */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;   
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 
    GPIO_Init(GPIOB, &GPIO_InitStructure);
    
    /* Set the GPIOB port pin 4 */
    /* 设置PB4端口数据位 */
    GPIO_WriteBit(GPIOB, GPIO_Pin_4, Bit_RESET);
}

LED.h

xxxxxxxxxx
#ifndef __LED_H__
#define __LED_H__

#include "stm32f10x.h"

void LED_Init(void);//LED初始化(PB4)

#endif

Human_Body_Infrared_Moudle.c

xxxxxxxxxx
#include "Human_Body_Infrared_Moudle.h"

void Human_Body_Infrared_Moudle_Init(void)//人体红外模块初始化(PA1)
{
    GPIO_InitTypeDef GPIO_InitStructure;
    
    /* Enable GPIOA */
    /* 使能GPIOA时钟 */
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); 
    
    /* Configure PA1 in Floating input mode */
    /* 配置PA1 浮空输入模式 */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;   
    GPIO_Init(GPIOA, &GPIO_InitStructure);  
}

Human_Body_Infrared_Moudle.h

xxxxxxxxxx
#ifndef __HUMAN_BODY_INFRARED_MOUDLE_H__
#define __HUMAN_BODY_INFRARED_MOUDLE_H__
Welcome device

COMPANY

  • About us
  • Team Style
  • Blog

LEARNING & EXPLORATION

  • Tutorials
  • Edge AI hardware
  • Educational robots
  • Embedded intelligent hardware

WHERE TO BUY

  • Yahboom Online Store
  • Amazon
  • Alibaba
  • AliExpress
  • Mercado

TECHNOLOGY SUPPORT

  • Email: support@yahboom.com

BE A DISTRIBUTOR

  • Email: sales@yahboom.com
QR Code

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文