/* WORK: Demostration of interfacing PIR sensor with
* the Arduino UNO and detection indicating by using LED
* ST ID: FGS_MIT_2021_058
*/
int pinPirSensor = 3; // Sensor pin
int pinLed = 2; // LED pin
void setup() {
pinMode(pinPirSensor, INPUT); // Setup sensor pin as input pin
pinMode(pinLed, OUTPUT); // Setup led pin as output pin
/* Starts serial communication to send out commands through
the USB connection just for debugging purpose
9600 is called the 'baud rate' of the connection */
Serial.begin(9600);
}
void loop() {
int pirSensor = digitalRead(pinPirSensor); // Get PIR sensor value
if(pirSensor == HIGH) { // If PIR detects any signal
digitalWrite(pinLed, HIGH); // Turn on LED
Serial.print("Detected!"); // Send serial message if we need to debug
}else { // If PIR didn't receive any signal
digitalWrite(pinLed, LOW); // Turn off LED
Serial.print("No detection!"); // Send serial message if we need to debug
}
}