____       _          ____                        
|  _ \ ___ | |__   ___/ ___| _   _ _ __ ___   ___  
| |_) / _ \| '_ \ / _ \___ \| | | | '_ ` _ \ / _ \ 
|  _ < (_) | |_) | (_) |__) | |_| | | | | | | (_) |
|_| \_\___/|_.__/ \___/____/ \__,_|_| |_| |_|\___/ 
                                                   
  ____            _    _                 _    
 / ___|___   ___ | | _| |__   ___   ___ | | __
| |   / _ \ / _ \| |/ / '_ \ / _ \ / _ \| |/ /
| |__| (_) | (_) |   <| |_) | (_) | (_) |   < 
 \____\___/ \___/|_|\_\_.__/ \___/ \___/|_|\_\

Controlling a DC motor with an Arduino

One of the most important things your RoboSumo robot needs to be able to do is control its motors. This basic example shows how to control a single DC motor, but it can be easily extended to control two motors, which will allow your robot to drive forward and backwards, but also to steer left and right.

This circuit allows bi-directional control of one DC motor by the Arduino:

insert alt text here

Here's how my example breadboard looks. Please don't rely on the breadboard photos to build your own circuit. It's useful to see a photo at this stage, because you are still learning how to lay out a breadboard circuits, but for future examples a circuit diagram may be the only thing provided, so you need to learn how to translate the circuit diagram into a working breadboard circuit yourself.

insert alt text here

insert alt text here

The following code can be used to test the circuit:

//
// Basic motor control example for Arduino Nano
// Motor forward for 2 seconds, reverse for 2 seconds
// and stop for 4 seconds. Repeats indefinitely./
//
// Written by Ted Burke - 01-Jan-2023
//

void setup()
{
  pinMode(4, OUTPUT); // make pin D4 a digital output
  pinMode(5, OUTPUT); // make pin D5 a digital output
}

void loop()
{
  // Motor forward for 2 seconds
  digitalWrite(4, HIGH); // set voltage on pin D4 to 5V
  digitalWrite(5, LOW);  // set voltage on pin D5 to 0V
  delay(2000);

  // Motor reverse for 2 seconds
  digitalWrite(4, LOW);  // set voltage on pin D4 to 0V
  digitalWrite(5, HIGH); // set voltage on pin D5 to 5V
  delay(2000);

  // Motor stop for 4 seconds
  digitalWrite(4, LOW);  // set voltage on pin D4 to 0V
  digitalWrite(5, LOW);  // set voltage on pin D5 to 0V
  delay(4000);  
}

Notes on connecting the SN754410NE

Notes on wire colours / wire preparation