Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade

PIR Motion Sensor - Detecting Motion with Arduino

The Importance and Utility of PIR Motion Sensors

PIR (Passive Infrared) motion sensors are essential components in various electronic systems, including security systems, home automation, and robotics. These sensors detect changes in infrared radiation emitted by objects in their field of view, allowing them to accurately detect motion. PIR motion sensors are widely used due to their low cost, simplicity, and reliability. Understanding how to use PIR motion sensors with Arduino opens up a world of possibilities for creating interactive and responsive projects.

Project: Creating a Motion-Activated LED Light

In this project, we will create a motion-activated LED light using an Arduino and a PIR motion sensor. The objective is to turn on an LED when motion is detected and turn it off after a certain period of inactivity. This project can be useful for applications such as automatic lighting in dark areas or as a security measure to detect intruders.

List of Components:

Examples:

  1. Wiring the Components:

Before writing the code, let's wire the components as follows:

  • Connect the VCC pin of the PIR motion sensor to the 5V pin of the Arduino.
  • Connect the GND pin of the PIR motion sensor to the GND pin of the Arduino.
  • Connect the OUT pin of the PIR motion sensor to digital pin 2 of the Arduino.
  • Connect the anode (long leg) of the LED to digital pin 13 of the Arduino.
  • Connect the cathode (short leg) of the LED to the 220-ohm resistor.
  • Connect the other end of the resistor to the GND pin of the Arduino.
  1. Code Explanation:
int pirPin = 2; // PIR motion sensor output pin
int ledPin = 13; // LED pin

void setup() {
  pinMode(pirPin, INPUT); // Set PIR pin as input
  pinMode(ledPin, OUTPUT); // Set LED pin as output
  Serial.begin(9600); // Initialize serial communication
}

void loop() {
  int pirState = digitalRead(pirPin); // Read PIR sensor state

  if (pirState == HIGH) { // If motion is detected
    digitalWrite(ledPin, HIGH); // Turn on the LED
    Serial.println("Motion detected!");
    delay(5000); // Wait for 5 seconds
  } else {
    digitalWrite(ledPin, LOW); // Turn off the LED
  }
}
  1. Usage and Challenges:

This example code demonstrates the basic functionality of a PIR motion sensor with Arduino. When motion is detected, the LED connected to pin 13 will turn on, and a message will be printed to the serial monitor. After 5 seconds of inactivity, the LED will turn off.

One common challenge when using PIR motion sensors is false triggering caused by environmental factors like changes in temperature or airflow. To reduce false triggers, it is recommended to adjust the sensitivity and delay settings on the sensor.

To share Download PDF

Gostou do artigo? Deixe sua avaliação!
Sua opinião é muito importante para nós. Clique em um dos botões abaixo para nos dizer o que achou deste conteúdo.