Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
mcharrison500
Published

The Motion Mobile: Gesture-Controlled Car

Have you ever wanted to be able to control a car with your hand? Introducing the Motion Mobile!

BeginnerFull instructions provided6,965
The Motion Mobile: Gesture-Controlled Car

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Arduino Nano R3
Arduino Nano R3
×1
Adafruit 433mhz rf transmitter and receiver
×2
Adafuit Motor shield
×1
GY-521 MPU-6050 3 Axis Gyroscope + Accelerometer Module For Arduino
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1

Hand tools and fabrication machines

Adafruit car chassis

Story

Read more

Schematics

Transmitter glove

receiver (RC Car)

RC car Flowchart

RC car Flowchart

Code

receiver (RC Car)

Arduino
this code is for rc car to receive signals
#include <VirtualWire.h> //VirtualWire library declaration
#include <AFMotor.h>
byte msg[VW_MAX_MESSAGE_LEN];//Data flow is received
byte msgLen = VW_MAX_MESSAGE_LEN;
char forward[1] = {1};

AF_DCMotor motor1(1, MOTOR12_1KHZ);
AF_DCMotor motor2(2, MOTOR12_1KHZ);
AF_DCMotor motor3(3, MOTOR34_1KHZ);
AF_DCMotor motor4(4, MOTOR34_1KHZ);

void setup()
{
  Serial.begin(9600);
  Serial.println("READY..........");
  vw_setup(2048); // set the baud rate
  vw_set_rx_pin(2);// Set up digital pins to receive signals
  vw_rx_start();// started receiving the signal
}


