ESP8266 + L298N Motor Drive + Smartphone

ESP8266 + L298N Motor Drive + Smartphone © GPL3+

Control an Arduino robot with a smartphone using ESP8266.

  • 18,246 views
  • 11 comments
  • 28 respects

Components and supplies

About this project

This document is about my attempt to control an Arduino robot with L298N motor drive and AI-Thinker ESP8266. This robot was named UTFPRBot version 1.0.

Here is a YouTube video to demonstrate it running:

This project explains how to create this Arduino robot. Also, I describe my personal steps to simplify the deployment of programs to control this robot.

Components and Supplies

  • ESP8266 โ€“ Al Cloud Inside
  • Arduino UNO
  • Motor Drive L298N
  • Solderless breadboard shield
  • Jumpers (a lot)
  • LED
  • 1K Resistor
  • 2 DC motors of 5V
  • Robotic base with 2 tiers and 1 omnidirectional tier.
  • Smartphone

About this project

This project is the result of a lot of effort to construct a simple robot controlled by ESP8266. I have not found good sources on the Internet that describe a simple way to build robots with ESP8266. Also, I found a lot of information that empirically is not necessary to make it, even with comments in forums. This project proposes to simplify this difficult process.

Settings

This is our goal:

Wiring

I put an LED in the circuit just to know that the ESP8266 is really powered with 3.3V, but you can use a multimeter to verify voltage. I used a solderless breadboard due to multiple connections. I tried to use an Arduino breadboard shield to avoid using a solderless breadboard, but this module only does software deployed directly with the Arduino board.

ESP8266 -- Arduino

  • VCC ๐Ÿ š 3.3V
  • CH_PD ๐Ÿ š 3.3V
  • GPIO2 ๐Ÿ š 3.3V
  • GND ๐Ÿ š GND
  • GPIO0 ๐Ÿ š GND
  • TX ๐Ÿ š TX
  • RX ๐Ÿ š RX

Step 1) Update the ESP8266 firmware

This step is done once only to assure that firmware is updated.

a) ESP8266 deployment only works without ATMega chip. But you can plug in Arduino a single wire in RST and GND. Then, only the board will be used, and not the ATMega chip.

b) You need to plug GPIO0 to deploy, and you need to remove GPIO0 after the sketch deploys.

c) You need to always use RST pin before deploying to sync your ESP. Do RST with GND quickly, and observe the light blink. If nothing happens, try again until you see a blue blink. After the blue blink, remove RST wire.

d) Power up ESP8266. Connect VCC, CH_PD and GPIO2 to 3.3V. I used a 1K resistor only to avoid high amperage to my LED.

e) You need to plug Rx๐Ÿ šRx and Tx๐Ÿ šTx to deploy firmware in ESP8266.

f) After deployment, remove wires in this order: TX and RX, GPIO0, VCC. Plug in again only VCC to verify that your ESP8266 keeps your deploy.

Software:

  • FLASH_DOWNLOAD_TOOLS_v2.4_150924

1) Make the wiring of your ESP8266 module as illustrate in figure.

2) Open the FLASH_DOWNLOAD_TOOLS_v2.4_150924/ESP_DOWNLOAD_TOOL_V2.4.exe.

3) Open โ€œDevice Managerโ€ in Windows to verify COM port connectivity when you plug in the USB Arduino cable. Test your serial COM port in the FlashDownloadTools program. Just click the START button, but first uncheck the download path config checkboxes. DETECT INFO and MAC Address areas should display ESP8266 information.

3) Now, check the path boxes and fill the fields as illustrated in figure:

esp_iot_sdk_v1.5.0_15_11_27\esp_iot_sdk_v1.5.0\bin\esp_init_data_default.bin ร 0xfc000
esp_iot_sdk_v1.5.0\bin\blank.bin ร  0xfe000
esp_iot_sdk_v1.5.0\bin\boot_v1.4(b1).bin ร  0x00000
esp_iot_sdk_v1.5.0\bin\at\512+512\user1.1024.new.2.bin ร  0x01000
ai-thinker-0.9.5.2.bin ร  0x00000

4) Click START and wait - SYNC until a complete flash of firmware files.

