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

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

RonWang2个月前 (12-14)电子编程133

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://www.donstudio.cn/?id=305

标签: Arduino

相关文章

Arduino Project 030A - Dual Motor Driver L298N

Arduino Project 030A - Dual Motor Driver L298N

L298N Dual Motor Driver Project Description  The L298N Motor Driver is a control...

Arduino Project 014 - Light Sensor

Arduino Project 014 - Light Sensor

This project introduces a new component known as a Light Dependent Resistor, or LDR. As the name imp...

Arduino Project 027 - Joystick Servo Control

Arduino Project 027 - Joystick Servo Control

In this tutorial, we are going to learn how to use Arduino and a joystick to control two servo motor...

Arduino Project 032 - BMP280 Pressure Sensor LCD Display

Arduino Project 032 - BMP280 Pressure Sensor LCD Display

For this project we will use Arduino Uno and BMP280 along with LCD 16x2 display module to display te...

C语言调试运行环境Pelles C的安装

C语言调试运行环境Pelles C的安装

C语言调试运行环境之TurboC一文介绍了在32位Windows系统下安装C语言运行环境之TubroC,但是由于TurobC只能在32位系统下运行,导致现在很多Windows10和Windows 11...

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...

发表评论

访客

看不清,换一张

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