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

Arduino UNO-Based Dual IR Sensor Controlled Servo Motor System

View and Edit Project In Cirkit DesignerImage of Arduino UNO-Based Dual IR Sensor Controlled Servo Motor System

Circuit Documentation

Summary

This circuit utilizes an Arduino UNO microcontroller to control two servo motors based on input from two IR sensors. The IR sensors detect obstacles, and depending on which sensor is triggered, the servo motors will either open or close. The circuit is powered by the 5V supply from the Arduino UNO.

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 (x2)

    • Description: A small servo motor used for precise control of angular position.
    • Pins: VCC 5V, PMW, GND
  3. IR Sensor (x2)

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

Wiring Details

Arduino UNO

Servo Motor 9G (1)

Servo Motor 9G (2)

IR Sensor (1)

IR Sensor (2)

Code Documentation

/*
 * This Arduino sketch controls a servo motor based on input from two IR sensors.
 * When the first IR sensor detects an obstacle, the servo motor closes.
 * When the second IR sensor detects an obstacle (distance under 10 cm),
 * the servo motor opens.
 */

#include <Servo.h>

// Define pin connections
const int irSensor1Pin = 7;
const int irSensor2Pin = 8;
const int servoPin = 9;

// Create servo object
Servo myServo;

void setup() {
  // Initialize serial communication
  Serial.begin(9600);

  // Attach the servo to the pin
  myServo.attach(servoPin);

  // Set IR sensor pins as input
  pinMode(irSensor1Pin, INPUT);
  pinMode(irSensor2Pin, INPUT);
}

void loop() {
  // Read IR sensor values
  int irSensor1State = digitalRead(irSensor1Pin);
  int irSensor2State = digitalRead(irSensor2Pin);

  // Check if the first IR sensor detects an obstacle
  if (irSensor1State == HIGH) {
    // Close the servo
    myServo.write(0); // Adjust angle as needed
    Serial.println("IR Sensor 1 detected obstacle: Closing servo");
  }
  // Check if the second IR sensor detects an obstacle
  else if (irSensor2State == HIGH) {
    // Open the servo
    myServo.write(90); // Adjust angle as needed
    Serial.println("IR Sensor 2 detected obstacle: Opening servo");
  }
  delay(100); // Small delay to debounce sensor readings
}

This code initializes the servo motor and IR sensors, reads the sensor values, and controls the servo motor based on the sensor inputs. When the first IR sensor detects an obstacle, the servo motor closes. When the second IR sensor detects an obstacle, the servo motor opens.