5) After deployment, remove wires in this order: TX and RX, GPIO0, VCC. Plug in again only VCC to verify that your ESP8266 keeps your deployed code.

Step 2) Use Arduino to upload new sketch

At this step, you need to put ITEADLIB_Arduino_WeeESP8266-master in C:\Program Files (x86)\Arduino\libraries. Also, you need to uncomment the following line in ESP8266.h:

#define ESP8266_USE_SOFTWARE_SERIAL

At this step, you need to enable ESP8266 modules in Arduino IDE. (File ๐Ÿ š Preferences: Informe URL: http://arduino.esp8266.com/package_esp8266com_index.json). After, upload the ESP8266 modules (I installed all that I found useful and mentioned ESP8266).

In Arduino IDE, choose Generic ESP8266 Module. The value was set as follows:

Then upload the new sketch: Web Server to Receive HTTP Connections to move the robot. Remember the wiring to deploy sketches in ESP8266:

  • VCC ๐Ÿ š 3.3V
  • RST ๐Ÿ š GND
  • GPIO0 ๐Ÿ š GND
  • GND ๐Ÿ š GND
  • TX ๐Ÿ š TX and RX ๐Ÿ š RX

Remember the wiring to remove after deploy:

  • TX and RX
  • GPIO0
  • RST
  • VCC.

Now, plug again only VCC to assure that your sketch was deployed. Use the Code1 (attached) to: Create a WiFi access point and provide a web server on it to move robot.

Step 3) Deploy Arduino Sketch to read ESP8266 data from SoftwareSerial

Now, you need to deploy code to Arduino ATMega chip. Note that I am using a solderless breadboard shield. To avoid removing/placing the ATMega chip many times, now you need only remove RST wire from GND.

Important: To read data from SoftwareSerial, you invert the connection of RX/TX wiring that ESP8266 uses to connect to Arduino.

Wiring

Use the Code 2 (attached) to:

  • Parse serial data from ESP8266 and
  • Move motors controlled by L298N motor drive.

Step 4) Wiring with L298N and Arduino:

Wiring

Step 5: Fine! Now it is time to test.

  • Connect your smartphone in the ESP8266 wireless AP (it is not necessary to change the IP address of you smartphone or any host connected to ESP8266).
  • Simply select options and have fun!

Final remarks:

LLC (Logic Level Converter): I observed that many forums recommend using an LLC to connect ESP8266 to Arduino. I bought one and, to my surprise, I was not able to use it with ESP8266 and Arduino (it does not work to deploy or send/receive serial data). Apparently, its use is not necessary to update firmware, nor to deploy new programs within ESP8266. Some assumptions:

  • ESP8266 supports until +6V (I looked that an Arduino forum mentioned that ESP8266 has internal capacitors to support until +6V (and this information is in manual of ESP8226). I only use ESP8266 with Arduino ports, so I believe that 50mA from the Arduino will not burn ESP8266, because it can support nearly 250mA.
  • Arduino ports are nearly 50mA.
  • ESP8266 ports supports nearly 250mA.
  • I will only connect ESP8266 with Arduino.
  • Power supply: I was not able to use rechargeable 9V batteries to supply Arduino + ESP8266 + L298N due to quick consumption. However, for my purposes, I am comfortable using a USB with larger wiring to supply L298N motor drive.
  • I still do not known how to change the MAC address (probably recompiling files) nor how to change the IP address from ESP8266 (probably with AT commands; maybe dealing with AT commands (Step 1) and changing the IP).

Doubts, suggestions and comments are welcome.

Code

Code1: esp8266_L298N.inoArduino
Create a WiFi access point and provide a web server on it to move robot.
/* Create a WiFi access point and provide a web server on it to move robot. 
 *  
 *  Important: Use without ATMega328 chip, or wire RST in GND
 *  
 *  Author: Lucio A. Rocha
 *  Last Update: 25 Jan 2017
 *
 */

#include <ESP8266WiFi.h>
#include <WiFiClient.h> 
#include <ESP8266WebServer.h>

/* Set these to your desired credentials. */
const char *ssid = "utfprbot";
const char *password = "654321";

ESP8266WebServer server(80);

const int led = 2;  //GPIO2

/* Just a little test message.  Go to http://192.168.4.1 in a web browser
 * connected to this access point to see it.
 */
void handleRoot() {

  int size=1000;
  char temp[size];
  
  int sec = millis() / 1000;
  int min = sec / 60;
  int hr = min / 60;

  snprintf ( temp, size,

"<html>\
  <head>\    
    <title>UTFPRBOT-1.0</title>\
    <style>\
      body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }\
    </style>\
  </head>\
  <body>\
    <h3>You are connected on UTFPRBOT #1!</h3>\
    <p>Uptime: %02d:%02d:%02d</p>\    
    <p>Status: Light ON</h1></p>\
    <p><a href=\"http://192.168.4.1/on\"><h1>Turn ON</h1></a></p>\
    <p></p>\
    <p><a href=\"http://192.168.4.1/of\"><h1>Turn OFF</h1></a></p>\           
    <p></p>\
    <p><a href=\"http://192.168.4.1/st\"><h1 align=\"center\">STOP</h1></a></p>\
    <p></p>\
    <p><a href=\"http://192.168.4.1/up\"><h1 align=\"center\">/\\/\\</h1></a></p>\
    <p></p>\
    <p><a href=\"http://192.168.4.1/lu\"><h1 align=\"center\">/\\_____</h1></a><a href=\"http://192.168.4.1/ru\"><h1 align=\"center\">_____/\\</h1></a></p>\
    <p></p>\
    <p><a href=\"http://192.168.4.1/ld\"><h1 align=\"center\">\\/_____</h1></a><a href=\"http://192.168.4.1/rd\"><h1 align=\"center\">_____\\/</h1></a></p>\
    <p><a href=\"http://192.168.4.1/do\"><h1 align=\"center\">\\/\\/</h1></a></p>\
    <p></p>\
  </body>\
</html>",

    hr, min % 60, sec % 60
  );
  server.send ( 200, "text/html", temp );  
  
}

