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

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

RonWang5个月前 (12-14)电子编程284

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 023 - Liquid Crystal Displays - Hello World

Arduino Project 023 - Liquid Crystal Displays - Hello World

Before wiring the LCD screen to your Arduino board we suggest to solder a pin header strip to the 14...

Arduino Project 012 - Piezo Sounder Melody Player

Arduino Project 012 - Piezo Sounder Melody Player

Rather than using the piezo to make annoying alarm sounds, why not use it to play a melody? You are...

​Arduino Project 046 - Based Security System by Arduino with Lcd Display

​Arduino Project 046 - Based Security System by Arduino with Lcd Display

Arduino Project 046 - Based Security System by Arduino with Lcd Display/*  * Project ...

Arduino Project 042 - SD Card Information Basic

Arduino Project 042 - SD Card Information Basic

Arduino Programming Basic -- Reading and Writing to an SD CardProject 42A SD Card InformationArduino...

Arduino Project 015 - Simple Motor Control

Arduino Project 015 - Simple Motor Control

First, you’re going to simply control the speed of a DC motor in one direction, using a power transi...

Arduino Project 045 - RFID Servo and LED Control System

Arduino Project 045 - RFID Servo and LED Control System

Arduino Programming Basic -- RFID Servo and LED Control System Project 45 RFID Servo...