Ad Code

Responsive Advertisement

Ticker

6/recent/ticker-posts

How To Make an Automatic barrier using IR sensor, Object detection, smart, simple Circuit

 How To Make an Automatic barrier using IR Sensor, Object detection, smart, simple Circuit


Here’s a code for your Arduino project using a servo motor and an IR sensor. In this scenario, when the IR sensor detects an object, the servo motor arm moves to 120 degrees and stays there for 2 seconds before returning to its initial position.

Components Required:

  • 1 x Arduino
  • 1 x Servo motor
  • 1 x IR sensor (e.g., IR obstacle avoidance sensor)
  • Jumper wires
  • 1 Green LED and one Red LED with Resistance

Circuit Diagram:

  • Servo Motor:
    • Connect the signal pin to Arduino digital pin 9
    • Connect the VCC to 5V
    • Connect the GND to GND
  • IR Sensor:
    • Connect the output pin to Arduino digital pin 7
    • Connect the VCC to 5V
    • Connect the GND to GND
  • LED Connections:
    • Connect the RED LED to 11
    • Connect the GREEN LED to 10

Video Link: - Click Here For Video

How To Make an Automatic barrier using IR sensor, Object detection, smart, simple Circuit: -



How To Make an Automatic barrier using IR sensor Arduino Programming: -

Arduino IDE Program

#include <Servo.h>

Servo myServo;  // Create a servo object to control the servo motor
int irSensorPin = 7;  // Pin where the IR sensor is connected
int irState;  // Variable to store the sensor state
int green = 10;//led
int red = 11;//led

void setup() {
  myServo.attach(9);  // Attach the servo on pin 9
  pinMode(irSensorPin, INPUT);  // Set the IR sensor pin as input
  myServo.write(0);  // Initial position of the servo (0 degrees)
  pinMode(green, OUTPUT);
  pinMode(red, OUTPUT);
 
}

void loop() {
  irState = digitalRead(irSensorPin);  // Read the state of the IR sensor

  if (irState == LOW) {  // If IR sensor detects an object (LOW state when an object is near)
    delay(1000);
    digitalWrite(green,LOW);
    digitalWrite(red,HIGH);
    myServo.write(120);  // Move servo to 120 degrees
    delay(2000);  // Wait for 2 seconds
   
  }else{
    myServo.write(0);  // Move servo back to 0 degrees
    digitalWrite(green,HIGH);
    digitalWrite(red,LOW);
  }

  delay(100);  // Small delay for stability
}



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

Explanation:

  1. The IR sensor detects an object.
  2. When an object is detected, the servo motor moves its arm to 120 degrees, simulating the parking token scenario and green LED will turn on after 1 sec and red will be off.
  3. After 2 seconds, the servo arm returns to its original position (0 degrees) and green LED turns off and red LED turned on.
  4. The code continuously checks for objects using the IR sensor.

Circuit Simulation:

You can use Tinkercad to simulate this project by adding the ultrasonic sensor, buzzer, and Arduino. Run the simulation to check how it works! Let me know if you need more details or help setting up.

Share, Support, and Subscribe!!! 1. PRO KAM EXPLAINED 2. Knowledge KAM 3. PRO KAM Follow us on 1. Facebook 2. Instagram 3. Pinterest 4. Blogspot 5 Twitter If you have any other ideas to make me design, you can describe them in the comment section and if I can, I will make a designing video on it. So I am waiting #prokam #wtc #Arduino #ideas #projects #diy #how #to

Post a Comment

0 Comments

Ad Code

Responsive Advertisement