void setup() {
  delay(1000);
  Serial.begin(9600);
  Serial.println();
  Serial.print("Configuring access point...");

  /* You can remove the password parameter if you want the AP to be open. */
  WiFi.softAP(ssid, password);

  IPAddress myIP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(myIP);

  pinMode(led, OUTPUT);
  digitalWrite ( led, HIGH );

  //URLs available to query
  server.on("/", handleRoot);  
  server.on ( "/up", moveUp );        //1
  server.on ( "/lu", moveLeftUp );    //2
  server.on ( "/ru", moveRightUp );   //3
  server.on ( "/ld", moveLeftDown );  //4
  server.on ( "/rd", moveRightDown ); //5
  server.on ( "/do", moveDown );      //6
  server.on ( "/st", moveStop );      //7
  server.on ( "/on", turnOn );        //8
  server.on ( "/of", turnOff );       //9  
  
  server.begin();
  Serial.println("HTTP server started");
  
}

void moveUp(){

  digitalWrite ( led, HIGH );

  int size=1000;
  char temp[size];

  int sec = millis() / 1000;
  int min = sec / 60;
  int hr = min / 60;

  snprintf ( temp, size,

"<html>\
  <head>\
    <title>UTFPRBOT - 1.0</title>\
    <style>\
      body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }\
    </style>\
  </head>\
  <body>\
    <h3>Request: Move UP</h3>\
    <p>Uptime: %02d:%02d:%02d</p>\
    <p><a href=\"http://192.168.4.1/on\"><h1>Turn ON</h1></a></p>\
    <p></p>\
    <p><a href=\"http://192.168.4.1/of\"><h1>Turn OFF</h1></a></p>\           
    <p></p>\
    <p><a href=\"http://192.168.4.1/st\"><h1 align=\"center\">STOP</h1></a></p>\
    <p></p>\
    <p><a href=\"http://192.168.4.1/up\"><h1 align=\"center\">/\\/\\</h1></a></p>\
    <p></p>\
    <p><a href=\"http://192.168.4.1/lu\"><h1 align=\"center\">/\\_____</h1></a><a href=\"http://192.168.4.1/ru\"><h1 align=\"center\">_____/\\</h1></a></p>\
    <p></p>\
    <p><a href=\"http://192.168.4.1/ld\"><h1 align=\"center\">\\/_____</h1></a><a href=\"http://192.168.4.1/rd\"><h1 align=\"center\">_____\\/</h1></a></p>\
    <p><a href=\"http://192.168.4.1/do\"><h1 align=\"center\">\\/\\/</h1></a></p>\
    <p></p>\
  </body>\
</html>",

    hr, min % 60, sec % 60
  );

  server.send ( 200, "text/html", temp);
  Serial.println("SETM1");
  
}

