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

Arduino UNO Controlled Dual Motor Driver with Joystick and Potentiometer Feedback

View and Edit Project In Cirkit DesignerImage of Arduino UNO Controlled Dual Motor Driver with Joystick and Potentiometer Feedback

Circuit Documentation

Summary

This circuit is designed to control multiple DC motors using an Arduino UNO microcontroller in conjunction with an L298N DC motor driver. The speed and direction of the motors are determined by the input from an analog joystick and multiple potentiometers. A 12V battery provides power to the system, with voltage regulation for the Arduino and other components that require 5V.

Component List

Arduino UNO

MRB Planetary Gearbox Motor (x2)

Analog Joystick (Wokwi Compatible)

Potentiometer (x4)

L298N DC Motor Driver

12V Battery

Wiring Details

Arduino UNO

MRB Planetary Gearbox Motors

Analog Joystick (Wokwi Compatible)

Potentiometers

L298N DC Motor Driver

12V Battery

Documented Code

// Motor pins
const int motor1Pin1 = 2;
const int motor1Pin2 = 3;
const int motor1PWM = 5;

const int motor2Pin1 = 4;
const int motor2Pin2 = 6;
const int motor2PWM = 9;

// Potentiometer pins for speed control
const int potSpeed1 = A2;
const int potSpeed2 = A3;

// Joystick pins
const int joyX = A0;
const int joyY = A1;

void setup() {
  // Motor pins as outputs
  pinMode(motor1Pin1, OUTPUT);
  pinMode(motor1Pin2, OUTPUT);
  pinMode(motor1PWM, OUTPUT);

  pinMode(motor2Pin1, OUTPUT);
  pinMode(motor2Pin2, OUTPUT);
  pinMode(motor2PWM, OUTPUT);

  // Initialize serial communication
  Serial.begin(9600);
}

void loop() {
  // Read joystick values
  int joyXVal = analogRead(joyX);
  int joyYVal = analogRead(joyY);

  // Read potentiometer values for speed control
  int speed1 = map(analogRead(potSpeed1), 0, 1023, 0, 255);
  int speed2 = map(analogRead(potSpeed2), 0, 1023, 0, 255);

  // Control motor 1 direction based on joystick X axis
  if (joyXVal > 512) {
    digitalWrite(motor1Pin1, HIGH);
    digitalWrite(motor1Pin2, LOW);
  } else if (joyXVal < 512) {
    digitalWrite(motor1Pin1, LOW);
    digitalWrite(motor1Pin2, HIGH);
  } else {
    digitalWrite(motor1Pin1, LOW);
    digitalWrite(motor1Pin2, LOW);
  }

  // Control motor 2 direction based on joystick Y axis
  if (joyYVal > 512) {
    digitalWrite(motor2Pin1, HIGH);
    digitalWrite(motor2Pin2, LOW);
  } else if (joyYVal < 512) {
    digitalWrite(motor2Pin1, LOW);
    digitalWrite(motor2Pin2, HIGH);
  } else {
    digitalWrite(motor2Pin1, LOW);
    digitalWrite(motor2Pin2, LOW);
  }

  // Apply PWM for speed control
  analogWrite(motor1PWM, speed1);
  analogWrite(motor2PWM, speed2);
}

Note: The provided code snippet is a partial representation of the full code. It includes setup and loop functions for motor control based on joystick input and potentiometer readings for speed control. The code is designed to be uploaded to the Arduino UNO microcontroller.