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

Arduino UNO Controlled Dual DC Motor Robot with IR Remote

View and Edit Project In Cirkit DesignerImage of Arduino UNO Controlled Dual DC Motor Robot with IR Remote

Circuit Documentation

Summary

This circuit is designed to control two DC motors using an Arduino UNO and an H-Bridge motor driver. The motors are powered by a 2x 18650 battery pack. The Arduino UNO is programmed to control the direction and speed of the motors based on the input from an IR receiver.

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. DC Motor (Motor A)

    • Description: A simple DC motor.
    • Pins: pin 1, pin 2
  3. DC Motor (Motor B)

    • Description: A simple DC motor.
    • Pins: pin 1, pin 2
  4. H-Bridge Motor Driver (Puente H carrito)

    • Description: A motor driver used to control the direction and speed of the motors.
    • Pins: OUT1, OUT2, OUT3, OUT4, 12V, GND, 5V, ENA, IN1, IN2, IN3, IN4, ENB, 5VEN
  5. 2x 18650 Battery Pack

    • Description: A battery pack consisting of two 18650 batteries.
    • Pins: vcc, gnd

Wiring Details

Arduino UNO

DC Motor (Motor A)

DC Motor (Motor B)

H-Bridge Motor Driver (Puente H carrito)

2x 18650 Battery Pack

Code Documentation

#include <IRremote.hpp>

const int IR_RECEIVE_PIN = 2;

// Motor A connections
int enA = 9;
int in1 = 8;
int in2 = 7;
// Motor B connections
int enB = 3;
int in3 = 6;
int in4 = 5;

void setup() {
  IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK); // Start the IR receiver
  // Set all the motor control pins to outputs
  pinMode(enA, OUTPUT);
  pinMode(enB, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(in3, OUTPUT);
  pinMode(in4, OUTPUT);
  
  // Turn off motors - Initial state
  digitalWrite(in1, LOW);
  digitalWrite(in2, LOW);
  digitalWrite(in3, LOW);
  digitalWrite(in4, LOW);
}

void loop() {
  directionControl();
  delay(1000);
  speedControl();
  delay(1000);
}

// This function lets you control spinning direction of motors
void directionControl() {
  // Set motors to maximum speed
  // For PWM maximum possible values are 0 to 100
  analogWrite(enA, 100);
  analogWrite(enB, 100);

  // Turn on motor A & B
  digitalWrite(in1, HIGH);
  digitalWrite(in2, LOW);
  digitalWrite(in3, HIGH);
  digitalWrite(in4, LOW);
  delay(2000);

  digitalWrite(in1, LOW);
  digitalWrite(in2, HIGH);
  digitalWrite(in3, LOW);
  digitalWrite(in4, HIGH);
  delay(2000);
  
  // Turn off motors
  digitalWrite(in1, LOW);
  digitalWrite(in2, LOW);
  digitalWrite(in3, LOW);
  digitalWrite(in4, LOW);
}

// This function lets you control speed of the motors
void speedControl() {
  // Accelerate from zero to maximum speed
  for (int i = 0; i < 101; i++) {
    analogWrite(enA, i);
    analogWrite(enB, i);
    delay(20);
  }

  // Decelerate from maximum speed to zero
  for (int i = 100; i >= 0; --i) {
    analogWrite(enA, i);
    analogWrite(enB, i);
    delay(20);
  }

  // Now turn off motors
  digitalWrite(in1, LOW);
  digitalWrite(in2, LOW);
  digitalWrite(in3, LOW);
  digitalWrite(in4, LOW);
}

This code initializes the IR receiver and sets up the motor control pins as outputs. The loop function calls two functions: directionControl and speedControl. The directionControl function controls the direction of the motors, while the speedControl function controls the speed of the motors.