YS312 Pyroelectric Infrared Sensor
The YS312 is a sensor developed by the Senba brand. Below is an introduction covering its product overview, features, applications, performance parameters, and code snippet.
I. Product Overview
The YS312 is a pyroelectric infrared sensor that integrates an AD chip and a human body detection sensing element within an electromagnetic shielding case. The sensing element detects human movement signals and transmits them to the AD chip, which then performs signal acquisition and filtering to output a 16-bit digital signal. These signals are processed by a microcontroller via peripheral circuits to enable various functions.
II. Features
-
16-bit digital signal output
-
Single-wire serial data communication
-
Low power consumption
III. Applications
-
Consumer Electronics: Toys, digital photo frames, doorbells, TVs, refrigerators, air conditioners, etc.
-
Smart Home & Security: Network cameras, personal alarms, car anti-theft systems, etc.
-
Lighting Systems: Automatic on/off functionality for indoor, garden, corridor, and stairway lighting.
IV. Performance Parameters
1. Internal block diagram (not included in this text)
2. Working conditions
Power supply voltage: 2.2--5.5V
Working current: 5--20uA
ADC resolution: 16 bits
Detection wavelength: 14um
Low-pass filter cutoff frequency: 7Hz
High-pass filter cutoff frequency: 0.44Hz
#error Delete this line after defining the PIR pin function
#define PIR_PIN // Definition of PIR pin
#define PIR_PIN_OUT // Definition of PIR pin output mode
#define PIR_PIN_IN // Definition of PIR pin input mode
#error Delete this line after defining MCU's enable/disable global interrupt functions
#define ENINT() // Define to enable global interrupt
#define DISINT() // Define to disable global interrupt
typedef unsigned char u8;
typedef unsigned int u16;
typedef unsigned long u32;
u16 pirDataLast; // Previous PIR data
u16 difference; // Difference value
typedef struct
{
u8 Timer1ms_F : 1;
}_Flag;
_Flag Flag;
void DelayUs(u8 nus)
{
#error Delete this line after implementing microsecond-level delay
}
/************************************************
* @Function Name : PIR_Read
* @Description : PIR data reading
1. PIR generates an interrupt signal approximately every 16ms (pulls the output pin high).
2. After detecting a PIR interrupt signal, it must stay high for at least 100μs before being forcibly pulled low.
3. The MCU's IO pin outputs low level for 4–8μs, then high level for 4–8μs,
then switches to input mode to read 1 bit of data (high bits are read first).
The total time of pulling low + high + reading 1 bit should not exceed 31.25μs (recommended not to exceed 25μs).
4. Repeat step 3 until all 19 bits of data are read.
5. After reading all the data, the MCU IO outputs a low level and then switches to input mode.
* @IN_Parameter : None
* @Return parameter : Detection status 1: Detected 0: Not detected
***********************************************/