Hi everyone! I am a beginner at Arduino and am currently using an Arduino UNO. My goal for this project is to create a device (using a PIR) that could accurately blink an LED light whenever someone is close by. But in the PIR's sense, whenever any heat signature is nearby. My code is at the bottom, can anyone help me?
// This is an introduction to all the variables
int ledPin = 11; // LED
int pirPin = 2; // input pin for the PIR sensor
int pirStat = LOW; // we start assuming no motion is detected
int pirState = 0; // variable for reading the status, also the value
void setup() {
pinMode(ledPin, OUTPUT); // the LED is output
pinMode(pirPin, INPUT); // the sensor is input
}
void loop(){
pirState = digitalRead(pirPin); // read input value
if (pirState == HIGH) { // check if the input is HIGH
digitalWrite(ledPin, HIGH); // turn LED ON
} else {
digitalWrite(ledPin, LOW); // turn LED OFF
if (pirStat == HIGH){ // if the PIR state is high, it switches on the LED and then turns low again
digitalWrite(ledPin, HIGH);
pirStat = LOW;
}
}
}
I also used this piece of code-
const int ledPin = 11; // LED
const int inputPin = 2; // input pin for the PIR sensor
const int pirState = LOW; // we start assuming no motion is detected
const int val = 0; // variable for reading the status
void setup() {
pinMode(ledPin, OUTPUT); // the LED is output
pinMode(inputPin, INPUT); // the sensor is 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
Serial.println("Motion Detected!");
else {
digitalWrite(ledPin, LOW); // turn LED OFF
(pirState = LOW);
Serial.println("Motion is gone!");
}
}