DC motor direction and speed lab
Build it step by step
0 of 7 doneWire the driver
Connect ENA, IN1, IN2 and the motor as in the table; take the ENA jumper off.
Power it
Connect the AA pack and share the ground with the Uno.
Run forward
Turn the pot to speed it up.
Reverse
Press the button twice: brake, then reverse.
Look at speed
Watch the speed value on the serial monitor.
Compare brake and coast
Set ENA to 0 to coast and note how long it spins.
Check the heat
Feel the driver heatsink after a minute.
How do you build a DC motor direction and speed lab?
Drive a DC motor forward, backward and at different speeds with an L298N. You need Arduino Uno R3, L298N Dual H-Bridge Module, TT gear motor 3 to 6 V, Potentiometer 10 kΩ, Tactile push button 6 mm, Battery holder 4 × AA with switch, AA alkaline battery × 4, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 7 steps and about 30 minutes.
- Level
- Beginner
- Time
- About 30 min
- Parts
- 9
Wiring
| From | To | Why |
|---|---|---|
| L298N ENA | Uno D9 (PWM) | Speed, remove the jumper on ENA |
| L298N IN1 | Uno D7 | Direction |
| L298N IN2 | Uno D8 | Direction |
| L298N OUT1 and OUT2 | Motor wires | Motor |
| 4 AA holder + | L298N 12 V terminal | Motor supply, about 6 V |
| 4 AA holder - | L298N GND and Uno GND | Common ground |
| Potentiometer wiper | Uno A0 | Speed control, ends on 5V and GND |
| Button | Uno D2 and GND | Brake and coast toggle |
Code
The L298N has two H-bridges. With IN1 high and IN2 low the motor turns one way, the opposite way with them swapped, and ENA sets the average voltage using PWM. The module drops about 2 V, so a 6 V pack gives the motor about 4 V, which is plenty for a TT gear motor. Keep the 5 V jumper on the driver as it is and do not connect the driver's 5 V terminal to the Uno; power the Uno from USB. The ground of the motor supply and the Uno must be joined. The driver heatsink can get warm at higher currents, so keep the load small and do not stall the motor for long. Arduino IDE, board "Arduino Uno" (or "Arduino Nano" with processor ATmega328P).
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).
// L298N: ENA sets speed with PWM, IN1 and IN2 set direction.
const byte ENA = 9, IN1 = 7, IN2 = 8, POT = A0, BTN = 2;
bool forward = true;
bool lastBtn = HIGH;
bool brake = false;
void setup() {
pinMode(ENA, OUTPUT); pinMode(IN1, OUTPUT); pinMode(IN2, OUTPUT);
pinMode(BTN, INPUT_PULLUP);
Serial.begin(9600);
}
void loop() {
// Button: first press brakes, next press runs the other way
bool b = digitalRead(BTN);
if (b == LOW && lastBtn == HIGH) {
delay(30);
if (!brake) { brake = true; }
else { brake = false; forward = !forward; }
}
lastBtn = b;
int speed = analogRead(POT) / 4; // 0 to 255
if (brake) {
digitalWrite(IN1, HIGH); digitalWrite(IN2, HIGH); // both inputs high with enable on brakes the motor
analogWrite(ENA, 255);
} else {
digitalWrite(IN1, forward ? HIGH : LOW);
digitalWrite(IN2, forward ? LOW : HIGH);
analogWrite(ENA, speed);
}
Serial.println(speed);
delay(20);
}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.
128 127 128 127 128 127
Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Pot at zero | Motor stopped |
| Pot raised | Faster |
| Button pressed once | Motor brakes |
| Button pressed again | Runs the other way |
If it does not work
Motor does not move
Check the ENA jumper is removed and PWM is on D9, and the common ground.
Only one direction
Check IN1 and IN2 wiring.
Motor weak
Fresh batteries and the 2 V drop; check the supply.
Uno resets
Power it from USB, not the motor pack.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the DC motor direction and speed lab?
Arduino Uno R3, L298N Dual H-Bridge Module, TT gear motor 3 to 6 V, Potentiometer 10 kΩ, Tactile push button 6 mm, Battery holder 4 × AA with switch, AA alkaline battery × 4, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).
How long does the DC motor direction and speed lab take to build?
About 30 minutes for a beginner maker, in 7 steps.
How do I know the DC motor direction and speed lab works?
Pot at zero: Motor stopped. Pot raised: Faster. Button pressed once: Motor brakes.
Motor does not move: what should I check?
Check the ENA jumper is removed and PWM is on D9, and the common ground.
Only one direction: what should I check?
Check IN1 and IN2 wiring.
Motor weak: what should I check?
Fresh batteries and the 2 V drop; check the supply.
Uno resets: what should I check?
Power it from USB, not the motor pack.
