-3

I'm trying to make a WiFi controlled Car from my old toy car which will be running on ESP8266. I'm using the L298N motor driver and have one motor for left-right control & other for forward-backward direction control.

Now the problem is I'm unable to use more than 3 pins at once. If I even try, likely my code stops working.

Below is my code :

static const uint8_t enFront   = D0;
static const uint8_t front_in1 = D1;
static const uint8_t front_in2 = D2;
static const uint8_t enBack    = D5;
static const uint8_t back_in1  = D3;
static const uint8_t back_in2  = D4;

#include <ESP8266WebServer.h>

const char* ssid = "espCar <^_^>";
const char* password = "hacksAllowed";

  ESP8266WebServer server(80);

void setup() {
  pinMode(enFront,OUTPUT);
  pinMode(front_in1,OUTPUT);
  pinMode(front_in2,OUTPUT);
 /* pinMode(enBack,OUTPUT);   <--Problem here
  pinMode(back_in1,OUTPUT);   <--Problem here
  pinMode(back_in2,OUTPUT);*/ <--Problem here

   Serial.begin(115200);
  WiFi.softAP(ssid, password);
  WiFi.mode(WIFI_AP);
  delay(500);  
  server.on("/REQ",processRequest);
  server.begin();
  Serial.println("Server is UP!");  
}

void loop() {
 // server.handleClient(); 
  analogWrite(enFront,1023);
  digitalWrite(front_in1,HIGH);
  digitalWrite(front_in2,LOW);
  delay(2000);
  digitalWrite(front_in2,HIGH);
  digitalWrite(front_in1,LOW);
  delay(2000);
}

void processRequest() { 
 /* if (server.arg("move")!=""){
    if (server.arg("right")!=""){
      analogWrite(enFront,server.arg("right").toInt());
      digitalWrite(front_in1,HIGH);
      digitalWrite(front_in2,LOW);
      /*Debug*/
    /*  server.send(200, "200", server.arg("right"));
    }else if(server.arg("left")!=""){
      analogWrite(enFront,server.arg("left").toInt());
      digitalWrite(front_in1,LOW);
      digitalWrite(front_in2,HIGH);
      /*Debug*/
     /* server.send(200, "200", server.arg("left"));
    } 
  }*/
}

All code working fine until I declare pinMode(pin,OUTPUT) for any 4th pin. (Everything is ok for every pin till 3rd one is declared)

I'm not so old with ESP or Arduino. So, please help by giving some clarification on this.


Schematic:

schematic

simulate this circuit – Schematic created using CircuitLab

Sorry for the mistake of making both motors tagged 2, → one is M1 & other is M2

  • scheme? (why did you add tags for other boards? I removed them) – Juraj Jan 22 at 19:41
  • ok. on the scheme you have a NodeMcu with Dx labels, in the code you use io pin numbers. you can use Dx constants in code. – Juraj Jan 22 at 20:04
  • pins io 0 and io 2 must be HIGH at boot. it is possible that wiring them to the driver board pulls them down. – Juraj Jan 22 at 20:06
  • Ok. Actually I used System.println to print out D1 to D5 then used them – Toaster Jan 22 at 20:06
  • 1
    Why can't you draw a schematic that is what you actually have? You might as well show nothing as to show something that isn't true. – Delta_G Jan 22 at 20:47
0

I found out the problem & it has nothing to deal with ESP8266. It was something like voltage conflict (I don't know the deeper science, I agree).

Actually, I was testing by plugging in the USB to ESP & at the same time I had a 11V lipo connected to L298N.

I tested by using one single voltage source & everything worked fine.

It looked something like this (It → the wrong one here):

schematic

simulate this circuit – Schematic created using CircuitLab

  • It is acceptable to connect two DC voltage sources like this, except that you should connect the GND connections together. – jose can u c Jan 23 at 13:42
  • I did the same but didn't make the GND together & likely that was the problem – Toaster Jan 23 at 13:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.