Hardware Used:
- Infrared Motion Sensor Module: HC-SR501
- Text-to-Speech Module: XFS5152
- Development Board: Ai-M61-32S
- General Input/Output with pull-up/pull-down
- Multiplexing with pull-up/pull-down
- Analog function
- External Interrupts (rising/falling edge, high/low level)
- Hardware Debouncing
- Drive Strength Control
GPIO Overview:
GPIO (General Purpose Input Output) features on Bouffalo series chips include:
In BL MCU SDK, pin configuration can be done in two ways:
- Pinmux Table: Located in /bsp/board/xxx_board/pinmux_config.h. Recommended for multiplexing functions.
- Standard GPIO Interface: Only supports basic input/output and interrupts.
How does the PIR Sensor work?
Every object above absolute zero emits infrared radiation. Hotter objects emit more radiation, which is invisible to the human eye. PIR sensors are designed to detect this radiation.
Components:
- Pyroelectric Sensor (circular part seen below): Detects infrared radiation.
- Fresnel Lens: Focuses infrared onto the sensor.
Working Principle:
When motion is not detected, the output is zero (background radiation). When motion occurs in front of either half of the sensor, voltage changes between the two halves, indicating movement.
Fresnel Lens: Composed of concentric grooves acting as individual refracting surfaces to focus light, enhancing detection range and field of view.
HC-SR501 Wiring Diagram:
Three pins hidden under the Fresnel lens:
- VCC: 5V – 12V
- OUT: High when motion detected, Low when idle
- GND: Ground
- L (Single Trigger): Output stays high during the delay set by potentiometer.
- H (Repeat Trigger): Output remains high and can retrigger continuously.
- Sensitivity: Clockwise = Increase, Counterclockwise = Decrease
- Delay: Clockwise = Longer delay, Counterclockwise = Shorter delay
- Use correct voltage (4.8V–20V, not 3.3V).
- Clean dust from lens/sensor.
- Adjust potentiometer for sensitivity.
- If nonfunctional after these checks, sensor may be defective.
- Default: LED off.
- When motion detected: LED turns red.
- TTS modules like XFS5152/SYN6288 (used here)
- ISD4000 Series Voice Chips
- UART/Key-controlled MP3 Modules
- OTP (One-Time Programmable) chips
Trigger Modes:
- L (Single Trigger): Output stays high during the delay set by potentiometer.
- H (Repeat Trigger): Output remains high and can retrigger continuously.
Adjustments:
- Sensitivity: Clockwise = Increase, Counterclockwise = Decrease
- Delay: Clockwise = Longer delay, Counterclockwise = Shorter delay
Voltage Regulator:
Onboard 3.3V regulator allows 4.5V–12V supply (5V preferred).
Troubleshooting:
- Use correct voltage (4.8V–20V, not 3.3V).
- Clean dust from lens/sensor.
- Adjust potentiometer for sensitivity.
- If nonfunctional after these checks, sensor may be defective.
Code Snippet Explanation:
#include "bflb_mtimer.h"
#include "board.h"
#include "bflb_gpio.h"
#include "locale.h"
#define DBG_TAG "MAIN"
#include "log.h"
struct bflb_device_s *gpio;
int main(void)
{
board_init();
gpio = bflb_device_get_by_name("gpio");
bflb_gpio_init(gpio, GPIO_PIN_13, GPIO_INPUT | GPIO_PULLDOWN | GPIO_SMT_EN | GPIO_DRV_0);
bflb_gpio_init(gpio, GPIO_PIN_12, GPIO_OUTPUT | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_0);
while (1) {
bool isH = bflb_gpio_read(gpio, GPIO_PIN_13);
if (isH) {
bflb_gpio_set(gpio, GPIO_PIN_12);
} else {
bflb_gpio_reset(gpio, GPIO_PIN_12);
}
LOG_F("Motion detected=%d\r\n", isH);
...
Read more »