From BT To WiFi: Creating WiFi Controlled Arduino Robot Car

From BT To WiFi: Creating WiFi Controlled Arduino Robot Car © GPL3+

NodeMCU ESP8266 in access point mode: the simplest way to make Wi-Fi controlled Robot Car from Bluetooth Arduino Robot Car + Android App.

  • 41,337 views
  • 29 comments
  • 83 respects

Components and supplies

Necessary tools and machines

09507 01
Soldering iron (generic)

Apps and online services

About this project

Story

In my project Smartphone Controlled Arduino 4WD Robot Car https://www.hackster.io/andriy-baranov/smartphone-controlled-arduino-4wd-robot-car-14d239 I presented a smartphone-controlled Arduino 4WD robot car or Bluetooth Arduino robot. Then I decided to make a Wi-Fi controlled robot car from a Bluetooth controlled one. For this purpose I simply removed Bluetooth module and added NodeMCU with the same wire connections (appropriate Andriod App was already created).

The NodeMCU ESP8266 works in acsess point mode in order to control robot car in open air, where there is not working Wi-Fi network.

How it works. At first we have to make connection to Wi-Fi Robot network and open Wi-Fi Robot Andriod App. When Forward button is touched down smartphone sends get request http://192.168.4.1/?State=F. Then, as we can see in sketch for the NodeMCU:

if( server.hasArg("State") ) {  Serial.println(server.arg("State"));  }

