Document Details

SpiritedHibiscus6249

Uploaded by SpiritedHibiscus6249

University of Petra

Tags

motion sensors arduino electronics programming

Summary

This document provides a comprehensive guide to using motion sensors, specifically PIR sensors, with Arduino. It includes explanations of the sensor's components, working principles, and various configuration options. The document also demonstrates example use cases and provides code snippets.

Full Transcript

Motion Sensors with Arduino Introduction to Motion Sensors What are Motion Sensors? Motion sensors are devices that detect physical movement in an environment. They are widely used in applications such as security systems, smart lighting, robotics, and automation. Types of Motion Se...

Motion Sensors with Arduino Introduction to Motion Sensors What are Motion Sensors? Motion sensors are devices that detect physical movement in an environment. They are widely used in applications such as security systems, smart lighting, robotics, and automation. Types of Motion Sensors: 1.Passive Infrared (PIR) Sensors: Detects motion based on infrared radiation emitted by objects. 2.Ultrasonic Sensors: Measures distance and detects motion using ultrasonic sound waves. 3.Accelerometers: Detect changes in acceleration or orientation. 4.Microwave Sensors: Uses microwave pulses to detect motion. Passive Infrared (PIR) Sensors PIR sensors detect general movement, but don’t give information as to who or what moved. PIR sensors are commonly called simply “PIR” or sometimes “PID” for “passive infrared detector.” The term passive refers to the fact that PIR devices don’t radiate energy for detection purposes. They work entirely by detecting infrared (radiant heat) emitted by or reflected from objects. Components Overview PIR Sensor: Structure: Contains a pyroelectric sensor, a Fresnel lens, and a control circuit. Working Principle: Detects changes in infrared radiation levels. All objects emit IR radiation. The sensor detects sudden changes in IR patterns. Output Signal: When motion is detected, the sensor’s OUT pin goes HIGH. Otherwise, it remains LOW. Pins: VCC: Power supply (typically 5V). OUT: Outputs HIGH or LOW signals based on motion. GND: Ground connection. Setting Up the PIR Sensor Setting Up the PIR Sensor Time Delay Adjust Function: This potentiometer controls the duration for which the output signal remains HIGH after motion is detected. Adjustment: Use a small screwdriver to rotate the potentiometer: Rotate clockwise to increase the delay. Rotate counterclockwise to decrease the delay. Example Use: If you want the sensor to keep the light or buzzer ON for a longer period after detecting motion, Setting Up the PIR Sensor Sensitivity Adjust Function: This potentiometer controls the range or sensitivity of the sensor's motion detection. Adjustment: Use a screwdriver to adjust: Rotate clockwise to increase sensitivity (detects motion from a farther distance). Rotate counterclockwise to decrease sensitivity. Example Use: For a small room or close-range application, reduce sensitivity. For outdoor or large room applications, increase sensitivity. Setting Up the PIR Sensor Trigger Modes The sensor supports two trigger modes: 1.Single Trigger Mode (Non-repeatable Mode): 1.Operation: The sensor's output is triggered once when motion is detected. Even if motion continues, the output will not retrigger until it resets. 2.Use Case: Suitable for scenarios where you need one-time activation for each motion event, like a single alarm sound or one-time light activation. 3.Configuration: Switch to the Single Trigger Mode as labeled in the figure. Setting Up the PIR Sensor 1.Repeatable Trigger Mode: 1.Operation: The output is retriggered continuously as long as motion is detected. 2.Use Case: Useful for applications like continuous light or alarm activation while motion is ongoing. 3.Configuration: Switch to the Repeatable Trigger Mode as labeled in the figure. Practical Applications Application 1: Motion-Activated Light Objective: Turn on a light when motion is detected. Implementation: Use the LED as a light source in the code. Code for led // Define pins const int PIR_PIN = 2; // PIR sensor output pin const int LED_PIN = 13; // LED pin void setup() { pinMode(PIR_PIN, INPUT); pinMode(LED_PIN, OUTPUT); Serial.begin(9600); Serial.println("PIR Sensor Initializing..."); delay(10000); // Allow sensor to stabilize Serial. println("PIR Sensor Ready!"); } void loop() { int motionDetected = digitalRead(PIR_PIN); if (motionDetected == HIGH) { digitalWrite(LED_PIN, HIGH); Serial.println("Motion detected!"); delay(1000); // Wait 1 second } else { digitalWrite(LED_PIN, LOW); }} Practical Applications Application 2: Security Alarm Objective: Activate a buzzer and send a message to the Serial Monitor when motion is detected. Implementation: Add the buzzer and monitor the serial output to the code. Code for buzzer (enhanced ) const int MOTION_SENSOR_PIN = 7; // OUTPUT pin of motion sensor const int BUZZER_PIN = 3; // Buzzer's pin int motionStateCurrent = LOW; // current state of motion sensor's pin int motionStatePrevious = LOW; // previous state of motion sensor's pin void setup() { Serial.begin(9600); // initialize serial pinMode(MOTION_SENSOR_PIN, INPUT); // set arduino pin to input mode pinMode(BUZZER_PIN, OUTPUT); // set arduino pin to output mode } void loop() { motionStatePrevious = motionStateCurrent; // store old state motionStateCurrent = digitalRead(MOTION_SENSOR_PIN); // read new state if (motionStatePrevious == LOW && motionStateCurrent == HIGH) { // pin state change: LOW -> HIGH Serial.println("Motion detected!"); digitalWrite(BUZZER_PIN, HIGH); // turn on } else if (motionStatePrevious == HIGH && motionStateCurrent == LOW) { // pin state change: HIGH -> LOW Serial.println("Motion stopped!"); digitalWrite(BUZZER_PIN, LOW); // turn off } }

Use Quizgecko on...
Browser
Browser