Arduino Motion Detection System with IR Sensor, Servo Motor, and LED

This is an arduino uno project with code for beginners, a simple security system for beginners simulated on proteus , with full project available for free!

Description of the Code

This Arduino project simulates a simple motion-activated servo mechanism using an IR sensor, a servo motor, and an LED. The system detects motion with the IR sensor and performs the following actions when motion is detected:

  1. IR Sensor Activation: When the IR sensor detects motion, it outputs a HIGH signal.
  2. LED Indicator: The LED connected to pin 13 turns on, providing a visual indication of detection.
  3. Servo Motor Motion:
    • The servo motor connected to pin 11 sweeps from 0° to 180° and back to 0°.
    • This sweeping motion mimics an automated action, such as opening and closing a barrier or scanning an area.
  4. System Reset: After completing the sweep, the LED turns off, and the system resets to wait for the next motion detection.

This code is ideal for applications such as automated gates, motion detection systems, or simple robotic arms.



Required Libraries, Components, and Software

Libraries:

  1. Servo.h: Built-in Arduino library for controlling servo motors.
    • Included by default in the Arduino IDE.
    • Used to create and control the servo object (myservo).

Components:

  1. IR Sensor Module:

    • Detects motion or obstacles.
    • Connected to Arduino's digital pin (IRSensor on pin 2).
  2. LED:

    • Provides a visual indication when motion is detected.
    • Connected to pin 13 with a current-limiting resistor (220Ω recommended).
  3. Servo Motor:

    • Performs sweeping motion from 0° to 180° and back.
    • Connected to pin 11 for control.
  4. Resistors:

    • 220Ω or 330Ω for the LED.
  5. Connecting Wires:

    • Male-to-male or male-to-female jumper wires.
  6. Breadboard:

    • For easy wiring and prototyping.
  7. Power Supply:

    • USB cable for powering the Arduino board.
  8. Arduino Board:

    • Any Arduino-compatible board (e.g., Arduino Uno, Nano, Mega).

Software:

  1. Arduino IDE:

  2. Proteus 8 Professional:

    • For simulating the Arduino project virtually.
    • Used to test circuit designs before actual hardware implementation.

Code Breakdown

  1. Libraries and Object Creation:

    • The Servo library is included for controlling the servo motor.
    • An object myservo is created to interact with the servo motor.
  2. Pin Configuration:

    • IRSensor (pin 2): Reads motion detection status.
    • LED (pin 13): Provides visual feedback.
    • Servo motor is attached to pin 11.
  3. Setup:

    • pinMode() configures the pins for the sensor and LED.
    • myservo.attach(11) initializes the servo motor.
  4. Loop:

    • The IR sensor's status is checked using digitalRead(IRSensor).
    • If motion is detected (HIGH signal):
      • The LED turns on.
      • The servo sweeps from 0° to 180° and back with a delay for smooth motion.
      • The LED turns off after the motion.

Schematic:

----------------------------------------------------------------------------------

Schematic




----------------------------------------------------------------------------------
Code:

#include <Servo.h>
int IRSensor = 2; // Connect IR sensor to Arduino pin 2
int LED = 13;     // Connect LED to Arduino pin 13
Servo myservo;    // Create Servo object

void setup() {
  pinMode(IRSensor, INPUT);  // Sensor pin set as INPUT
  pinMode(LED, OUTPUT);      // LED pin set as OUTPUT
  myservo.attach(11);        // Attach the servo to pin 11
}

int pos = 0; // Variable to track servo position

void loop() {
  int sensor_status = digitalRead(IRSensor); // Read IR sensor status

  if (sensor_status == HIGH) { // Check if sensor is activated
    digitalWrite(LED, HIGH);   // Turn LED ON

    // Sweep servo from 0 to 180 degrees
    for (pos = 0; pos <= 180; pos++) {
      myservo.write(pos);
      delay(15); // Small delay for smoother motion
    }

    // Sweep servo back from 180 to 0 degrees
    for (pos = 180; pos >= 0; pos--) {
      myservo.write(pos);
      delay(15); // Small delay for smoother motion
    }

    digitalWrite(LED, LOW); // Turn LED OFF
  }
}

----------------------------------------------------------------------------------------------------------------------------

Project Link:

https://drive.google.com/file/d/1vGt3nR66-63sC0BaXmTL4zHQs8RkpTye/view?usp=drive_link
----------------------------------------------------------------------------------------------------------------------------


  • Arduino Servo Project
  • Arduino IR Sensor Tutorial
  • Motion Detection with Arduino
  • IR Sensor Servo Motor Control
  • Arduino LED Servo Motion
  • Arduino Barrier Control System
  • Automated Motion Sensor Servo
  • Servo Sweep Arduino Example
  • IR Sensor with LED and Servo
  • Proteus Arduino Simulation
  • Arduino Motion Activated Servo
  • IR Sensor and Servo Control Code
  • Arduino Robotics Basics
  • DIY Motion Sensor Project
  • Home Automation with Arduin

  • Comments