Engines start as soon as you receive the code

Good afternoon

I have a cart project that works with cell phone and via wifi network.
I have the problem that as soon as I send the code to the board, the wheel motors start and do not stop.
The card I'm using is WeMos D1 R1 Wifi ESP8266.

The compilation also does not point out errors.

Code:

/*-----------------------code start here -------------------------------------*/
int led = D3;        //led 
int outPin1 = D4;     //motor1 
int outPin2 = D5;    //motor1 
int outPin4 = D6;   //motor2 
int outPin3 = D7;   //motor2 
char bt = 0;       //BT  
/*------------------------------------------------------------------------------*/ 
#include <ESP8266WiFi.h>
#include <WiFiClient.h> 
#include <ESP8266WebServer.h>

String command;             //String to store app command state.
int speedCar = 800;         // 400 - 1023.
int speed_Coeff = 3;

const char* ssid = "Autobots";
const char* password = "247mg";
ESP8266WebServer server(80);
/*------------------------------------------------------------------------------*/ 
void setup() 
{ 
Serial.begin(9600); 
pinMode(outPin1,OUTPUT); 
pinMode(outPin2,OUTPUT); 
pinMode(outPin3,OUTPUT); 
pinMode(outPin4,OUTPUT); 
pinMode(led,OUTPUT); 
Serial.begin(115200);
// Connecting WiFi


  WiFi.mode(WIFI_AP);
  WiFi.softAP(ssid);

  IPAddress myIP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(myIP);
 
 // Starting WEB-server 
     server.on ( "/", HTTP_handleRoot );
     server.onNotFound ( HTTP_handleRoot );
     server.begin();    
} 
void loop() 
{ 
  server.handleClient();
  command = server.arg("State");
if (Serial.available() > 0) 
{ 
 bt = Serial.read(); 
 digitalWrite(led, 1); 
 /*________________________________________________________________________*/ 
 if(bt == 'F')        //move forwards 
 { 
   digitalWrite(outPin1,HIGH); 
   digitalWrite(outPin2,LOW); 
   digitalWrite(outPin3,HIGH); 
   digitalWrite(outPin4,LOW); 
 } 
 else if (bt == 'B')       //move backwards 
 { 
   digitalWrite(outPin1,LOW); 
   digitalWrite(outPin2,HIGH); 
   digitalWrite(outPin3,LOW); 
   digitalWrite(outPin4,HIGH); 
 } 
 else if (bt == 'S')     //stop!! 
 {    
   digitalWrite(outPin1,LOW); 
   digitalWrite(outPin2,LOW); 
   digitalWrite(outPin3,LOW); 
   digitalWrite(outPin4,LOW); 
 } 
 else if (bt == 'R')    //right 
 { 
   digitalWrite(outPin1,HIGH); 
   digitalWrite(outPin2,LOW); 
   digitalWrite(outPin3,LOW); 
   digitalWrite(outPin4,LOW); 
 } 
 else if (bt == 'L')     //left 
 { 
   digitalWrite(outPin1,LOW); 
   digitalWrite(outPin2,LOW); 
   digitalWrite(outPin3,HIGH); 
   digitalWrite(outPin4,LOW); 
 } 
 else if (bt == 'I')    //forward right 
 { 
   digitalWrite(outPin1,HIGH); 
   digitalWrite(outPin2,LOW); 
   digitalWrite(outPin3,LOW); 
   digitalWrite(outPin4,HIGH); 
 } 
 else if (bt == 'G')    //forward left 
 { 
   digitalWrite(outPin1,LOW); 
   digitalWrite(outPin2,HIGH); 
   digitalWrite(outPin3,HIGH); 
   digitalWrite(outPin4,LOW); 
 } 
 } 
} 

void HTTP_handleRoot(void) {

if( server.hasArg("State") ){
       Serial.println(server.arg("State"));
  }
  server.send ( 200, "text/html", "" );
  delay(1);
}
/*---------------- E N  D ------------------------------------------------------*/ 

Could your serial also contain a CR and possibly a LF chareacter?

The fact that you do not get any errors is a good thing but it does NOT tell your code will work, only that the compiler can put into code. If you upload it it will run and do what the code instructs it to do. This is good but if it is not what you want then back to the coding.

That should be easy to diagnose and fix by yourself. Work your way through the code and circuitry, answering the following questions in order.

  • Starting from the motor electronics: what signals are required to start the motor?

  • How and why does your program produce those signals upon startup?

  • Why does your program not produce signals to stop or otherwise control the motor as desired?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.