Comments on: ESP32 with DC Motor and L298N Motor Driver – Control Speed and Direction https://randomnerdtutorials.com/esp32-dc-motor-l298n-motor-driver-control-speed-direction/ Learn ESP8266, ESP32, Arduino, and Raspberry Pi Wed, 23 Apr 2025 20:54:06 +0000 hourly 1 https://wordpress.org/?v=6.8.2 By: Brian Mufambirwi https://randomnerdtutorials.com/esp32-dc-motor-l298n-motor-driver-control-speed-direction/#comment-1030155 Wed, 23 Apr 2025 20:54:06 +0000 http://randomnerdtutorials.com/?p=61995#comment-1030155 In reply to Tracy.

Thank you very much. Had to modify it for a single motor, single direction working with an opto coupler and N-Channel MOSFET IRZL 44N. Need help in modifying main loop to include running the motor at maximum speed for 30 Minutes after reaching maximum speed

]]>
By: Electromax https://randomnerdtutorials.com/esp32-dc-motor-l298n-motor-driver-control-speed-direction/#comment-893933 Fri, 23 Feb 2024 16:40:36 +0000 http://randomnerdtutorials.com/?p=61995#comment-893933 The L298N has a Three-State Output. When enabled, the output has low impedance; when not enabled, it has high impedance. Consequently, if both outputs are the same and the L298N is enabled, you achieve a fast stop. On the other hand, if the L298N is not enabled and the outputs have high impedance, you experience a free-running stop.

]]>
By: Sai Sagar https://randomnerdtutorials.com/esp32-dc-motor-l298n-motor-driver-control-speed-direction/#comment-884425 Tue, 16 Jan 2024 19:01:28 +0000 http://randomnerdtutorials.com/?p=61995#comment-884425 In reply to Vliertemans.

can’t I just use analogWrite(), instead of going through setting up PWM signal

]]>
By: Vliertemans https://randomnerdtutorials.com/esp32-dc-motor-l298n-motor-driver-control-speed-direction/#comment-882332 Sat, 06 Jan 2024 09:19:30 +0000 http://randomnerdtutorials.com/?p=61995#comment-882332 Thanks for the great tutorial.
Just wanted to mention there is a small bug in you program.

In the code below the LOW should be connected to motor1Pin1 and the HIGH to motor1Pin2.
// Move DC motor forward with increasing speed
digitalWrite(motor1Pin1, HIGH);
digitalWrite(motor1Pin2, LOW);

]]>
By: stanley.rhm@gmail.com https://randomnerdtutorials.com/esp32-dc-motor-l298n-motor-driver-control-speed-direction/#comment-871664 Sun, 12 Nov 2023 18:44:29 +0000 http://randomnerdtutorials.com/?p=61995#comment-871664 it worked for me, im soo happy….now i need to know how to make a car controled by movil or joistick

]]>
By: Panagiotis https://randomnerdtutorials.com/esp32-dc-motor-l298n-motor-driver-control-speed-direction/#comment-857167 Fri, 25 Aug 2023 14:03:43 +0000 http://randomnerdtutorials.com/?p=61995#comment-857167 In reply to Panagiotis.

update 2: I just found the solution!!! It was as simple as getting rid of all the LEDC commands and replacing ledcWrite(channel, value) with analogWrite(pin, value).

By taking a look at the LEDC documentation by Espressif https://espressif-docs.readthedocs-hosted.com/projects/arduino-esp32/en/latest/api/ledc.html#:~:text=ledcWrite,duty%20for%20the%20LEDC%20channel.&text=chan%20select%20the%20LEDC%20channel,be%20set%20for%20selected%20channel.
I found that there is an “analogWrite” command for esp32 that is fully compatible with the analogWrite command for arduino UNO/NANO etc. Using this command instead worked straight away. There is a few more handy PWM-related commands on that page too.

]]>
By: Panagiotis https://randomnerdtutorials.com/esp32-dc-motor-l298n-motor-driver-control-speed-direction/#comment-857139 Fri, 25 Aug 2023 11:53:42 +0000 http://randomnerdtutorials.com/?p=61995#comment-857139 update: the example itself works just fine, it’s when I try to incorporate it’s functionality to an ESPnow remote control code that problems arise. I’ve searched for hours but can’t find why this happens.

]]>
By: Panagiotis https://randomnerdtutorials.com/esp32-dc-motor-l298n-motor-driver-control-speed-direction/#comment-857103 Fri, 25 Aug 2023 09:08:13 +0000 http://randomnerdtutorials.com/?p=61995#comment-857103 Hello. I followed everything in the tutorial exactly but my motor barely even moves. When I put the jumper to the L298N to have 100% duty cycle, the motor spins as it should. But when I try to send PWM from the esp32, the motor barely turns at all. I’ve tried frequencies from as high as 30000Hz to as low as 1Hz. Although frequencies lower than 500Hz did help the motor spin slightly faster, I could never get it to spin at more than 10% speed with PWM. I’d appreciate some help.

]]>
By: Eduardo https://randomnerdtutorials.com/esp32-dc-motor-l298n-motor-driver-control-speed-direction/#comment-831782 Mon, 24 Apr 2023 19:11:58 +0000 http://randomnerdtutorials.com/?p=61995#comment-831782 In reply to Eduardo.

I keep on making mistakes… sorry about that
33.33 µs (micro seconds) 0.00003333 s

]]>
By: Eduardo https://randomnerdtutorials.com/esp32-dc-motor-l298n-motor-driver-control-speed-direction/#comment-831709 Mon, 24 Apr 2023 14:21:21 +0000 http://randomnerdtutorials.com/?p=61995#comment-831709 In reply to Eduardo.

Correction: 33.33 ms, not ns

]]>