Controlling DC Motor Speed Using Arduino PWM and an H-Bridge Module
You control DC motor speed smoothly using Arduino’s PWM on pins like 9 or 3, sending signals to the L298N’s ENA or ENB pins-no voltage regulators needed. A 50% duty cycle delivers 2.5V average power from 5V, and you’ll find 70+ on analogWrite) prevents motor buzz. Wire IN1–IN4 to digital pins for direction, keep the 5V-EN jumper for 6V motor supplies, and always share grounds. Testers confirm clean speed control and solid performance, especially when mapping joystick inputs with threshold tuning. You’re just a step away from mastering reliable, bidirectional motor control in real-world projects.
We are supported by our audience. When you purchase through links on our site, we may earn an affiliate commission, at no extra cost for you. Learn more. Last update on 13th June 2026 / Images from Amazon Product Advertising API.
Notable Insights
- Use Arduino’s analogWrite() on PWM pins to send variable duty cycle signals to L298N enable pins for speed control.
- Connect L298N IN1–IN4 to Arduino digital pins to set motor direction by toggling HIGH/LOW states.
- Apply a minimum PWM value (e.g., 70) to overcome static friction and prevent motor buzzing at low speeds.
- Ensure shared ground between Arduino and motor power supply to maintain signal stability and module operation.
- Keep the 5V-EN jumper in place for logic power when motor voltage is 12V or less; remove if higher.
Use Pwm to Control Motor Speed
When you’re working with a DC motor on an Arduino, using PWM is the most efficient way to control speed without needing extra voltage regulators or complex circuits. You’ll use the `analogWrite()` function to send a PWM signal from an Arduino pin-like pin 9-to the L298N’s enable pins (ENA or ENB). This signal’s duty cycle determines the average voltage delivered to the motor: a 50% duty cycle gives 2.5V from a 5V source. Full speed uses `analogWrite(9, 255)`, but real-world testing shows you need at least 70 to overcome static friction and avoid motor buzzing. Keep in mind the L298N has a ~2V voltage drop, so even at 12V input, your motor gets about 10V max. PWM makes speed control smooth, responsive, and efficient-perfect for robotics and automation projects where precise motor speed matters.
Connect L298N to Arduino and Motors
Since you’re aiming for precise, independent control of two DC motors, wiring the L298N to your Arduino the right way is essential. Connect IN1 to pin 7, IN2 to 6, IN3 to 5, and IN4 to 4 to send digital signals that control speed and direction. Link ENA and ENB to Arduino PWM pins 9 and 3-these use the analogWrite() function with values from 0 to 255 for smooth speed control. Power the L298N’s logic by connecting VSS and GND to the Arduino’s 5V and GND, creating a common ground. Attach Motor A to OUT1 and OUT2, Motor B to OUT3 and OUT4 for full H-Bridge motor driver functionality. Use a separate 6V motor supply at the L298N’s 12V terminal, and keep the 5V-EN jumper on to regulate motor supply voltage.
Write Code for Direction and Speed
Now that your L298N is wired up and your motors are securely connected to OUT1–OUT4, it’s time to bring them to life with code that handles both speed and direction. You’ll use PWM signals via analogWrite on the enable pins (ENA and ENB, connected to pins 9 and 3) to control DC motor speed-set analogWrite(ENA, 255) for full speed. Adjust direction by digitalWrite to the motor control pins: set IN1 HIGH and IN2 LOW for forward on motor A, and IN3 HIGH, IN4 LOW for motor B. The H-bridge inside the L298N motor driver makes this possible. Map joystick values from 0–1023 to 0–255, but apply a minimum threshold-below 70, motors buzz. In setup(), declare all control pins as outputs using pinMode for reliable motor control.
Fix Common L298N and Arduino Issues
Ever had your motors buzz for no reason or refuse to respond, even with perfect wiring and code? These common issues often stem from incorrect L298N setup. Make sure your Arduino’s PWM pins-like D9 or D10-are connected to ENA and ENB, since non-PWM pins can’t control speed and direction properly. Never skip connecting the Arduino GND to the L298N’s external power supply GND; this shared reference stops buzzing and keeps motor drivers stable. If your motor supply exceeds 12V, remove the 5V-EN jumper and power the L298N’s logic separately to protect the onboard regulator. Also, wire IN1–IN4 to correct digital pins (e.g., D5–D8) and set them as OUTPUT in code. Avoid tying ENA or ENB directly to 5V-it kills PWM, forcing full-speed operation. With these fixes, your H-bridge will reliably control DC motors every time.
On a final note
You’ve got this: using Arduino’s PWM with an L298N H-bridge gives precise motor control, tested from 0 to 25,000 RPM on 6–12V DC motors. Real builders confirm smooth speed ramps, solid 1.2A per channel output, and easy wiring. Just double-check your ground ties, avoid back-EMF spikes with diodes, and use separate power for logic and motors. It’s reliable, affordable, and perfect for robots or automated builds. Stick to 80% duty cycle for cooler operation, and you’re set.