void moveLeftUp(){

  digitalWrite ( led, HIGH );

  int size=1000;
  char temp[size];

  int sec = millis() / 1000;
  int min = sec / 60;
  int hr = min / 60;

  snprintf ( temp, size,

"<html>\
  <head>\
    <title>UTFPRBOT - 1.0</title>\
    <style>\
      body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }\
    </style>\
  </head>\
  <body>\
    <h3>Request: Move LEFT-UP</h3>\
    <p>Uptime: %02d:%02d:%02d</p>\
    <p><a href=\"http://192.168.4.1/on\"><h1>Turn ON</h1></a></p>\
    <p></p>\
    <p><a href=\"http://192.168.4.1/of\"><h1>Turn OFF</h1></a></p>\           
    <p></p>\
    <p><a href=\"http://192.168.4.1/st\"><h1 align=\"center\">STOP</h1></a></p>\
    <p></p>\
    <p><a href=\"http://192.168.4.1/up\"><h1 align=\"center\">/\\/\\</h1></a></p>\
    <p></p>\
    <p><a href=\"http://192.168.4.1/lu\"><h1 align=\"center\">/\\_____</h1></a><a href=\"http://192.168.4.1/ru\"><h1 align=\"center\">_____/\\</h1></a></p>\
    <p></p>\
    <p><a href=\"http://192.168.4.1/ld\"><h1 align=\"center\">\\/_____</h1></a><a href=\"http://192.168.4.1/rd\"><h1 align=\"center\">_____\\/</h1></a></p>\
    <p><a href=\"http://192.168.4.1/do\"><h1 align=\"center\">\\/\\/</h1></a></p>\
    <p></p>\
  </body>\
</html>",

    hr, min % 60, sec % 60
  );

  server.send ( 200, "text/html", temp);
  Serial.println("SETM2");
  
}

void moveLeftDown(){

  digitalWrite ( led, HIGH );

  int size=1000;
  char temp[size];

  int sec = millis() / 1000;
  int min = sec / 60;
  int hr = min / 60;

  snprintf ( temp, size,

"<html>\
  <head>\
    <title>UTFPRBOT - 1.0</title>\
    <style>\
      body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }\
    </style>\
  </head>\
  <body>\
    <h3>Request: Move LEFT-DOWN</h3>\
    <p>Uptime: %02d:%02d:%02d</p>\
    <p><a href=\"http://192.168.4.1/on\"><h1>Turn ON</h1></a></p>\
    <p></p>\
    <p><a href=\"http://192.168.4.1/of\"><h1>Turn OFF</h1></a></p>\           
    <p></p>\
    <p><a href=\"http://192.168.4.1/st\"><h1 align=\"center\">STOP</h1></a></p>\
    <p></p>\
    <p><a href=\"http://192.168.4.1/up\"><h1 align=\"center\">/\\/\\</h1></a></p>\
    <p></p>\
    <p><a href=\"http://192.168.4.1/lu\"><h1 align=\"center\">/\\_____</h1></a><a href=\"http://192.168.4.1/ru\"><h1 align=\"center\">_____/\\</h1></a></p>\
    <p></p>\
    <p><a href=\"http://192.168.4.1/ld\"><h1 align=\"center\">\\/_____</h1></a><a href=\"http://192.168.4.1/rd\"><h1 align=\"center\">_____\\/</h1></a></p>\
    <p><a href=\"http://192.168.4.1/do\"><h1 align=\"center\">\\/\\/</h1></a></p>\
    <p></p>\
  </body>\
</html>",

    hr, min % 60, sec % 60
  );

  server.send ( 200, "text/html", temp);
  Serial.println("SETM4");
  
}

