Controle de carro robótico por WiFi

WiFi Robotic Car Control

This tutorial will teach you how to control a Robo car using any Wifi enabled device.

Required components:

1. ESP 8266 Wi-Fi Module
2. Arduino UNO (or equivalent) 3. Driver L293D 4. Chassis 5. 12V DC gearmotors 6. Wheels 7. Spinning wheel 8. Yarn 9. Test board 10. Small PCB 11. Masculine Headers 12. Girly headers

About ESP8266

ESP 8266 is the latest thing on the internet. It's a Wifi module a little bigger than a 1 Re coin. Well, that's not why he's famous. What has made it very popular among electronics enthusiasts is its incredibly low cost. I bought it for just $5 (~300 Rs). An Arduino along with a Wifi shield would cost 10 times the cost of this module.

Imagem mostrando módulos Wi-Fi ESP8266

Fig. 1: Image showing ESP8266 Wi-Fi modules

It can be interconnected with any microcontroller through USART communication, which means that it only needs the RX and TX pins. Another feather to the hat was recently added. The developer has released the SDK files of the module and hence even the module can be reprogrammed and its GPIO pins can be used independently without any additional microcontroller. But that's beyond the scope of this tutorial. We would be using the module along with Arduino UNO.

Making a Breadboard Adapter for the ESP8266 Module:

The problem with the physical feature of the module is that you cannot connect it directly to a breadboard. So I decided to make an adapter that will be used to connect the module to a breadboard. These are the parts you would need to make the adapter:

Imagem mostrando os componentes necessários para fazer o adaptador breadboard do modem ESP8266

Figure 2: Image showing the components needed to make the ESP8266 modem breadboard adapter

Start by soldering the female connector to the PCB. Solder the corner pins first so that the header fits properly on the PCB. Then solder the remaining 4 pins.

Imagem mostrando PCB do adaptador de placa de ensaio soldada para caber no cabeçalho fêmea do modem ESP8266

Fig. 3: Image showing breadboard adapter PCB soldered to fit ESP8266 modem female header

Then place the male connectors on the opposite side of the PCB and carefully solder them to the PCB.

Imagem mostrando o cabeçalho macho colocado no adaptador da placa de ensaio do modem ESP8266

Figure 4: Image showing the male header placed on the ESP8266 modem breadboard adapter

After soldering, you can remove the black plastic piece attached to the male connector and begin soldering each male pin to the corresponding female pin. In the end you would have something like this:

Imagem mostrando o cabeçalho macho soldado no adaptador da placa de ensaio do modem ESP8266

Fig. 5: Image showing the male connector soldered onto the ESP8266 modem breadboard adapter

Once you do this, you can plug it into a breadboard and connect the ESP 8266 module to it easily.

Here is a detailed video tutorial showing the process: (Optional)

Imagem mostrando o adaptador de placa de ensaio do modem ESP8266 colocado em uma placa de ensaio

Figure 6: Image showing the ESP8266 modem breadboard adapter placed on a breadboard

Imagem mostrando o módulo Wi-Fi ESP8266 colocado sobre a placa de ensaio

Figure 7: Image showing the ESP8266 Wi-Fi module placed on the breadboard

AT commands for ESP 8266:

Command

Description

AT+GMR

To find out the firmware version

AT+RST

To reset the module

AT+CWMODE

To set the mode of operation, i.e. as access point or station mode or both.

AT+CWLAP

To see the list of available APs

AT+CIPSERVER

To set as server

AT+CIPMUX

To choose between single or multiple connections

AT+CIPSEND

To set channel number, data length and send data over WiFi

AT+CYPCLOSIS

To close the connection

Server on ESP 8266:

We will be sending a web interface (an HTML page) to any device (say a Wifi enabled mobile phone) connected to the Wifi module. The HTML page code would be provided by Arduino. And also, Arduino would decode the request from the device and control the motors accordingly. As the Wifi module can also function as an access point, we do not need an extra wireless router for the project. If you have no idea about HTML pages, go to my project “Controlling Appliances over Wifi and Ethernet” and learn the basics. Here is the algorithm to be followed to configure a server on ESP 8266:

Algorithm:

– Test module using the “AT” command – Set the operating mode using the command “AT+CWMODE= ” – Define the number of connections using the command “AT+CIPMUX= ” – Define it as a server using the command “AT+CIPSERVER= , ” – If the GET request is received from a browser, use the command “AT+CIPSEND= , ” followed by the HTML data you want to send. – After completion, close the connection using the “AT+CIPCLOSE” command.

Hardware configuration:

Gather all the pieces shown in the image.

Imagem mostrando os componentes necessários para fazer o robô

Figure 8: Image showing the components needed to make the robot

Attach the engines to the chassis and then the wheels to the axle.

Imagem mostrando a estrutura metálica do robô conectada ao motor DC

Figure 9: Image showing the metal structure of the robot connected to the DC motor

Use some screws and nuts to fix the spinning wheel

Imagem mostrando rodas conectadas aos motores DC no Robot

Figure 10: Image showing wheels connected to DC motors on the Robot

Imagem da roda giratória fixada na parte frontal do Robot Car

Figure 11: Image of the rotating wheel attached to the front of the Robot Car

Imagem do carro robótico totalmente montado

Figure 12:

Code explanation:

– Define pins 8, 9, 10 and 11 as output pins and serial communication with a baud rate of 9600 bps. – Send the “AT” command to the module. – Set the operation mode to station and access point using the command “AT+CWMODE=3” – Set the connection mode to multiple connections by sending “AT+CIPMUX=1” – Put the module in Server mode and use the default port sending “AT+CIPSERVER=1, 80” – Enter infinite loop and check for incoming Wifi requests – If a request was made, read the request and store the channel number where the request originated – Send the HTML page code to the stored channel number using the commands “AT+CIPSEND= , ” followed by the HTML code data. – Close the connection using “AT+CIPCLOSE= ” and wait for the next request made by the browser. – If the request is received, read it and decode the request instruction. Take corresponding measures on the engines. (For example, If you click “Next” on the web page, Arduino will listen to the request, switch to the robot direction to forward)

Setup Instructions

-Connect everything according to the circuit diagram and turn on the entire system.

Protótipo de carro robótico simples

Fig. 13: Simple robotic car prototype

– Wait a few seconds for Wifi and Arduino to initialize. After about 30 seconds, activate Wifi on your device (mobile, tablet or laptop) and you will see some available networks.

– You can connect to your home network (which is “ Robots Recharged ” in my case and that’s what I’m going to connect to) or to the access point itself (which is “ ESP_9F0F14 ” in my case. The SSID of the module is nothing more is than your name followed by the last 6 characters of your MAC address)

Protótipo de circuito de controle baseado em Arduino montado em carro robótico

Figure 14: Arduino-based control circuit prototype mounted on robotic car

– Then open your browser and enter the IP address

1. From the module on the home network if you are connected to the home network (like me and in my case it is 192.168.0.101 or 192.168.0.102 ) Or 2. 192.168.1.4 if you connect to the access point named “ESP_<last 6 characters of MAC address>” In a moment you should see a page like this in your browser: Now click on the links and you will see the engine start moving. If they are moving in the wrong direction, check the connections and change them if necessary.

Captura de tela de conexões Wi-Fi no telefone Android mostrando o ponto de acesso do módulo ESP

Figure 15: Screenshot of Wi-Fi connections on Android phone showing ESP module hotspot

– You can connect to your home network (which is “Robots Reloaded” in my case and that is what I will connect to) or to the Access Point itself (which is “ESP_9F0F14” in my case. The SSID of the module is nothing more is than your name followed by the last 6 characters of your MAC address)

Project source code

 #define esp Serial
#define in1 8#define in2 9#define in3 10#define in4 11#define BUFFER_SIZE 1000char buffer(BUFFER_SIZE); void send_at(String x){ esp.println(x);} void setup { pinMode(in1, OUTPUT);pinMode(in2, OUTPUT);pinMode(in3, OUTPUT);pinMode(in4, OUTPUT);delay(2000) ;esp.begin(9600);esp.println("AT");delay(1000);esp.println("AT+CWMODE=3");delay(1000);esp.println("AT+CIPMUX=1 ");delay(1000);esp.println("AT+CIPSERVER=1.80");delay(1000);esp.println("AT+CIFSR");delay(1000);} bool read_till_eol { static int i=0; if(esp.available ) { char c=esp.read ; buffer(i++)=c; if(i==BUFFER_SIZE) i=0; if(i>1 && buffer(i-2)==13 && buffer(i-1)==10) { buffer(i)=0; i=0; return true; } } return false;} void loop { int ch_id, packet_len; char *pb; if(read_till_eol ) { if(strncmp(buffer, "+IPD,", 5)==0) { // request format: +IPD,ch,len:data sscanf(buffer+5, "%d,%d" , &ch_id, &packet_len); if (packet_len > 0) { pb = buffer+5; while(*pb!=':') pb++; pb++; if (strncmp(pb, "GET / ", 6) == 0) { serve_homepage(ch_id,0); } else if (strncmp(pb, "GET /?fwd", 9) == 0){ forward ; serve_homepage(ch_id,1); } else if (strncmp(pb, "GET /?rev", 9) == 0){ reverse ; serve_homepage(ch_id,2); } else if (strncmp(pb, "GET /?rgt", 9) == 0){ right ; serve_homepage(ch_id,3); } else if (strncmp(pb, "GET /?lft", 9) == 0){ left ; serve_homepage(ch_id,4); } else if (strncmp(pb, "GET /?stp", 9) == 0){ stop_bot ; serve_homepage(ch_id,0); } } }} } void serve_homepage(int ch_id, byte state){ delay(1000); esp.print(F("AT+CIPSEND=")); esp.print(ch_id); esp.print(","); esp.println("512"); delay(500); esp.print("HTTP/1.1 200 OKrnContent-Type:text/htmlrnrn ROBOT CONTROLLER
WELCOME TO THE WEB INTERFACE OF ROBOT CONTROLLER OVER WIFI

"); esp.print("

FORWARD

LEFT STOP "); esp.print("RIGHT

REVERSE


Created by GANESH SELVARAJ for EngineersGarage.com


"); delay(5000); esp.print(F("AT+CIPCLOSE=")); esp.println(ch_id);} void forward { digitalWrite(in1,HIGH); digitalWrite(in2,LOW); digitalWrite( in3,HIGH); digitalWrite(in4,LOW);}void reverse { digitalWrite(in1,LOW); digitalWrite(in2,HIGH); digitalWrite(in4,HIGH);}void right { digitalWrite( in1,HIGH); digitalWrite(in2,LOW); digitalWrite(in2,LOW); ; digitalWrite(in4,LOW);}void stop_bot { digitalWrite(in1,LOW); digitalWrite(in3,LOW);

Circuit diagrams

Circuit Diagram-Arduino-ESP8266-Ased-Module-Wi-Fi-Controlled-Robotic-Car

Project video

Related Content

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.