当前位置:首页 > 科学研究 > 电子编程 > 正文内容

​Arduino Project 048 - Human Body Infrared Detector and Relay Light

RonWang1周前 (12-14)电子编程34

Project 48 Human Body Infrared Detector and Relay Light

Arduino Body Infrared Detector and Relay Light Circuit

/*
 * Coding by Ronwang 
 * This example code is in the public domain
 * Hardware Support by Autaba Website :https://www.autabaec.com
 * HC-SR501 PIR Sensor Works & Interface It With Arduino
 * https://lastminuteengineers.com/pir-sensor-arduino-tutorial/
 * Project 48 Human Body Infrared Detector and Relay Light
*/
int ledPin = 13;                // choose the pin for the LED
int inputPin = 8;               // choose the input pin (for PIR sensor)
int pirState = LOW;             // we start, assuming no motion detected
int val = 0;                    // variable for reading the pin status
 
void setup() {
  pinMode(ledPin, OUTPUT);      // declare LED as output
  pinMode(inputPin, INPUT);     // declare sensor as input
  Serial.begin(9600);
}
 
void loop(){
  val = digitalRead(inputPin);  // read input value
  if (val == HIGH)// check if the input is HIGH
  {            
    digitalWrite(ledPin, HIGH);  // turn LED ON
    if (pirState == LOW) 
{
      Serial.println("Motion detected!");// print on output change
      pirState = HIGH;
    }
  } 
  else 
  {
    digitalWrite(ledPin, LOW); // turn LED OFF
    if (pirState == HIGH)
{
      Serial.println("Motion ended!");// print on output change
      pirState = LOW;
    }
  }
}



版权声明:本文为原创文章,版权归donstudio所有,欢迎分享本文,转载请保留出处!

本文链接:http://parentscn.com/?id=305

标签: Arduino

相关文章

Arduino Project 003 - LED Traffic Light

Arduino Project 003 - LED Traffic Light

You are now going to create a set of traffic lights that will change from green to red, via amber, a...

Arduino Project 034 - TM1637 4Digital 7Segment Display Module

Arduino Project 034 - TM1637 4Digital 7Segment Display Module

A standard 4-digit 7-segment display is needed for clock, timer and counter projects, but it usually...

Arduino Project 001 - LED Blink

Arduino Project 001 - LED Blink

Arduino 电子编程--灯项目及控制,主要使用Arduino编程控制LED灯,实现基本控制Project 1 LED闪烁,基本的应用Project 3和4红绿灯项目项目1 Project...

Arduino Programming Basic - Serial Monitor

Arduino Programming Basic - Serial Monitor

Arduino 程序基础,介绍Arduino程序的基本组成,第一部分编写数个例程,讲解关于变量及变量名称,串口监视器,if循环,for循环,while循环等。第二部分介绍了函数,全局变量,局部变量和静...

Arduino Project 030B - MX1508 H-Driver Motor

Arduino Project 030B - MX1508 H-Driver Motor

MX1508 H-BridgeDual Motor DriverThe driver can drive up to two motors. The H-Bridge dual motor drive...

 Arduino Project 033 - 4 Digital 7 Segment Display

Arduino Project 033 - 4 Digital 7 Segment Display

Showing Heep and number 0-9 on a Common Anode 7-segment LED display. Displays the numbers 0-9 on the...

发表评论

访客

看不清,换一张

◎欢迎参与讨论,请在这里发表您的看法和观点。