I hooked my ESP8266 Wi-Fi module to an ESP-12E Motor Shield and connected it to an RC car. It works fine when connected to my laptop (Goes forward, backward, left, and right. Though the car doesn't seem to turn a lot because of low power). I connected it to a 7.4v power supply, and it works fine, except it only moves forward and only turns right. Doesn't turn the motors the other direction.
I followed this tutorial. In case, you'd want the code.
I did have a change of code though, this is the only code I changed
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
// These are the pins used to control the motor shield
#define STEER_MOTOR_POWER D2 // Motor A
#define STEER_MOTOR_DIRECTION D3
#define DRIVE_MOTOR_POWER D1 // Motor B
#define DRIVE_MOTOR_DIRECTION D4
int drivePower = 1000;
uint8_t driveDirection = LOW;
int steeringPower = 1000;
uint8_t steerDirection = LOW;
// ----------------
// Set your WiFi SSID and Password here
// ----------------
const char* ssid = "xxxxx";
const char* password = "xxxxxxxxxxx";
ESP8266WebServer server(80);
void setup(void){
pinMode(DRIVE_MOTOR_POWER, OUTPUT); // Initialize the LED_BUILTIN pin as an output
pinMode(DRIVE_MOTOR_DIRECTION, OUTPUT);
pinMode(STEER_MOTOR_POWER, OUTPUT);
pinMode(STEER_MOTOR_DIRECTION, OUTPUT);
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(100);
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
Serial.println(WiFi.macAddress());
if (MDNS.begin("WifiCar")) {
Serial.println("MDNS Responder Started");
analogWrite(DRIVE_MOTOR_POWER, 10);
digitalWrite(DRIVE_MOTOR_DIRECTION, driveDirection);
delay(2000);
analogWrite(DRIVE_MOTOR_POWER, 0);
}
server.on("/car/controls/front", [](){
Serial.println("front");
analogWrite(DRIVE_MOTOR_POWER, drivePower);
digitalWrite(DRIVE_MOTOR_DIRECTION, driveDirection);
delay(100);
server.send(200, "text/plain", "front");
});
server.on("/car/controls/back", [](){
Serial.println("back");
analogWrite(DRIVE_MOTOR_POWER, drivePower);
digitalWrite(DRIVE_MOTOR_DIRECTION, !driveDirection);
delay(100);
server.send(200, "text/plain", "back");
});
server.on("/car/controls/stopDirection", [](){
delay(100);
Serial.println("stopDirection");
analogWrite(DRIVE_MOTOR_POWER, 0);
delay(100);
server.send(200, "text/plain", "stopDirection");
});
server.on("/car/controls/right", [](){
Serial.println("right");
analogWrite(STEER_MOTOR_POWER, steeringPower);
digitalWrite(STEER_MOTOR_DIRECTION, steerDirection);
delay(100);
server.send(200, "text/plain", "right");
});
server.on("/car/controls/left", [](){
Serial.println("left");
analogWrite(STEER_MOTOR_POWER, steeringPower);
digitalWrite(STEER_MOTOR_DIRECTION, !steerDirection);
delay(100);
server.send(200, "text/plain", "left");
});
server.on("/car/controls/stopSteering", [](){
delay(100);
Serial.println("stopSteering");
analogWrite(STEER_MOTOR_POWER, 0);
delay(100);
server.send(200, "text/plain", "stopSteering");
});
server.begin();
Serial.println("HTTP Server Started");
}
void loop(void){
server.handleClient();
}