- Get link
- X
- Other Apps
- Get link
- X
- Other Apps
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:
- IR Sensor Activation: When the IR sensor detects motion, it outputs a HIGH signal.
- LED Indicator: The LED connected to pin 13 turns on, providing a visual indication of detection.
- 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.
- 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:
- 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:
IR Sensor Module:
- Detects motion or obstacles.
- Connected to Arduino's digital pin (
IRSensor
on pin 2).
LED:
- Provides a visual indication when motion is detected.
- Connected to pin 13 with a current-limiting resistor (220Ω recommended).
Servo Motor:
- Performs sweeping motion from 0° to 180° and back.
- Connected to pin 11 for control.
Resistors:
- 220Ω or 330Ω for the LED.
Connecting Wires:
- Male-to-male or male-to-female jumper wires.
Breadboard:
- For easy wiring and prototyping.
Power Supply:
- USB cable for powering the Arduino board.
Arduino Board:
- Any Arduino-compatible board (e.g., Arduino Uno, Nano, Mega).
Software:
Arduino IDE:
- Required to upload the code to the Arduino board.
- Can be downloaded from Arduino's official website.
Proteus 8 Professional:
- For simulating the Arduino project virtually.
- Used to test circuit designs before actual hardware implementation.
Code Breakdown
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.
- The
Pin Configuration:
IRSensor
(pin 2): Reads motion detection status.LED
(pin 13): Provides visual feedback.- Servo motor is attached to pin 11.
Setup:
pinMode()
configures the pins for the sensor and LED.myservo.attach(11)
initializes the servo motor.
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:
----------------------------------------------------------------------------------
----------------------------------------------------------------------------------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
----------------------------------------------------------------------------------------------------------------------------
- Get link
- X
- Other Apps
Comments
Post a Comment