NodeMCU sends "F" to serial port. When Arduino Uno board recieves "F" via serial port it starts void goAhead():

  if (Serial.available() > 0) { command = Serial.read();   
   switch (command) { case 'F':goAhead();break; 

When Forward button is touched up Robot stops. Basic steps for remaking Bluetooth Robot Car into Wi-Fi one:

  • Remove Bluetooth module
  • Install NodeMCU ESP-12E Development Kit board
  • Upload sketches for Arduino Uno board and NodeMCU board in Arduino IDE
  • Connect wires Tx, Rx, +5v and GND to NodeMCU
  • Install and open Android App
  • Connect your smartphone to WiFi Robot network (without password) and enjoy driving Robot Car!

Step 1. The NodeMCU

This development board for the ESP8266 SoC inside the ESP-12E module is out-of-the-box ready for you to connect it to your computer, install USB drivers, and start writing programs that connect to your Wi-Fi network!

Step 2. Installing the NodeMCU board at Arduino IDE

  • In the MENU select: Tools → Board → Boards Manager and scroll down and to choose esp8266 by ESP8266 Community and click INSTALL. Installing takes about 3 minutes.
  • Install the USB Driver (in my case CH340).
  • Restart the Arduino IDE and select our board from the menu option: Tools → Board → NodeMCU 1.0 (ESP-12E Module).
  • Then, we specify the correct CPU Frequency (Tools → CPU Frequency→ 80MHz) and Upload Speed (Tools → Upload Speed → 115200).
  • Select the correct option for the Port (Tools → Port → COM5).

And now we are ready to upload our sketch for NodeMCU!

Step 3. Uploading sketches for Arduino Uno board and NodeMCU board

Before uploading do not forget to change selection of our board from the menu option:

  • Tools → Board → NodeMCU 1.0 (ESP-12E Module) or
  • Tools → Board → Arduino/Genuino Uno

Step 4. Wire connections

After uploading sketches we can connect Tx, Rx wires to NodeMCU board and +5v and GND wires.

Step 5. Andriod App and Finish!

Install my App (Wifi Robot #4).

Power up your Wi-Fi Robot Car, go to Wi-Fi settings of your smartphone and select Wi-Fi Robot network (without password). After connection to Wi-Fi Robot network open the App and enjoy driving Wi-Fi Robot Car!

Andrioid App for this project was created in MIT App Inventor. You can change it as you want using .aia file.

I would be grateful for constructive proposals and wishes!

Code

WiFi_Robot4_arduinoUno.inoArduino
Code for Arduino Uno board
#define light_FR  14    //LED Front Right   pin A0 for Arduino Uno
#define light_FL  15    //LED Front Left    pin A1 for Arduino Uno
#define horn_Buzz 18    //Horn Buzzer       pin A4 for Arduino Uno

#define ENA_m1 5        // Enable/speed motor Front Right 
#define ENB_m1 6        // Enable/speed motor Back Right
#define ENA_m2 10       // Enable/speed motor Front Left
#define ENB_m2 11       // Enable/speed motor Back Left

#define IN_11  2    		// L298N #1 in 1 motor Front Right
#define IN_12  3    		// L298N #1 in 2 motor Front Right
#define IN_13  4    		// L298N #1 in 3 motor Back Right
#define IN_14  7    		// L298N #1 in 4 motor Back Right

#define IN_21  8    		// L298N #2 in 1 motor Front Left
#define IN_22  9    		// L298N #2 in 2 motor Front Left
#define IN_23  12   		// L298N #2 in 3 motor Back Left
#define IN_24  13   		// L298N #2 in 4 motor Back Left

int command; 			      //Int to store app command state.
int speedCar = 100; 		// 50 - 255.
int speed_Coeff = 4;
boolean lightFront = false;
boolean horn = false;

void setup() {  
   
	  pinMode(light_FR, OUTPUT);
    pinMode(light_FL, OUTPUT);
    pinMode(horn_Buzz, OUTPUT);
    
	  pinMode(ENA_m1, OUTPUT);
  	pinMode(ENB_m1, OUTPUT);
	  pinMode(ENA_m2, OUTPUT);
	  pinMode(ENB_m2, OUTPUT);
  
    pinMode(IN_11, OUTPUT);
    pinMode(IN_12, OUTPUT);
    pinMode(IN_13, OUTPUT);
    pinMode(IN_14, OUTPUT);
    
    pinMode(IN_21, OUTPUT);
    pinMode(IN_22, OUTPUT);
    pinMode(IN_23, OUTPUT);
    pinMode(IN_24, OUTPUT);

	Serial.begin(115200); 

  } 

void goAhead(){ 

      digitalWrite(IN_11, HIGH);
      digitalWrite(IN_12, LOW);
	    analogWrite(ENA_m1, speedCar);

      digitalWrite(IN_13, LOW);
      digitalWrite(IN_14, HIGH);
	    analogWrite(ENB_m1, speedCar);


      digitalWrite(IN_21, LOW);
      digitalWrite(IN_22, HIGH);
	    analogWrite(ENA_m2, speedCar);


      digitalWrite(IN_23, HIGH);
      digitalWrite(IN_24, LOW);
	    analogWrite(ENB_m2, speedCar);

  }

void goBack(){ 

      digitalWrite(IN_11, LOW);
      digitalWrite(IN_12, HIGH);
	    analogWrite(ENA_m1, speedCar);


      digitalWrite(IN_13, HIGH);
      digitalWrite(IN_14, LOW);
	    analogWrite(ENB_m1, speedCar);


      digitalWrite(IN_21, HIGH);
      digitalWrite(IN_22, LOW);
	    analogWrite(ENA_m2, speedCar);


      digitalWrite(IN_23, LOW);
      digitalWrite(IN_24, HIGH);
	    analogWrite(ENB_m2, speedCar);

  }

void goRight(){ 

      digitalWrite(IN_11, LOW);
      digitalWrite(IN_12, HIGH);
	    analogWrite(ENA_m1, speedCar);


      digitalWrite(IN_13, HIGH);
      digitalWrite(IN_14, LOW);
	    analogWrite(ENB_m1, speedCar);


      digitalWrite(IN_21, LOW);
      digitalWrite(IN_22, HIGH);
	    analogWrite(ENA_m2, speedCar);


      digitalWrite(IN_23, HIGH);
      digitalWrite(IN_24, LOW);
	    analogWrite(ENB_m2, speedCar);


  }

void goLeft(){

      digitalWrite(IN_11, HIGH);
      digitalWrite(IN_12, LOW);
	    analogWrite(ENA_m1, speedCar);


      digitalWrite(IN_13, LOW);
      digitalWrite(IN_14, HIGH);
	    analogWrite(ENB_m1, speedCar);

        
      digitalWrite(IN_21, HIGH);
      digitalWrite(IN_22, LOW);
	    analogWrite(ENA_m2, speedCar);


      digitalWrite(IN_23, LOW);
      digitalWrite(IN_24, HIGH);
	    analogWrite(ENB_m2, speedCar);

        
  }

void goAheadRight(){
      
      digitalWrite(IN_11, HIGH);
      digitalWrite(IN_12, LOW);
      analogWrite(ENA_m1, speedCar/speed_Coeff);

      digitalWrite(IN_13, LOW);
      digitalWrite(IN_14, HIGH);
      analogWrite(ENB_m1, speedCar/speed_Coeff);


      digitalWrite(IN_21, LOW);
      digitalWrite(IN_22, HIGH);
      analogWrite(ENA_m2, speedCar);


      digitalWrite(IN_23, HIGH);
      digitalWrite(IN_24, LOW);
      analogWrite(ENB_m2, speedCar);
 
  }

void goAheadLeft(){
      
      digitalWrite(IN_11, HIGH);
      digitalWrite(IN_12, LOW);
      analogWrite(ENA_m1, speedCar);

      digitalWrite(IN_13, LOW);
      digitalWrite(IN_14, HIGH);
      analogWrite(ENB_m1, speedCar);


      digitalWrite(IN_21, LOW);
      digitalWrite(IN_22, HIGH);
      analogWrite(ENA_m2, speedCar/speed_Coeff);


      digitalWrite(IN_23, HIGH);
      digitalWrite(IN_24, LOW);
      analogWrite(ENB_m2, speedCar/speed_Coeff);
 
  }

void goBackRight(){ 

      digitalWrite(IN_11, LOW);
      digitalWrite(IN_12, HIGH);
      analogWrite(ENA_m1, speedCar/speed_Coeff);


      digitalWrite(IN_13, HIGH);
      digitalWrite(IN_14, LOW);
      analogWrite(ENB_m1, speedCar/speed_Coeff);


      digitalWrite(IN_21, HIGH);
      digitalWrite(IN_22, LOW);
      analogWrite(ENA_m2, speedCar);


      digitalWrite(IN_23, LOW);
      digitalWrite(IN_24, HIGH);
      analogWrite(ENB_m2, speedCar);

  }

void goBackLeft(){ 

      digitalWrite(IN_11, LOW);
      digitalWrite(IN_12, HIGH);
      analogWrite(ENA_m1, speedCar);


      digitalWrite(IN_13, HIGH);
      digitalWrite(IN_14, LOW);
      analogWrite(ENB_m1, speedCar);


      digitalWrite(IN_21, HIGH);
      digitalWrite(IN_22, LOW);
      analogWrite(ENA_m2, speedCar/speed_Coeff);


      digitalWrite(IN_23, LOW);
      digitalWrite(IN_24, HIGH);
      analogWrite(ENB_m2, speedCar/speed_Coeff);

  }

void stopRobot(){  

      digitalWrite(IN_11, LOW);
      digitalWrite(IN_12, LOW);
	    analogWrite(ENA_m1, speedCar);


      digitalWrite(IN_13, LOW);
      digitalWrite(IN_14, LOW);
	    analogWrite(ENB_m1, speedCar);

  
      digitalWrite(IN_21, LOW);
      digitalWrite(IN_22, LOW);
	    analogWrite(ENA_m2, speedCar);

      
      digitalWrite(IN_23, LOW);
      digitalWrite(IN_24, LOW);
	    analogWrite(ENB_m2, speedCar);
  
  }
  
void loop(){
    
if (Serial.available() > 0) {
	command = Serial.read();
	
if (lightFront) {digitalWrite(light_FR, HIGH); digitalWrite(light_FL, HIGH);}
if (!lightFront) {digitalWrite(light_FR, LOW); digitalWrite(light_FL, LOW);}
if (horn) {digitalWrite(horn_Buzz, HIGH);}
if (!horn) {digitalWrite(horn_Buzz, LOW);}

switch (command) {
case 'F':goAhead();break;
case 'B':goBack();break;
case 'L':goLeft();break;
case 'R':goRight();break;
case 'I':goAheadRight();break;
case 'G':goAheadLeft();break;
case 'J':goBackRight();break;
case 'H':goBackLeft();break;
case '0':speedCar = 100;break;
case '1':speedCar = 120;break;
case '2':speedCar = 135;break;
case '3':speedCar = 155;break;
case '4':speedCar = 170;break;
case '5':speedCar = 185;break;
case '6':speedCar = 195;break;
case '7':speedCar = 215;break;
case '8':speedCar = 235;break;
case '9':speedCar = 255;break;
case 'S':stopRobot();break;
case 'W':lightFront = true;break;
case 'w':lightFront = false;break;
case 'V':horn = true;break;
case 'v':horn = false;break;

}
}
}
WiFi_Robot4_NodeMCU_ESP8266.inoArduino
Code for NodeMCU_ESP8266 board
#include <ESP8266WiFi.h>
#include <WiFiClient.h> 
#include <ESP8266WebServer.h>

const char* host = "WiFi_Robot4_NodeMCU";
const char* ssid = "WiFi_Robot4";

ESP8266WebServer server(80);

void setup() {
  Serial.begin(115200);
  

// Connecting WiFi

  WiFi.mode(WIFI_AP);
  WiFi.softAP(ssid);
// Starting WEB-server
    
     server.on ( "/", HTTP_handleRoot );
     server.onNotFound ( HTTP_handleRoot );
     server.begin();    
     
}

void loop() {
  server.handleClient();
   delay(50);
}

void HTTP_handleRoot(void) {

if( server.hasArg("State") ){
       Serial.println(server.arg("State"));
  }
  server.send ( 200, "text/html", "" );
}

Custom parts and enclosures

Wi-Fi Robot .apk file
wifirobot_v03_MQYJJWi5zd.apk
Wi-Fi Robot .aia file
If you want to change .apk file
wifirobot_v03_GDgI6lmVqg.aia

Schematics

wifi_robot_car_dWyN5trVCL.fzz
wifi_robot_car_dWyN5trVCL.fzz
wifi_robot_car__E1hC3P8VcK.jpg
Wifi robot car  e1hc3p8vck

Comments

Similar projects you might like

Smartphone Controlled Arduino 4WD Robot Car

Project in progress by Andriy Baranov

  • 53,280 views
  • 43 comments
  • 98 respects

Arduino 4WD RC Car

Project tutorial by Andriy Baranov

  • 13,414 views
  • 4 comments
  • 48 respects

Bluetooth Controlled Pick And Place Robot

Project tutorial by Ahmed Ebrahem Ahmed

  • 8,971 views
  • 15 comments
  • 41 respects

Android Apps Controlled Arduino Robot Car

by Team platinum

  • 3,594 views
  • 0 comments
  • 16 respects

Bolt Controlled Robot Car

Project tutorial by Team Bolt

  • 1,508 views
  • 1 comment
  • 13 respects
Add projectSign up / Login