Driving Relay H-bridge with Arduino

Controlling the direction of a DC motor is a fundamental concept in robotics and automation. One of the simplest ways to achieve this is by using an H-Bridge circuit. While transistor-based H-bridges are common, using relays offers a straightforward and cost-effective alternative. In this guide, we’ll show how to build a relay-based H-Bridge and control it with an Arduino.

Understanding the Relay-Based H-Bridge

An H-Bridge allows a DC motor to rotate in both forward and reverse directions by altering the polarity of the voltage applied to it. In this project, we use two 5V relays, an Arduino, and a 9V battery to control motor movement.

Circuit Components

  • Arduino (any model)

  • Two 5V relays

  • 9V battery (for motor power)

  • DC motor

  • Connecting wires

Circuit Connections

The following is the relay based H-bridge circuit diagram, where the H-bridge is controlled with Arduino.

relay based H-bridge circuit diagram

The relay H-bridge circuit works as follows:

  • The two relays act as switches that control the motor’s polarity.
  • The coil terminals of both relays are connected to Arduino pin 9 (control signal) and ground.
  • The Normally Closed (NC) and Normally Open (NO) contacts of both relays are connected to the motor, power supply, and ground in a way that keeps the motor disconnected by default.
  • When the Arduino activates the relay coils, both relays switch ON, allowing current to flow through the motor from the 9V battery.

For more details read our guide on SPDT switch-based H-Bridge .

Arduino Code for Controlling the H-Bridge

Here is a simple Arduino sketch/program code to control the relay-based H-Bridge:

/* 
 * How to drinve Relay H-bridge with Arduino
 * Created By: ee-diary.com
 * Date: Wed Mar 19 2025
 * Processor: Arduino Uno
 * Compiler:  Arduino AVR
 */

const int relayPin = 9; // Relay control pin

void setup() {
    pinMode(relayPin, OUTPUT);
    Serial.begin(9600);
}

void loop() {
    digitalWrite(relayPin, LOW); // Turn off relays, motor stops
    Serial.println("Motor Stopped");
    delay(1000);

    digitalWrite(relayPin, HIGH); // Turn on relays, motor runs
    Serial.println("Motor Running");
    delay(1000); // Run for 1 seconds
   
}

Video demonstration of  Relay H-bridge

The following video shows how the the relay based h-bridge circuit works which is driven by Arduino to turn on and off a DC motor.

How the Relay H-bridge Arduino Code Works

  • Relay Pin Control: The Arduino controls both relays through pin 9.

  • Motor Operation: The motor turns ON when relays are activated (HIGH) and turns OFF when relays are deactivated (LOW).

  • Timing Delays: The motor runs for 3 seconds, then stops for 3 seconds, repeating indefinitely.

Enhancing Motor Control

For more advanced motor control, consider using BJT-based H-bridges, as explained in this BJT-based H-Bridge guide.

If you want precise speed and direction control with a joystick, check out our precise speed and direction control tutorial.

To explore understanding of relay control with Arduino se our guide how relays work with Arduino.

Conclusion

Using a relay-based H-Bridge is a simple yet effective way to control a DC motor with an Arduino. While transistor-based H-bridges offer more flexibility, relays are ideal for low-power applications. By following this guide, you can build your own motor control circuit for DIY robotics and automation projects!

Would you like help with customizing this relay H-bridge Motor project further? Let us know in the comments!

Post a Comment

Previous Post Next Post