Arduino Nano H‑Bridge Module
The H‑Bridge Module project demonstrates how to control the direction and speed of a DC motor using an H‑Bridge motor driver with an Arduino Nano. This project is essential for building robotics projects, motorized vehicles, and various mechanical automation systems.
Components Needed
- Arduino Nano
- H‑Bridge Motor Driver Module (e.g. L298N or L293D)
- DC Motor
- Power Source (battery or external 5–12 V supply)
- Jumper Wires
Circuit Setup
1. Connect H‑Bridge Module to Arduino Nano:
Connect the PWM speed control pin (enA) of the H‑Bridge module to pin 9 of the Arduino Nano.
Connect the direction control pins (in1 and in2) of the H‑Bridge module to pins 8 and 7 of the Arduino Nano, respectively.
Connect the power and ground pins of the H‑Bridge module to an appropriate external power source and common ground with the Arduino Nano.
Programmed Motor Control
Using PWM and digital pins, the Arduino can smoothly change motor speed and reverse direction for forward, backward, and stop states.
#define enA 9
#define in1 8
#define in2 7
void setup() {
// Set pin modes
pinMode(enA, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
// Stop motor at start
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
analogWrite(enA, 0);
}
void loop() {
// 1. Run forward, medium speed
forward(150);
delay(3000);
// 2. Stop
stopMotor();
delay(1000);
// 3. Run backward, low speed
backward(80);
delay(3000);
// 4. Stop
stopMotor();
delay(1000);
}
void forward(int speed) {
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
analogWrite(enA, speed); // 0–255 PWM
}
void backward(int speed) {
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
analogWrite(enA, speed);
}
void stopMotor() {
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
analogWrite(enA, 0);
}
Instructions
1. Circuit Setup:
Wire the H‑Bridge module to the Arduino Nano according to the circuit setup, including proper power and ground connections.
2. Code Upload:
Connect the Arduino Nano to your computer using a USB cable.
Open the Arduino IDE and paste the provided H‑Bridge motor‑control code.
Select the appropriate board (Arduino Nano) and port from the Tools menu.
Upload the code to the Arduino Nano.
3. Testing:
Once the code is uploaded, observe the DC motor run forward, stop, run backward, and stop again in a repeating pattern.
Applications
Robotics Projects: Control motors in robotic arms, wheels, and other robotic systems.
Motorized Vehicles: Drive motors in RC cars, drones, and other remote‑controlled vehicles.
Mechanical Automation: Automate mechanical systems such as conveyor belts, gates, and doors.
Understanding the H‑Bridge Logic
- in1 = HIGH, in2 = LOW → Motor forward.
- in1 = LOW, in2 = HIGH → Motor backward.
- in1 = LOW, in2 = LOW → Motor stopped (brake/coast).
The PWM value on the enA pin (0–255) controls motor speed; higher values give faster rotation, lower values give slower rotation, and 0 stops the motor.
Troubleshooting Common Issues
- Motor not spinning? Check if power is connected to the H‑Bridge and if the EN/enable pin is driven by PWM.
- Motor runs only one direction? Verify in1 and in2 wiring and code logic.
- Motor jerks or buzzes at low speed? Increase the minimum PWM threshold (e.g., 60–80 instead of very low values).
- H‑Bridge module overheating? Use an appropriate voltage and avoid short‑circuiting motor outputs.
Best Practices and Notes
- Always connect a common ground between the Arduino Nano and the H‑Bridge power supply.
- Use a separate power supply for the motor (not Arduino’s 5V) when driving larger DC motors.
- Add a 100 µF capacitor across the motor terminals to reduce noise and voltage spikes.
- Do not exceed the current and voltage ratings of the H‑Bridge module or motor.
- Adjust speed values and timings in the code to match your motor and mechanical load.
Variants and Extensions
You can extend this project by adding a potentiometer to control speed from 0–255, or buttons/switches to change direction manually. For robots, you can duplicate this setup for a second motor (enB, in3, in4) to create a differential‑drive robot car.