void moveRightUp(){

  digitalWrite ( led, HIGH );

  int size=1000;
  char temp[size];

  int sec = millis() / 1000;
  int min = sec / 60;
  int hr = min / 60;

  snprintf ( temp, size,

"<html>\
  <head>\
    <title>UTFPRBOT - 1.0</title>\
    <style>\
      body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }\
    </style>\
  </head>\
  <body>\
    <h3>Request: Move RIGHT-UP</h3>\
    <p>Uptime: %02d:%02d:%02d</p>\
    <p><a href=\"http://192.168.4.1/on\"><h1>Turn ON</h1></a></p>\
    <p></p>\
    <p><a href=\"http://192.168.4.1/of\"><h1>Turn OFF</h1></a></p>\           
    <p></p>\
    <p><a href=\"http://192.168.4.1/st\"><h1 align=\"center\">STOP</h1></a></p>\
    <p></p>\
    <p><a href=\"http://192.168.4.1/up\"><h1 align=\"center\">/\\/\\</h1></a></p>\
    <p></p>\
    <p><a href=\"http://192.168.4.1/lu\"><h1 align=\"center\">/\\_____</h1></a><a href=\"http://192.168.4.1/ru\"><h1 align=\"center\">_____/\\</h1></a></p>\
    <p></p>\
    <p><a href=\"http://192.168.4.1/ld\"><h1 align=\"center\">\\/_____</h1></a><a href=\"http://192.168.4.1/rd\"><h1 align=\"center\">_____\\/</h1></a></p>\
    <p><a href=\"http://192.168.4.1/do\"><h1 align=\"center\">\\/\\/</h1></a></p>\
    <p></p>\
  </body>\
</html>",

    hr, min % 60, sec % 60
  );

  server.send ( 200, "text/html", temp);
  Serial.println("SETM3");
  
}

void moveRightDown(){

  digitalWrite ( led, HIGH );

  int size=1000;
  char temp[size];

  int sec = millis() / 1000;
  int min = sec / 60;
  int hr = min / 60;

  snprintf ( temp, size,

"<html>\
  <head>\
    <title>UTFPRBOT - 1.0</title>\
    <style>\
      body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }\
    </style>\
  </head>\
  <body>\
    <h3>Request: Move RIGHT-DOWN</h3>\
    <p>Uptime: %02d:%02d:%02d</p>\
    <p><a href=\"http://192.168.4.1/on\"><h1>Turn ON</h1></a></p>\
    <p></p>\
    <p><a href=\"http://192.168.4.1/of\"><h1>Turn OFF</h1></a></p>\           
    <p></p>\
    <p><a href=\"http://192.168.4.1/st\"><h1 align=\"center\">STOP</h1></a></p>\
    <p></p>\
    <p><a href=\"http://192.168.4.1/up\"><h1 align=\"center\">/\\/\\</h1></a></p>\
    <p></p>\
    <p><a href=\"http://192.168.4.1/lu\"><h1 align=\"center\">/\\_____</h1></a><a href=\"http://192.168.4.1/ru\"><h1 align=\"center\">_____/\\</h1></a></p>\
    <p></p>\
    <p><a href=\"http://192.168.4.1/ld\"><h1 align=\"center\">\\/_____</h1></a><a href=\"http://192.168.4.1/rd\"><h1 align=\"center\">_____\\/</h1></a></p>\
    <p><a href=\"http://192.168.4.1/do\"><h1 align=\"center\">\\/\\/</h1></a></p>\
    <p></p>\
  </body>\
</html>",

    hr, min % 60, sec % 60
  );

  server.send ( 200, "text/html", temp);
  Serial.println("SETM5");
  
}