void loop()
{
  if (vw_get_message(msg, &msgLen)) // if the signal is transmitted
  {
    Serial.print("got transmition");
    motor1.setSpeed(255);
    motor2.setSpeed(255);
    motor3.setSpeed(255);
    motor4.setSpeed(255);
    switch (msg[0])
    {
      case '0':
        {
          motor1.run(RELEASE);
          motor2.run(RELEASE);
          motor3.run(RELEASE);
          motor4.run(RELEASE);
          break;
        }

      case '1':
        {
          motor1.run(FORWARD);
          motor2.run(FORWARD);
          motor3.run(FORWARD);
          motor4.run(FORWARD);
          break;
        }

      case '2':
        {
          motor1.setSpeed(150);
          motor2.setSpeed(150);
          motor3.setSpeed(150);
          motor4.setSpeed(150);
          motor1.run(FORWARD);
          motor2.run(FORWARD);
          motor3.run(BACKWARD);
          motor4.run(BACKWARD);
          break;
        }

      case '3':
        {
          motor1.setSpeed(150);
          motor2.setSpeed(150);
          motor3.setSpeed(150);
          motor4.setSpeed(150);
          motor1.run(BACKWARD);
          motor2.run(BACKWARD);
          motor3.run(FORWARD);
          motor4.run(FORWARD);
          break;
        }

      case '4':
        {
          motor1.run(BACKWARD);
          motor2.run(BACKWARD);
          motor3.run(BACKWARD);
          motor4.run(BACKWARD);
          break;
        }

      case '5':
        {
          motor3.setSpeed(70);
          motor4.setSpeed(70);
          motor1.run(FORWARD);
          motor2.run(FORWARD);
          motor3.run(FORWARD);
          motor4.run(FORWARD);
          break;
        }

      case '6':
        {
          motor1.setSpeed(70);
          motor2.setSpeed(70);
          motor1.run(FORWARD);
          motor2.run(FORWARD);
          motor3.run(FORWARD);
          motor4.run(FORWARD);
          break;
        }
    }



}

RCtransmitter (glove)

Arduino
sends signals to rc
#include <VirtualWire.h> // VirtualWire library declaration
#include "I2Cdev.h"
#include "MPU6050.h"

#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
#include "Wire.h"
#endif
MPU6050 accelgyro;
int16_t ax, ay, az;//used for making programs cross platform
int16_t gx, gy, gz;//used for making programs cross platform
//#define OUTPUT_READABLE_ACCELGYRO
#define OUTPUT_BINARY_ACCELGYRO
#define LED_PIN 13
bool blinkState = false;
char text[5] = "";// array array declaration
byte i = 0;

void setup()
{
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE//communicacate between devices
  Wire.begin();
#elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
  Fastwire::setup(400, true);
#endif
  Serial.begin(9600);// Serial communication with baudrate 9600
  accelgyro.initialize();
  Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");
  Serial.println("Ready.........");
  vw_set_ptt_inverted(true);// Requirements for RF link modules
  vw_setup(2048);// set the baud rate
  vw_set_tx_pin(8);// Set up digital pins to signal
  pinMode(LED_PIN, OUTPUT);

}

void loop()
{
  accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
#ifdef OUTPUT_READABLE_ACCELGYRO
  // display tab-separated accel/gyro x/y/z values
  Serial.print("a/g:\t");
  Serial.print(ax); Serial.print("\t");
  Serial.print(ay); Serial.print("\t");
  Serial.print(az); Serial.print("\t");
  Serial.print(gx); Serial.print("\t");
  Serial.print(gy); Serial.print("\t");   //-32000
  Serial.println(gz);
  //delay(250);
#endif

#ifdef OUTPUT_BINARY_ACCELGYRO
  /*  Serial.write((uint8_t)(ax >> 8)); Serial.write((uint8_t)(ax & 0xFF));
    Serial.write((uint8_t)(ay >> 8)); Serial.write((uint8_t)(ay & 0xFF));
    Serial.write((uint8_t)(az >> 8)); Serial.write((uint8_t)(az & 0xFF));
    Serial.write((uint8_t)(gx >> 8)); Serial.write((uint8_t)(gx & 0xFF));
    Serial.write((uint8_t)(gy >> 8)); Serial.write((uint8_t)(gy & 0xFF));
    Serial.write((uint8_t)(gz >> 8)); Serial.write((uint8_t)(gz & 0xFF)); */
#endif


  if ((ay < 9000) and (ay > -9000) and (ax < 12000) and (ax > -3000))
  {
    Serial.println("Ready.........");
    text[i] = '0';
    vw_send((byte *)text, sizeof(text));// send the signal away
    vw_wait_tx();

  }

  if (ax < -3800)
  {
    if (ay < -13000)
    {
      Serial.println("to the right");
      text[i] = '5'; // to the right
      vw_send((byte *)text, sizeof(text));// send the signal away
      vw_wait_tx();
    }
    else if (ay > 8000)
    {
      Serial.println("to the left");
      text[i] = '6'; // to the left
      vw_send((byte *)text, sizeof(text));// send the signal away
      vw_wait_tx();
    }
    else
    {
      Serial.println("to the left"); 
      text[i] = '1'; //tới
      vw_send((byte *)text, sizeof(text));// send the signal away
      vw_wait_tx();
    }
  }

  if (ay < -13000)
  {
    if (ax < -3800)
    {
      Serial.println("to the right");
      text[i] = '5'; // to the right
      vw_send((byte *)text, sizeof(text));// send the signal away
      vw_wait_tx();
    }
    else
    {
      Serial.println("to the right");
      text[i] = '2'; // right
      vw_send((byte *)text, sizeof(text));// send the signal away
      vw_wait_tx();
    }
  }

  if (ay > 7000)
  {
    if (ax < -3800)
    {
      Serial.println("to the left");
      text[i] = '6'; // to the left
      vw_send((byte *)text, sizeof(text));// send the signal away
      vw_wait_tx();
    }
    else
    {
      Serial.println("to the left");
      text[i] = '3'; //  to the left
      vw_send((byte *)text, sizeof(text));// send the signal away
      vw_wait_tx();
    }
  }

  if (ax > 14000)
  {
    text[i] = '4'; //backward
    vw_send((byte *)text, sizeof(text));// send the signal away
    vw_wait_tx();
  }



  blinkState = !blinkState;
  digitalWrite(LED_PIN, blinkState);

}

Credits

mcharrison500
1 project • 8 followers
Ambitious 4th year student of BEng (Hons) Software & Electronic Engineering at Galway-Mayo Institute of Technology (GMIT).

Comments