Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO Controlled Dual Servo Motor System with IR Sensor for Object Detection

View and Edit Project In Cirkit DesignerImage of Arduino UNO Controlled Dual Servo Motor System with IR Sensor for Object Detection

Circuit Documentation

Summary

This circuit is designed to control two servo motors based on input from an IR sensor using an Arduino UNO. When the IR sensor detects an object, the servo motors will open. When the object is no longer detected, the servo motors will remain closed.

Component List

  1. Arduino UNO

    • Description: A microcontroller board based on the ATmega328P.
    • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
  2. Servo Motor 9G (Servo 1)

    • Description: A small and lightweight servo motor.
    • Pins: VCC 5V, PMW, GND
  3. Servo Motor 9G (Servo 2)

    • Description: A small and lightweight servo motor.
    • Pins: VCC 5V, PMW, GND
  4. IR Sensor

    • Description: An infrared sensor used to detect objects.
    • Pins: out, gnd, vcc

Wiring Details

Arduino UNO

Servo Motor 9G (Servo 1)

Servo Motor 9G (Servo 2)

IR Sensor

Code Documentation

/*
 * This Arduino sketch controls two servo motors based on input from an IR sensor.
 * When the IR sensor detects an object (e.g., a rail), the servo motors will open.
 * When the object is no longer detected, the servo motors will always remain closed.
 */

#include <Servo.h>

Servo servo1; // Servo motor connected to pin D9
Servo servo2; // Servo motor connected to pin D10

const int irSensorPin = 2; // IR sensor output connected to pin D2
const int servo1Pin = 9;  // Servo motor 1 control pin
const int servo2Pin = 10; // Servo motor 2 control pin

void setup() {
  // Initialize the IR sensor pin as input
  pinMode(irSensorPin, INPUT);
  // Attach the servo motors to their respective pins
  servo1.attach(servo1Pin);
  servo2.attach(servo2Pin);
  // Initialize servos to closed position
  servo1.write(90); // Closed position
  servo2.write(90); // Closed position
}

void loop() {
  // Read the IR sensor value
  int irSensorValue = digitalRead(irSensorPin);
  // If the IR sensor detects an object
  if (irSensorValue == HIGH) {
    // Open the servo motors
    servo1.write(0); // Open position
    servo2.write(0); // Open position
  } else {
    // Keep the servo motors closed
    servo1.write(90); // Closed position
    servo2.write(90); // Closed position
  }
  // Small delay to avoid rapid switching
  delay(100);
}

This code initializes the IR sensor and two servo motors. When the IR sensor detects an object, the servo motors move to the open position. When the object is no longer detected, the servo motors return to the closed position.