void moveDown(){

  digitalWrite ( led, HIGH );

  int size=1000;
  char temp[size];

  int sec = millis() / 1000;
  int min = sec / 60;
  int hr = min / 60;

  snprintf ( temp, size,

"<html>\
  <head>\
    <title>UTFPRBOT - 1.0</title>\
    <style>\
      body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }\
    </style>\
  </head>\
  <body>\
    <h3>Request: Move DOWN</h3>\    
    <p>Uptime: %02d:%02d:%02d</p>\
    <p><a href=\"http://192.168.4.1/on\"><h1>Turn ON</h1></a></p>\
    <p></p>\
    <p><a href=\"http://192.168.4.1/of\"><h1>Turn OFF</h1></a></p>\           
    <p></p>\
    <p><a href=\"http://192.168.4.1/st\"><h1 align=\"center\">STOP</h1></a></p>\
    <p></p>\
    <p><a href=\"http://192.168.4.1/up\"><h1 align=\"center\">/\\/\\</h1></a></p>\
    <p></p>\
    <p><a href=\"http://192.168.4.1/lu\"><h1 align=\"center\">/\\_____</h1></a><a href=\"http://192.168.4.1/ru\"><h1 align=\"center\">_____/\\</h1></a></p>\
    <p></p>\
    <p><a href=\"http://192.168.4.1/ld\"><h1 align=\"center\">\\/_____</h1></a><a href=\"http://192.168.4.1/rd\"><h1 align=\"center\">_____\\/</h1></a></p>\
    <p><a href=\"http://192.168.4.1/do\"><h1 align=\"center\">\\/\\/</h1></a></p>\
    <p></p>\
  </body>\
</html>",

    hr, min % 60, sec % 60
  );

  server.send ( 200, "text/html", temp);
  Serial.println("SETM6");
  
}


void moveStop(){

  digitalWrite ( led, HIGH );

  int size=1000;
  char temp[size];

  int sec = millis() / 1000;
  int min = sec / 60;
  int hr = min / 60;

  snprintf ( temp, size,

"<html>\
  <head>\
    <title>UTFPRBOT - 1.0</title>\
    <style>\
      body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }\
    </style>\
  </head>\
  <body>\
    <h3>Request: STOP</h3>\
    <p>Uptime: %02d:%02d:%02d</p>\
    <p><a href=\"http://192.168.4.1/on\"><h1>Turn ON</h1></a></p>\
    <p></p>\
    <p><a href=\"http://192.168.4.1/of\"><h1>Turn OFF</h1></a></p>\           
    <p></p>\
    <p><a href=\"http://192.168.4.1/st\"><h1 align=\"center\">STOP</h1></a></p>\
    <p></p>\
    <p><a href=\"http://192.168.4.1/up\"><h1 align=\"center\">/\\/\\</h1></a></p>\
    <p></p>\
    <p><a href=\"http://192.168.4.1/lu\"><h1 align=\"center\">/\\_____</h1></a><a href=\"http://192.168.4.1/ru\"><h1 align=\"center\">_____/\\</h1></a></p>\
    <p></p>\
    <p><a href=\"http://192.168.4.1/ld\"><h1 align=\"center\">\\/_____</h1></a><a href=\"http://192.168.4.1/rd\"><h1 align=\"center\">_____\\/</h1></a></p>\
    <p><a href=\"http://192.168.4.1/do\"><h1 align=\"center\">\\/\\/</h1></a></p>\
    <p></p>\
  </body>\
</html>",

    hr, min % 60, sec % 60
  );

  server.send ( 200, "text/html", temp);
  Serial.println("SETM7");
  
}

void turnOn(){

  digitalWrite ( led, HIGH );

  int size=1000;
  char temp[size];

  int sec = millis() / 1000;
  int min = sec / 60;
  int hr = min / 60;

  snprintf ( temp, size,

"<html>\
  <head>\    
    <title>UTFPRBOT - 1.0</title>\
    <style>\
      body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }\
    </style>\
  </head>\
  <body>\
    <h3>Request: Light ON</h3>\
    <p>Uptime: %02d:%02d:%02d</p>\
    <p>Status: Light ON</p>\        
    <p><a href=\"http://192.168.4.1/on\"><h1>Turn ON</h1></a></p>\
    <p></p>\
    <p><a href=\"http://192.168.4.1/of\"><h1>Turn OFF</h1></a></p>\           
    <p></p>\
    <p><a href=\"http://192.168.4.1/st\"><h1 align=\"center\">STOP</h1></a></p>\
    <p></p>\
    <p><a href=\"http://192.168.4.1/up\"><h1 align=\"center\">/\\/\\</h1></a></p>\
    <p></p>\
    <p><a href=\"http://192.168.4.1/lu\"><h1 align=\"center\">/\\_____</h1></a><a href=\"http://192.168.4.1/ru\"><h1 align=\"center\">_____/\\</h1></a></p>\
    <p></p>\
    <p><a href=\"http://192.168.4.1/ld\"><h1 align=\"center\">\\/_____</h1></a><a href=\"http://192.168.4.1/rd\"><h1 align=\"center\">_____\\/</h1></a></p>\
    <p><a href=\"http://192.168.4.1/do\"><h1 align=\"center\">\\/\\/</h1></a></p>\
    <p></p>\
  </body>\
</html>",

    hr, min % 60, sec % 60
  );

  server.send ( 200, "text/html", temp);
  Serial.println("SETM8");
}

