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

Arduino-Controlled Dual DC Motor Driver with Hall Effect Sensors and Indicator LEDs

View and Edit Project In Cirkit DesignerImage of Arduino-Controlled Dual DC Motor Driver with Hall Effect Sensors and Indicator LEDs

Circuit Documentation

Summary

This circuit is designed to control two DC motors and three LEDs using an Arduino UNO microcontroller. The motors are driven by an L293D motor driver, and their operation is influenced by the state of three Hall sensors. The LEDs are used as indicators for the Hall sensors' output. The circuit is powered by a 9V battery, and it includes resistors for current limiting purposes.

Component List

Microcontroller

Motor Driver

Motors

Power Supply

Sensors

LEDs

Resistors

Wiring Details

Arduino UNO

L293D Motor Driver

DC Motors

9V Battery

Hall Sensors

LEDs

Resistors

Documented Code

// Code for Arduino UNO
const int hallSensor1 = A0;
const int hallSensor2 = A1;
const int hallSensor3 = A2;
const int motor1Pin1 = 5;
const int motor1Pin2 = 6;
const int motor2Pin1 = 7;
const int motor2Pin2 = 8;
const int led1Pin = 3;
const int led2Pin = 2;
const int led3Pin = 12;

void setup() {
  pinMode(hallSensor1, INPUT);
  pinMode(hallSensor2, INPUT);
  pinMode(hallSensor3, INPUT);
  pinMode(motor1Pin1, OUTPUT);
  pinMode(motor1Pin2, OUTPUT);
  pinMode(motor2Pin1, OUTPUT);
  pinMode(motor2Pin2, OUTPUT);
  pinMode(led1Pin, OUTPUT);
  pinMode(led2Pin, OUTPUT);
  pinMode(led3Pin, OUTPUT);
}

void loop() {
  int sensor1Value = digitalRead(hallSensor1);
  int sensor2Value = digitalRead(hallSensor2);
  int sensor3Value = digitalRead(hallSensor3);

  digitalWrite(led1Pin, sensor1Value == HIGH ? HIGH : LOW);
  digitalWrite(led2Pin, sensor2Value == HIGH ? HIGH : LOW);
  digitalWrite(led3Pin, sensor3Value == HIGH ? HIGH : LOW);

  if (sensor1Value == HIGH) {
    digitalWrite(motor1Pin1, HIGH);
    digitalWrite(motor1Pin2, LOW);
  } else {
    digitalWrite(motor1Pin1, LOW);
    digitalWrite(motor1Pin2, LOW);
  }

  if (sensor2Value == HIGH) {
    digitalWrite(motor2Pin1, HIGH);
    digitalWrite(motor2Pin2, LOW);
  } else {
    digitalWrite(motor2Pin1, LOW);
    digitalWrite(motor2Pin2, LOW);
  }

  if (sensor3Value == HIGH) {
    digitalWrite(motor1Pin1, LOW);
    digitalWrite(motor1Pin2, HIGH);
  }
}

This code configures the Arduino UNO pins for input from the Hall sensors and output to the motor driver and LEDs. It reads the state of each Hall sensor and turns on the corresponding LED. Depending on the sensor readings, it controls the direction of the motors. If a Hall sensor detects a magnetic field (reads HIGH), the corresponding motor is set to rotate in one direction; otherwise, it stops. If the third sensor reads HIGH, the first motor's direction is reversed.