Objective:

In this project , we will  use Arduino to drive HC-SR505 and detect human motion. If a person is close to the sensor (within 3 meters),  HC-SR505  will output high voltage and the LED will flash.

Parts and Devices:

Arduino UNO R3 x 1

USB cable x 1

LED x 1

HC-SR505 motion sensor x 1

Jumper wires

Circuit Graph:

HC-SR505_bb

Sample Code:

int SR505=7;//模块信号输出引脚接数字7口
int LED=13;//LED灯接13口
void setup()
{
pinMode(LED,OUTPUT);//设定LED脚为输出
pinMode(SR505,INPUT);//设定SR505信号引脚为输入
Serial.begin(9600);//设定串口波特率
}
void loop()
{
if(digitalRead(SR505)==HIGH)//判断传感器输出是否为高电平
{
Serial.println(“Enter The Sensing Area “);
digitalWrite(LED,HIGH);//有人不进入感应区LED闪烁
delay(10);
digitalWrite(LED,LOW);
delay(10);
}
else
{
Serial.println(“NO Man”);//无人进去感应区LED熄灭
digitalWrite(LED,LOW);
}
delay(500);
}

Result:

Load above code into Arduino IDE, open serial terminal in upright corner. When a person is close to the sensor, the serial window will show , “Enter The Sensing Area” and LED will flash.

1

When a person leave the sensor away, the serial window will show “no man” and LED will turn off.

2