Projects / Uno DPDT relay motor reverser

Uno DPDT relay motor reverser

Intermediate2.5 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. UNOON

    Find the relay pins

    Use the datasheet: two coil pins, and for each set a common, normally open and normally closed pin.

  2. UNONPN

    Wire the coil driver

    Pin 8 through 1 kilo-ohm to the 2N2222 base, the coil between 5V and the collector, diode across the coil.

  3. UNOTIP120

    Wire the motor supply

    Battery plus to NC1 and NO2, TIP120 collector to NO1 and NC2, motor to the commons.

  4. UNOTIP120

    Add the speed control

    Pin 9 through 1 kilo-ohm to the TIP120 base, emitters to common ground.

  5. UNO

    Add the diode and capacitor

    1N4007 on the collector and plus, 100 nanofarads across the motor.

  6. UNO

    Upload the sketch

    Open the Serial Monitor at 9600.

  7. UNO

    Press the button

    Forward, stop, reverse, stop.

In short

How do you build an uno DPDT relay motor reverser?

An Arduino Uno switches a DPDT relay to reverse the polarity of a small toy DC motor on a battery pack, with a button for direction and a stop between changes. You need Arduino Uno R3, Relay 5 V DPDT (HK19F), DC motor 130 size (toy motor), NPN Transistor 2N2222, TIP120 Darlington transistor, Resistor 1 kΩ × 2, Signal Diode 1N4148, Rectifier Diode 1N4007, Ceramic Capacitor 100 nF, Tactile push button 6 mm and Breadboard 830 Tie Points. It takes 7 steps and about 150 minutes.

Level
Intermediate
Time
About 150 min
Parts
11

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
Uno pin 81 kilo-ohm resistor to 2N2222 baseRelay on and off
2N2222 emitterUno GNDCommon ground
2N2222 collectorRelay coil pin (one side)Switches the coil to ground
Relay coil other pinUno 5VCoil supply
1N4148 diodeAcross the relay coil, stripe (cathode) on the 5V sideFlyback diode for the coil
Uno pin 91 kilo-ohm resistor to TIP120 basePWM speed control
TIP120 emitterBattery pack minus and Uno GNDCommon ground
TIP120 collectorRelay contacts NO1 and NC2, togetherSwitched low side of the motor supply
Battery pack plusRelay contacts NC1 and NO2, togetherMotor supply plus
Relay COM1 and COM2Motor wires A and BMotor is reversed by the relay
1N4007 diodeTIP120 collector to battery plus, stripe (cathode) on the plus sideClamps spikes from the motor
100 nF capacitorAcross the two motor wiresReduces electrical noise
Direction buttonUno pin 2 and GNDSteps through stop, forward, stop, reverse

Code

A DPDT relay has two sets of changeover contacts moved by one coil. Wired as in the table, with the motor on the two common contacts, plus and minus swap places on the motor when the relay moves, and a brushed DC motor turns the other way when its polarity is reversed. The coil takes more current than a pin can give, so a 2N2222 transistor switches it, and a diode across the coil absorbs the spike when the coil turns off. A diode must not be put across the motor itself in this circuit, because the motor sees both polarities and the diode would short it in one direction. Instead a TIP120 on the low side of the motor supply controls the speed with PWM, and a 1N4007 diode from its collector to the battery plus clamps spikes. The program never moves the relay while the motor is running: it brings the power to zero, waits, moves the relay and ramps back up, so the contacts do not arc and wear out. Use a small battery pack of two AA cells for a 3 volt toy motor, not a bigger battery. Check the contact rating on the relay and that it is above the motor's stall current, and do not hold the shaft.

Runs on a virtual Arduino Uno in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

const uint8_t RELAY = 8;       // relay coil driver (high = relay on)
const uint8_t DRIVE = 9;       // PWM to the TIP120
const uint8_t BUTTON = 2;      // to ground when pressed

// States step in a circle: stop, forward, stop, reverse
int state = 0;
int duty = 0;
bool lastButton = HIGH;
unsigned long lastChange = 0;

void rampTo(int target) {
  while (duty != target) {
    duty += (duty < target) ? 5 : -5;
    if (abs(duty - target) < 5) duty = target;
    analogWrite(DRIVE, duty);
    delay(15);
  }
}

void setup() {
  pinMode(RELAY, OUTPUT);
  pinMode(DRIVE, OUTPUT);
  pinMode(BUTTON, INPUT_PULLUP);
  digitalWrite(RELAY, LOW);
  analogWrite(DRIVE, 0);
  Serial.begin(9600);
  Serial.println("Press the button: forward, stop, reverse, stop");
}

void loop() {
  bool b = digitalRead(BUTTON);
  if (b == LOW && lastButton == HIGH && millis() - lastChange > 200) {
    lastChange = millis();
    state = (state + 1) % 4;
    if (state == 1 || state == 3) {
      // the relay only switches while the motor current is off, which protects its contacts
      analogWrite(DRIVE, 0);
      delay(300);
      digitalWrite(RELAY, state == 3 ? HIGH : LOW);
      delay(100);
      rampTo(200);                                  // about 80 percent power
      Serial.println(state == 1 ? "Forward" : "Reverse");
    } else {
      rampTo(0);
      Serial.println("Stop");
    }
  }
  lastButton = b;
}

What the serial monitor should show

Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual Arduino Uno with its sensors at their default values. Your numbers will follow your real readings, but the format should match.

Press the button: forward, stop, reverse, stop

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
First pressMotor runs one way
Second pressMotor ramps down and stops
Third pressMotor runs the other way
Fourth pressStops again
Listen to the relayIt clicks only when the motor is stopped

If it does not work

Always runs one way

Check the commons go to the motor and that NC and NO are wired as in the table.

Relay does not click

Check the transistor pins and the coil diode direction.

Motor does not start

Check the battery, the TIP120 pins and the common ground.

Uno resets

Run the motor from the battery, not the Uno, and keep the grounds joined.

Motor is noisy

Fit the 100 nanofarad capacitor across its terminals.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the uno DPDT relay motor reverser?

Arduino Uno R3, Relay 5 V DPDT (HK19F), DC motor 130 size (toy motor), NPN Transistor 2N2222, TIP120 Darlington transistor, Resistor 1 kΩ × 2, Signal Diode 1N4148, Rectifier Diode 1N4007, Ceramic Capacitor 100 nF, Tactile push button 6 mm and Breadboard 830 Tie Points.

How long does the uno DPDT relay motor reverser take to build?

About 150 minutes for a intermediate maker, in 7 steps.

How do I know the uno DPDT relay motor reverser works?

First press: Motor runs one way. Second press: Motor ramps down and stops. Third press: Motor runs the other way.

Always runs one way: what should I check?

Check the commons go to the motor and that NC and NO are wired as in the table.

Relay does not click: what should I check?

Check the transistor pins and the coil diode direction.

Motor does not start: what should I check?

Check the battery, the TIP120 pins and the common ground.

Uno resets: what should I check?

Run the motor from the battery, not the Uno, and keep the grounds joined.