void turnOff(){

  digitalWrite ( led, LOW );

  int size=1000;
  char temp[size];

  int sec = millis() / 1000;
  int min = sec / 60;
  int hr = min / 60;

  snprintf ( temp, size,

"<html>\
  <head>\    
    <title>UTFPRBOT - 1.0</title>\
    <style>\
      body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }\
    </style>\
  </head>\
  <body>\
    <h3>Request: Light OFF</h3>\
    <p>Uptime: %02d:%02d:%02d</p>\
    <p>Status: Light OFF</p>\        
    <p><a href=\"http://192.168.4.1/on\"><h1>Turn ON</h1></a></p>\
    <p></p>\
    <p><a href=\"http://192.168.4.1/of\"><h1>Turn OFF</h1></a></p>\           
    <p></p>\
    <p><a href=\"http://192.168.4.1/st\"><h1 align=\"center\">STOP</h1></a></p>\
    <p></p>\
    <p><a href=\"http://192.168.4.1/up\"><h1 align=\"center\">/\\/\\</h1></a></p>\
    <p></p>\
    <p><a href=\"http://192.168.4.1/lu\"><h1 align=\"center\">/\\_____</h1></a><a href=\"http://192.168.4.1/ru\"><h1 align=\"center\">_____/\\</h1></a></p>\
    <p></p>\
    <p><a href=\"http://192.168.4.1/ld\"><h1 align=\"center\">\\/_____</h1></a><a href=\"http://192.168.4.1/rd\"><h1 align=\"center\">_____\\/</h1></a></p>\
    <p><a href=\"http://192.168.4.1/do\"><h1 align=\"center\">\\/\\/</h1></a></p>\
    <p></p>\
  </body>\
</html>",

    hr, min % 60, sec % 60
  );

  server.send ( 200, "text/html", temp);
  Serial.println("SETM9");
}

void loop() {
  //IPAddress myIP = WiFi.softAPIP();
  //Serial.print("AP IP address: ");
  //Serial.println(myIP);
  server.handleClient();
}
Code2: SoftwareSerialArduino
Software to parse serial data from ESP8266 and
move motors controlled by L298N motor drive.
/*
SoftwareSerialParser
(based on SoftwareSerialExample.ino)

Description: Software to parse serial data from ESP8266 and
move motors controlled by L298N motor drive.

Author: Lucio A. Rocha
Last update: 12/03/2017

 */
#include <SoftwareSerial.h>

int IN3 = 8; //IN3 motor = pino no arduino
int IN4 = 7;
int ENB = 6; // ENB eh o pino de controle de velocidade no motor

int IN1 = 5; //IN1 motor = pino no arduino
int IN2 = 4;
int ENA = 3; // ENA eh o pino de controle de velocidade no motor

int TIME_MOVE=2000; //Tempo de cada movimento

SoftwareSerial mySerial(0, 1); // RX, TX

void setup() {

  pinMode(ENB, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);
  
  pinMode(ENA, OUTPUT);
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  Serial.println("SoftwareSerialParser Started!");

  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
  mySerial.println("Hello, world?");
}


