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

Arduino-Controlled IR Sensor and Servo Motor Obstacle Interaction

View and Edit Project In Cirkit DesignerImage of Arduino-Controlled IR Sensor and Servo Motor Obstacle Interaction

Circuit Documentation

Summary

This circuit is designed to control a servo motor and two LEDs based on the input from an IR sensor. The Arduino UNO microcontroller is used to read the IR sensor output and control the servo motor and LEDs accordingly. When the IR sensor detects an obstacle, the servo motor rotates to 90 degrees for a duration of 2 seconds, and one of the LEDs lights up. The sensor is checked every 0.1 seconds for obstacle detection.

Component List

Sensor FC-51 IR

Arduino UNO

SG90 Servo Motor

LED: Two Pin (red)

Wiring Details

Sensor FC-51 IR

Arduino UNO

SG90 Servo Motor

LED: Two Pin (red)

Documented Code

/*
 * This Arduino sketch controls a servo motor and two LEDs based on input from an
 * IR sensor. When the IR sensor detects an obstacle, the servo motor rotates 90
 * degrees for 2 seconds, and the LED connected to pin D8 lights up. The sensor
 * is read every 0.1 seconds.
 */

#include <Servo.h>

// Pin definitions
const int irSensorPin = 8; // IR sensor output connected to D8
const int ledPin = 8;      // LED anode connected to D8
const int servoPin = 3;    // Servo PWM connected to D3

Servo myServo;

void setup() {
  pinMode(irSensorPin, INPUT);
  pinMode(ledPin, OUTPUT);
  myServo.attach(servoPin);
  myServo.write(0); // Initialize servo to 0 degrees
}

void loop() {
  int sensorValue = digitalRead(irSensorPin);
  if (sensorValue == HIGH) { // Obstacle detected
    digitalWrite(ledPin, HIGH); // Turn on LED
    myServo.write(90); // Rotate servo to 90 degrees
    delay(2000); // Wait for 2 seconds
    myServo.write(0); // Return servo to 0 degrees
    digitalWrite(ledPin, LOW); // Turn off LED
  }
  delay(100); // Read sensor every 0.1 seconds
}

Filename: sketch.ino

This code is written for the Arduino UNO microcontroller. It initializes the servo motor and sets up the IR sensor and LED pin modes. In the main loop, it reads the sensor value and, if an obstacle is detected, it activates the LED and moves the servo motor. After a delay, it resets the servo motor and turns off the LED before checking the sensor again.