devansh_tangri
Published © GPL3+

Wi-Fi Controlled Bot

This bot implements the addition of ESP8266 for establishing a Wi-Fi communication between the Arduino on the remote side and the bot side.

AdvancedShowcase (no instructions)640
Wi-Fi Controlled Bot

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×2
ESP8266 ESP-01
Espressif ESP8266 ESP-01
×2
DC motor (generic)
×2
Dual H-Bridge motor drivers L298
SparkFun Dual H-Bridge motor drivers L298
×1
Tactile Switch, SPST-NO
Tactile Switch, SPST-NO
×4
Breadboard (generic)
Breadboard (generic)
×1
SparkFun Breadboard Power Supply 5V/3.3V
SparkFun Breadboard Power Supply 5V/3.3V
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

remote_controlled_bot_diagram_QtGucTNZuX.png

Code

Bot : Arduino Code

Arduino
const int i1 = 2;
const int i2 = 3;
const int i3 = 4;
const int i4 = 5;
int i;
void setup() {
  Serial.begin(115200);
  pinMode(i1, OUTPUT);
  pinMode(i2, OUTPUT);
  pinMode(i3, OUTPUT);
  pinMode(i4, OUTPUT);
}

void loop() {
  if(Serial.available()) {
    i = Serial.read();
    Serial.println(i);

    if(i == 115) {
      digitalWrite(i1, HIGH);
      digitalWrite(i2, LOW);
      digitalWrite(i3, LOW);
      digitalWrite(i4, HIGH); 
    }
    else if(i == 119) {
      digitalWrite(i1, LOW);
      digitalWrite(i2, HIGH);
      digitalWrite(i3, HIGH);
      digitalWrite(i4, LOW);      
    }
    else if(i == 100) {
      digitalWrite(i1, HIGH);
      digitalWrite(i2, LOW);
      digitalWrite(i3, HIGH);
      digitalWrite(i4, LOW);
    }
    else if(i == 97) {
      digitalWrite(i1, LOW);
      digitalWrite(i2, HIGH);
      digitalWrite(i3, LOW);
      digitalWrite(i4, HIGH);
    }
  }
  else {
    delay(600);
    i = 0;
    digitalWrite(i1, LOW);
    digitalWrite(i2, LOW);
    digitalWrite(i3, LOW);
    digitalWrite(i4, LOW);
  }
}

Bot : ESP8266 Code

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

#define APSSID "ESP8266"
#define APPSK  "12345678"

const char *apssid = APSSID;
const char *appassword = APPSK;
char c;

WiFiServer server(1234);

void setup() {
  Serial.begin(115200);
  delay(1000);
  WiFi.softAP(apssid, appassword);
  server.begin();
  Serial.println();
}

void loop() {
  WiFiClient client = server.available();
  
  if(client) {
    while(client.connected()) {
      while(client.available() > 0) {
        c = client.read();
        Serial.write(c);
      }
      delay(25);
    }
  }
}

Remote : Arduino Code

Arduino
const int f = A0;
const int l = A1;
const int b = A2;
const int r = 7;

void setup() {
  pinMode(f, INPUT_PULLUP);
  pinMode(b, INPUT_PULLUP);
  pinMode(l, INPUT_PULLUP);
  pinMode(r, INPUT_PULLUP);
  Serial.begin(115200);
}
void loop() {
  delay(500);
  if(digitalRead(f) == 0) {
    Serial.print("w");
  }
  else if(digitalRead(b) == 0) {
    Serial.print("s");
  }
  else if(digitalRead(l) == 0) {
    Serial.print("a");
  }
  else if(digitalRead(r) == 0) {
    Serial.print("d");
  }
}

Remote : ESP8266 Code

Arduino
#include <ESP8266WiFi.h>

#define STASSID "ESP8266"
#define STAPSK  "12345678"

const char* ssid     = STASSID;
const char* password = STAPSK;

const char* host = "192.168.4.1";
const uint16_t port = 1234;
char c;

void setup() {
  Serial.begin(115200);
  Serial.println();
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);

  while(WiFi.status() != WL_CONNECTED) {
    Serial.println("Trying to Connect to ESP8266 Access Point");
    delay(1000);
  }
  Serial.println("Connection Successful");
}

void loop() {
  WiFiClient client;

  if(!client.connect(host, port)) {
    Serial.println("Connection Lost, Trying to establish connection");
    delay(2000);
    return;
  }

  Serial.println("Communication Established");
  while(client.connect(host, port)) {
    if(Serial.available()) {
      c = Serial.read();
      Serial.println(c); 
      client.print(c);
    }
  }

  Serial.println("Connection Lost");
  client.stop();
}

Credits

devansh_tangri

devansh_tangri

2 projects • 9 followers
I'm a 17 yo student, making Arduino Projects and Electrical Circuits is my favorite hobby. I have been making circuits for about 8 years.

Comments