void moveMotor(char c){
   
   Serial.println(c);

   switch (c){
    //Up
    case '1': 
      //Prepara a saida do motor
      digitalWrite(IN1, LOW);
      digitalWrite(IN2, HIGH);
      //Prepara a saida do motor
      digitalWrite(IN3, HIGH);
      digitalWrite(IN4, LOW);
      //Move
      analogWrite(ENA, 255);
      analogWrite(ENB, 255);
      delay(TIME_MOVE);  
      //Desliga o motor e espera
      analogWrite(ENA, 0);
      analogWrite(ENB, 0);      
      break;
    //LeftUp
    case '2':       
      //Prepara a saida do motor
      digitalWrite(IN3, HIGH);
      digitalWrite(IN4, LOW);
      //Move      
      analogWrite(ENB, 255);
      delay(TIME_MOVE);  
      //Desliga o motor e espera      
      analogWrite(ENB, 0);      
      break;      
    //RightUp
    case '3':       
      //Prepara a saida do motor
      digitalWrite(IN1, LOW);
      digitalWrite(IN2, HIGH);      
      //Move
      analogWrite(ENA, 255);      
      delay(TIME_MOVE);  
      //Desliga o motor e espera
      analogWrite(ENA, 0);
      break;
    //LeftDown
    case '4':       
      //Prepara a saida do motor
      digitalWrite(IN3, LOW);
      digitalWrite(IN4, HIGH);
      //Move      
      analogWrite(ENB, 255);
      delay(TIME_MOVE);  
      //Desliga o motor e espera      
      analogWrite(ENB, 0);      
      break;        
      //RightDown
    case '5':       
      //Prepara a saida do motor
      digitalWrite(IN1, HIGH);
      digitalWrite(IN2, LOW);      
      //Move
      analogWrite(ENA, 255);      
      delay(TIME_MOVE);  
      //Desliga o motor e espera
      analogWrite(ENA, 0);
      break;
      //Down
    case '6':                
//Prepara a saida do motor
      digitalWrite(IN1, HIGH);
      digitalWrite(IN2, LOW);
      //Prepara a saida do motor
      digitalWrite(IN3, LOW);
      digitalWrite(IN4, HIGH);
      //Move
      analogWrite(ENA, 255);
      analogWrite(ENB, 255);
      delay(TIME_MOVE);  
      //Desliga o motor e espera
      analogWrite(ENA, 0);
      analogWrite(ENB, 0);      
      break;
  //Stop
    case '7':                
      //Desliga o motor e espera
      analogWrite(ENA, 0);
      analogWrite(ENB, 0);      
      break;      
    default:
      break;
   }//end switch
 
}


void parseMove(String response){
      Serial.print("[");
      String movement="";
      int i=0;
      char c = response[i];
      while (i<4){ //Take first 5 chars from readings of ESP8266 line
        c = response[i];
        movement+=c;
        Serial.print(c);
        i=i+1;
     }
    //Takes on more char to identify the number of movement
    c = response[i];
    if (movement=="SETM"){     
      movement+=c;
      Serial.println("\n===========================================");      
      Serial.println(movement);
      Serial.println(c);

      //c is the number of movement
      moveMotor(c);

      Serial.println("-------------------------------------------");  
    }
     Serial.print("]");
}  

void loop() { // run over and over
  String response = "";
  bool achou=false;  
  while (mySerial.available()) {
    response = mySerial.readStringUntil('\n');
    Serial.println(response);

    parseMove(response);
   
  }
}

Schematics

ESP8266 wiring to firmware update with FLASH Download Tools
Esp8266 deploy fqkjbh5epj
ESP8266 witing to deploy HTTP Web Server with Arduino Board
Esp8266 arduino deploy 2yi0u7eeag
Arduino + L298N motor drive wiring
Motor l298n deploy pflhpjenzy

Comments

Similar projects you might like

ESP8266 ESP-01 Webserver

by Robin

  • 100,362 views
  • 18 comments
  • 131 respects

Control Arduino Uno Using ESP8266 WiFi Module and Blynk App

Project tutorial by Adithya TG

  • 5,254 views
  • 10 comments
  • 18 respects

Control Speed and Direction of Motor

Project in progress by ahmed soliman

  • 14,773 views
  • 3 comments
  • 20 respects

Arduino Burglar

Project showcase by paolo_cravero

  • 2,376 views
  • 2 comments
  • 6 respects

Smartphone Controlled Arduino 4WD Robot Car

Project in progress by Andriy Baranov

  • 53,239 views
  • 43 comments
  • 98 respects
Add projectSign up / Login