Arduino中文教程---认识HC-SR501模块并制作人体感应LED

in #utopian-io6 years ago (edited)

What Will I Learn?(将会学到什么)

  • 了解Arduino的人体红外传感器
  • 使用人体红外传感器制作人体感应灯

图片.png

Requirements(所需元件)

  • Arduino UNO开发板

  • HC-SR501人体红外传感器

    图片.png

  • 面包板、跳线、LED等配件

Difficulty(难度)

  • 基础

Tutorial Contents(教程内容)

一、了解Arduino的人体红外传感器

自然界中任何的物体都会辐射出红外线,只不过物体不同,辐射出来的红外线波长不相同而已。HC-SR501人体红外传感器就是根据人体辐射出的波长大约在10000nm左右的红外线,从而感应出人体的接近与远离。下表为不同颜色的波长分布:

光线波长
紫光0.4-0.43μm
蓝光0.43-0.47μm
青光0.47-0.50μm
绿光0.50-0.56μm
黄光0.56-0.59μm
橙光0.59-0.62μm
红光0.62-0.76μm
红外0.76-100μm

其实还可以根据不同光线的波长进行调节红外传感器,进而让传感器检测不同波长的光线。

HC-SR501人体红外传感器各元件的作用介绍:

图片.png

  • 时间延迟调节:旋钮形式,用于调节检测到当前红外后的延迟时间

  • 感应距离调节:旋钮形式,用于调节模块的灵敏度

  • 检测模式跳线:选择单次检测或连续检测

  • VCC:用于给模块提供电源,一般为5V

  • GND:接地引脚

  • 输出针脚:输出数字信号

二、Arduino连接HC-SR501传感器并获取数据

  • 连接Aruino UNO与HC-SR501

图片.png

HC-SR501Arduino
VCC5V
输出引脚D7
GNDGND
  • 编写获取HC-SR501数据程序

    • 初始化setup(),设置连接HC-SR501的数字引脚为输入模式
    void setup()
    {
        pinMode(7, INPUT);
        Serial.begin(9600);
    }
    
    • loop()函数获取数据

      void loop()
      {
          pirValue = digitalRead(7);
          Serial.print(pirValue);
          delay(1000);
      }
      
      
  • 打开串口监视框查看数据,测试的时候慢慢靠近HC-SR501模块,看打印出什么

    • 如下图,当人体接近HC-SR501传感器小于一定的距离的时候,就会输出1至Arduino 的D7引脚。
    • 当大于设定的距离的时候,模块则会输出0到D7引脚
    • 当前为连续检测模式下的效果

    图片.png

三、制作红外感应灯

图片.png

需求分析:

  • 在模块上旋钮先设定好需要检测的距离
  • 当人体靠近到一定距离的时候,输出高电平,LED亮
  • 当人体远离该距离的时候,输出低电平,LED灭

整合程序:

void setup()
{
    pinMode(13, OUTPUT);
    pinMode(7, INPUT);
    digitalWrite(13, LOW);
    Serial.begin(9600);
}

void loop()
{
    pirValue = digitalRead(7);
    digitalWrite(13, pirValue);
}

全部程序:

void setup()
{
    pinMode(13, OUTPUT);
    pinMode(7, INPUT);
    digitalWrite(13, LOW);
    Serial.begin(9600);
}
void loop()
{
    pirValue = digitalRead(7);
    if (pirValue == 0)
    {
      digitalWrite(13, LOW);
    }
    else if (pirValue == 1)
    {
      digitalWrite(13, HIGH);;
    }
    delay(500);
}

Curriculum(系列教程)



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

wow。这个可以有,我也是Arduino爱好者

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

thanks once more

Hey @cha0s0000 I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Suggestions

  • Contribute more often to get higher and higher rewards. I wish to see you often!
  • Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck!

Get Noticed!

  • Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

Coin Marketplace

STEEM 0.18
TRX 0.14
JST 0.030
BTC 58659.71
ETH 3164.52
USDT 1.00
SBD 2.43