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

Arduino UNO Controlled DC Motor with IR and Tilt Sensor Feedback

View and Edit Project In Cirkit DesignerImage of Arduino UNO Controlled DC Motor with IR and Tilt Sensor Feedback

Circuit Documentation

Summary of the Circuit

This circuit is designed to control a DC gearmotor using an Arduino UNO microcontroller in conjunction with an L298N DC motor driver. The system also includes two infrared (IR) sensors and a tilt sensor to provide input signals to the Arduino, which then processes these signals to determine the motor's operation. The motor is controlled based on the tilt sensor's state and the detection of objects by the IR sensors. The Arduino UNO board is responsible for reading sensor inputs, making decisions, and driving the motor through the motor driver.

Component List

Arduino UNO

L298N DC Motor Driver

Gearmotor DC / Motorreductor

IR Sensor (2x)

Tilt Sensor

Wiring Details

Arduino UNO

L298N DC Motor Driver

Gearmotor DC / Motorreductor

IR Sensor

Tilt Sensor

Documented Code

// Pin definitions
const int irSensor1Pin = 7;
const int irSensor2Pin = 6;
const int tiltSensorPin = 2;
const int motorEnPin = 3;
const int motorIn3Pin = 5;
const int motorIn4Pin = 4;

// Boolean variables
bool IsTilt = false;
bool OnlyOneIR = false;

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

  // Initialize sensor pins
  pinMode(irSensor1Pin, INPUT);
  pinMode(irSensor2Pin, INPUT);
  pinMode(tiltSensorPin, INPUT);

  // Initialize motor control pins
  pinMode(motorEnPin, OUTPUT);
  pinMode(motorIn3Pin, OUTPUT);
  pinMode(motorIn4Pin, OUTPUT);
}

void loop() {
  // Read sensor values
  int irSensor1Value = digitalRead(irSensor1Pin);
  int irSensor2Value = digitalRead(irSensor2Pin);
  int tiltSensorValue = digitalRead(tiltSensorPin);

  // Update boolean variables
  IsTilt = (tiltSensorValue == HIGH);
  OnlyOneIR = (irSensor1Value != irSensor2Value);

  // Print boolean states to serial monitor
  Serial.print("IsTilt: ");
  Serial.print(IsTilt);
  Serial.print(" | OnlyOneIR: ");
  Serial.println(OnlyOneIR);

  // Control DC motor
  if (IsTilt && OnlyOneIR) {
    digitalWrite(motorEnPin, HIGH);
    digitalWrite(motorIn3Pin, HIGH);
    digitalWrite(motorIn4Pin, LOW);
  } else {
    digitalWrite(motorEnPin, LOW);
    digitalWrite(motorIn3Pin, LOW);
    digitalWrite(motorIn4Pin, LOW);
  }

  // Small delay to avoid spamming the serial monitor
  delay(100);
}

Filename: sketch.ino

Description: This code is designed to run on an Arduino UNO. It reads inputs from two IR sensors and a tilt sensor to determine the state of the system. Based on these inputs, it controls a DC gearmotor through the L298N motor driver. The motor is enabled and set to rotate in a specific direction when the tilt sensor is triggered and only one of the IR sensors detects an object. The serial monitor outputs the status of the tilt and IR sensors for debugging purposes.