pir motion sensor circuit diagram using arduino uno

Creating a DIY Automated Lighting Control System using Arduino and PIR Motion Sensor Module: a step-by-step guide Leave a comment

This Arduino Code is a simple yet effective solution for creating an automated lighting control system using an Arduino Board and PIR Motion Sensor Module. The code is easy to understand and implement, and it is a great starting point for those who want to learn about using PIR Motion Sensor Module and Arduino for automating tasks. The code utilizes the digital input and output capabilities of the Arduino board to read the PIR sensor’s output and control the state of an LED. The code is also flexible and can be easily modified to add more advanced features like connecting multiple lights or other devices based on motion detection.

#include <NewPing.h>

const int pirPin = 2; // pin connected to the PIR sensor's output
const int ledPin = 13; // pin connected to the LED

void setup() {
pinMode(pirPin, INPUT); 
pinMode(ledPin, OUTPUT);
}

void loop() {
int motion = digitalRead(pirPin); // read the value of the PIR sensor's output pin

if (motion == HIGH) { // check if motion is detected
digitalWrite(ledPin, HIGH); // turn on the LED
} 
else {
digitalWrite(ledPin, LOW); // turn off the LED
}
}

This is a simple code for an automated lighting control system using an Arduino PIR Motion Sensor Module. It uses the digitalRead() function to read the value of the PIR sensor’s output pin and the digitalWrite() function to control the state of the LED. When motion is detected, the PIR sensor outputs a HIGH signal, which causes the LED to turn on. When no motion is detected, the PIR sensor outputs a LOW signal, and the LED turns off.

It’s important to note that the pin numbers used in this code are just an example, you should check the pin connections of your sensor and adjust accordingly. Also, you can add a delay to the loop() function to adjust the duration of the LED staying on after motion is detected, or you can add other features to the code such as connecting multiple lights or controlling other devices based on the motion detection.

Leave a Reply

SHOPPING CART

close