Sikkandar Sulaiman
Published © GPL3+

Robot Movement by Hand Gesture

Move your robot, with 5 controls for direction and stop, by waving your hand in range of WiFi.

IntermediateFull instructions provided3 hours1,967
Robot Movement by Hand Gesture

Things used in this project

Hardware components

ESP8266 ESP-01
Espressif ESP8266 ESP-01
×1
Adafruit ADXL345
×1
Raspberry Pi 1 Model B
Raspberry Pi 1 Model B
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Modulo Motor Driver
Modulo Motor Driver
×1
DC motor (generic)
×2
1N4007 – High Voltage, High Current Rated Diode
1N4007 – High Voltage, High Current Rated Diode
×2

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Custom parts and enclosures

Handshield

A wearable which has ESP8266, Accelerometer and a Battery.

The robot

A movable robot which is connected to ESP8266 in hand with WiFi by either with another ESP8266 or a Raspberry Pi

Code

ESP Handshield

Arduino
Just upload it to ESP8266 and connect ADXL345 to ESP.
Remember first run the node.js code on RaspberryPi and then power up ESP8266
#include <Wire.h>
#include <ADXL345.h>
#include <ESP8266WiFi.h>

const char* ssid     = "ESP8266";
const char* password = "secretPassword";	
const char* host     = "raspberrypi";	//Change to the name of your raspberrypi
const int httpPort   = 8000;

ADXL345 acc;
WiFiClient client;
int x,y,z; 
String url, prevUrl="", tri, tempTri, prevTri="";

void setup() {
  Serial.begin(115200);
  WiFi.softAPConfig({192,168,1,1},{192,168,1,1},{255,255,255,0});
  WiFi.softAP(ssid, password);
  delay(5000); //Give required time for the robot device to connect to ESP8266
  acc.powerOn();
}

void loop() {

  if(client.status()==0)
    while (!client.connect(host, httpPort)) {
      delay(500);
      //Serial.print(".");
    }
  
  acc.readAccel(&x,&y,&z);
  x-=17; y-=6; z+=16;
  tri = "";
  tri += set(x);
  tri += set(y);
  tri += set(z);

  if(tri != prevTri){
    tempTri = tri;
    delay(500);
    
    
    if(tempTri == tri){
      if(tri == "00-1")
        url = "/move";
      else if(tri == "001")
        url = "/back";
      else if(tri == "100")
        url = "/left";
      else if(tri == "-100")
        url = "/rite";
      else if(tri == "0-10")
        url = "/halt";
        if(url != prevUrl){
            client.print(String("GET ") + url + " HTTP/1.1\r\n" +
                     "Host: " + host + "\r\n" + 
                     "Connection: close\r\n\r\n");
            delay(10);
            Serial.println(url);
            Serial.println(tri);
			//If the client (raspberry pi) needs to convey anything
            while(client.available()){
              String line = client.readStringUntil('\r');
              Serial.print(line);
            }
        }
        prevUrl = url;
    }

    
  }
  prevTri = tri;
  
  /*Serial.print(x);
  Serial.print("\t");
  Serial.print(y);
  Serial.print("\t");
  Serial.println(z);*/
  //Serial.println(tri);
  delay(50);
}


int set(int k) {
  float K = k/256.0;
  K = K>200 ? -1-(255-K) : K;
  if(K>0.33)
    return 1;
  else if(K<-0.33)
    return -1;
  else
    return 0;
}

Raspberry Pi robot

JavaScript
Put it anywhere in your Raspberry Pi and run it before switching ON your ESP8266
var express = require('../express'), // Replace dots with full path where
    gpio = require('../rpi-gpio');  // you've installed those modules
var exp = express();

gpio.setMode(gpio.MODE_BCM);
gpio.setup(17, gpio.DIR_OUT);
gpio.setup(18, gpio.DIR_OUT);
gpio.setup(22, gpio.DIR_OUT);
gpio.setup(23, gpio.DIR_OUT);

exp.get('/halt', set(0,0,0,0));
exp.get('/move', set(1,0,0,1));
exp.get('/back', set(0,1,1,0));
exp.get('/left', set(1,0,0,0));
exp.get('/rite', set(0,0,0,1));

function set(set17, set18, set22, set23){
  gpio.write(17, set17);
  gpio.write(18, set18);
  gpio.write(22, set22);
  gpio.write(23, set23);
}

exp.listen(8000);

Credits

Sikkandar Sulaiman

Sikkandar Sulaiman

5 projects • 25 followers
Engineering student actively working with IoT, Image Processing and Robotics.

Comments