• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

analogWrite esp8266 L298N

Q&A Forum › Category: ESP8266 › analogWrite esp8266 L298N
0 Vote Up Vote Down
DK asked 6 years ago

Hi

I just got a Wifi Arduino car and put in NodeMCU esp8266 …

Controlling it both web page and C# speech   say forward it moves forward, but I can not get analogWrite() function to adjust the speed by PWM …

I have read may tutorials. each, when applied failed. Any ideas or different H-Brigde?

Regards
derek

5 Answers
1 Vote Up Vote Down
Best Answer
Sara Santos Staff answered 6 years ago

Hi.

As I’ve told you the duty cycle range for the PWM of the ESP8266 is 0 to 1023.

However, when controlling the motor, low duty cycles values may result in a weird buzz sound, and the motor won’t move.

You need to experiment and see what is the lowest value that makes the motor move.
If you experiment higher duty cycles, the motor will probably move.

For example, try:

analogWrite(enA, 990);

Then, let me know the results.
Regards,
Sara

0 Vote Up Vote Down
Sara Santos Staff answered 6 years ago

Hi.

I’ve experimented with the L298N driver with an ESP32, and it worked fine to adjust the speed. So, I don’t think the problem is related with the H-bridge.

We have a tutorial about the L298N driver with the ESP32 that may be useful to better understand how the L298N driver works: https://randomnerdtutorials.com/esp32-dc-motor-l298n-motor-driver-control-speed-direction/

Which pins are you using for PWM? Have you tried generating a PWM signal on a separated sketch and see if it is working with that pin?

Also, please note that the PWM analog range of the ESP8266 is 0 to 1023. (while with an Arduino is 0 to 255).

If you provide more details, maybe I can help you better.

Regards,
Sara

0 Vote Up Vote Down
DK answered 6 years ago

Hi
Thank you for responding …
It work with the Arduino, so I put in a ESP8266 for its Wifi
How to Make Arduino ESP8266 WiFi Robot Car
https://youtu.be/2AL7HfiRlp4?t=313
but he does not use analogWrite just set enA to HIGH (255)

Learn about the L289N
Controlling DC Motors with the L298N H Bridge and Arduino
https://youtu.be/dyjo_ggEtVU?t=4

pins for NodeMCU esp8266
https://circuits4you.com/2018/02/20/esp8266-arduino-digital-io/
https://www.youtube.com/watch?v=c0tMGlJVmkw

//Code …
///////////////////////////////////////////////////////////////
//Global variables

// Set speed range 0~255
n = 150; // this comes from webpage or C# WebClient/Speech 5.4

// Motor A
int enA = D2;
int in1   = D3;
int in2   = D4;
 
// Motor B

int enB  = D5;
int in3    = D6;
int in4    = D7;

//example
void forward()
{
// server.send(200, “text/plane”, “forward … “); //Send client ajax request
//Motor A
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
analogWrite(enA, n); // n is set to 150

//Motor B
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
analogWrite(enB, n);
}
It moves forward, back etc … when  put in
digitalWrite(enA, HIGH);
digitalWrite(enB, HIGH);
 
but no speed control for
analogWirites(enA, 150);
analogWirites(enB, 150);
just a hum from the L289N
 
Maybe its the Pins
 
Regards
derek

0 Vote Up Vote Down
DK answered 6 years ago

Hi Sara
Thank you Thank You Thank You
I Live and Learn … its works
Keep Smiling
derek

0 Vote Up Vote Down
Sara Santos Staff answered 6 years ago

That’s great! 
You’re welcome!
If you need anything else, you just need to open a new question in our forum.
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.