Project tutorial
DIY Virtual Reality Skateboard

DIY Virtual Reality Skateboard © CC BY-NC-SA

An accelerometer/gyro goes onto an Arduino board and transmits the angular motion of the board via bluetooth to a virtual reality app.

  • 4,340 views
  • 7 comments
  • 18 respects

Components and supplies

Apps and online services

About this project

This is a really fun and easy project that can be done in about an hour. On the bottom of the skateboard is an accelerometer/gyro with an Arduino board that transmits the angular motion of the board via Bluetooth to a little VR game I made in Unity for Android phones. So, when you turn on your Arduino and the bluetooth connects with your phone, you start moving forward. Lean left and you go left, lean right and you go right. Lift up the front wheels and your character will jump. This only works for Android phones and your phone must be compatible with Google Cardboard. So, if you have an old skateboard laying around, turn it into a virtual reality snowboard. Here's how:

You will need:

A Google Cardboard style virtual reality headset.

A skateboard.

4 tennis balls (to keep from rolling away)

An Arduino Leonardo (or Uno)

Some jumper wires

A mini breadboard

An HC-06 Bluetooth module

An MPU-6050 accelerometer/gyro

A 9V battery with battery box that has a on/off switch and a barrel plug (to power the Arduino board)

A soldering iron and maybe a hot glue gun

The Android app, Arduino code, and parts list with links can be found here:

http://wirebeings.com/virtual-reality-skateboard.html

Step 1: Create your Arduino Device/Transmitter/Input/Thing

Assemble your device as shown in the picture above.

You will need to solder the header pins onto the MPU-6050, if your soldering iron is new and the tip is clean this can be done in about 11 seconds. If your soldering iron tip is dirty and old this will quickly become the hardest thing you have ever done (speaking from experience).

Make sure the orientation of everything is exactly as shown in the pictures above so you do not have to get into the code and edit anything.

Attach everything to you skateboard EXACTLY as shown (really just make sure the MPU6050 is facing the same direction as the picture)

Here I glued the battery box to the board with hot glue and screwed the Arduino board down. I used an old school board because a wider board is better for the purposes of this experience. It is pretty hard to balance on a board while in virtual reality.

NOTE: The Leonardo works much better for this...however...

If you are using an Arduino Uno all the connections are the same except:

SDA goes to A4 and SCL goes to A5

Step 2: Upload the Arduino code to your Device / Transmitter / Input Thing

IMPORTANT: Unplug the RX and TX pins before uploading the code to your board. 

Step 3: Almost done! Download App to your Phone!

Follow this link and download the app to your phone.

Google Cardboard Virtual Reality Skateboard/Snowboard App

You will need to go into your security settings and allow apps to be installed from unknown developers.

Make sure to pair the Bluetooth module to your phone, do not change the default name (HC-06). The password should be 1234. 

Notes:

This is my first Unity Game...so it's pretty basic.

If enough people make this I can try to make a better snowboard game, or make an actual skateboard game depending on what I get requests for.

When your turn on your Arduino device make sure the skateboard is flat on the ground and then open the app. As soon as the Bluetooth connects you will drop in.

If the Bluetooth becomes disconnected, restart the app (it is set to connect at the start of the app only, for right now).

Code

Arduino CodeArduino
#include "I2Cdev.h"
#include "MPU6050_6Axis_MotionApps20.h"
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
    #include "Wire.h"
#endif

MPU6050 mpu;


bool dmpReady = false;  
uint8_t mpuIntStatus;   
uint8_t devStatus;     
uint16_t packetSize;    
uint16_t fifoCount;     
uint8_t fifoBuffer[64]; 


Quaternion q;           
VectorInt16 aa;        
VectorInt16 aaReal;     
VectorInt16 aaWorld;    
VectorFloat gravity;    
float euler[3];         
float ypr[3];           
volatile bool mpuInterrupt = false;   

void setup() 
{
    #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
        Wire.begin();
        TWBR = 24; 
    #elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
        Fastwire::setup(400, true);
    #endif

    Serial.begin(9600);  //For use with Arduino Uno
    Serial1.begin(9600); //For use with Leonardo

    Serial.println(F("Initializing I2C devices..."));
    mpu.initialize();

    Serial.println(F("Testing device connections..."));
    Serial.println(mpu.testConnection() ? F("MPU6050 connection successful") : F("MPU6050 connection failed"));
    Serial.println(F("Initializing DMP..."));
    devStatus = mpu.dmpInitialize();

    mpu.setXGyroOffset(220);
    mpu.setYGyroOffset(76);
    mpu.setZGyroOffset(-85);
    mpu.setZAccelOffset(1788); 
    if (devStatus == 0) {
        Serial.println(F("Enabling DMP..."));
        mpu.setDMPEnabled(true);
        Serial.println(F("Enabling interrupt detection (Arduino external interrupt 0)..."));
        attachInterrupt(0, dmpDataReady, RISING);
        mpuIntStatus = mpu.getIntStatus();
        Serial.println(F("DMP ready! Waiting for first interrupt..."));
        dmpReady = true;
        packetSize = mpu.dmpGetFIFOPacketSize();
    } else {
        Serial.print(F("DMP Initialization failed (code "));
        Serial.print(devStatus);
        Serial.println(F(")"));
    }
   
}

void sendData(int x, int y, int z)
{
  
    if(z < -10){   
      //forward
      Serial1.write("f"); // Write to Leonardo
      Serial1.write(10);  //Stop Bit
      Serial.write("f");  // Write to Uno
      Serial.write(10);   //Stop bit
    } else if (z > 0){
      //backward
      Serial1.write("b");
      Serial1.write(10);
      Serial.write("b");
      Serial.write(10);
    } else if (y > 5){   //To make more sensitive change value to 4 or less
      //right
      Serial1.write("r");
      Serial1.write(10);
      Serial.write("r");
      Serial.write(10);
    } else if (y < -5){  //To make more sensitive change to -4 or greater 
      //left
      Serial1.write("l");
      Serial1.write(10);
      Serial.write("l");
      Serial.write(10);
    } else
      //stop
      Serial1.write("s");
      Serial1.write(10);
      Serial.write("s");
      Serial.write(10);
         
}

void loop() 
{
  
    if (!dmpReady) return;
    mpuInterrupt = false;
    mpuIntStatus = mpu.getIntStatus();
    fifoCount = mpu.getFIFOCount();
    if ((mpuIntStatus & 0x10) || fifoCount == 1024) {
        mpu.resetFIFO();
        Serial.println(F("FIFO Overflow"));

    } else if (mpuIntStatus & 0x02) {
        while (fifoCount < packetSize) {
          fifoCount = mpu.getFIFOCount();
        }
        mpu.getFIFOBytes(fifoBuffer, packetSize);        
        fifoCount -= packetSize;
        mpu.dmpGetQuaternion(&q, fifoBuffer);
        mpu.dmpGetGravity(&gravity, &q);
        mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);
        sendData(ypr[0] * 180/M_PI, ypr[1] * 180/M_PI, ypr[2] * 180/M_PI);
    }
}

void dmpDataReady() 
{
    mpuInterrupt = true;
}

Schematics

Connections
Vrconnections

Comments

Similar projects you might like

Hack Skateboard for Virtual Reality with Arduino

Project showcase by Matthew Hallberg

  • 5,142 views
  • 2 comments
  • 26 respects

Let it Snow - IoT Snow Globe With Virtual Reality Web

Project tutorial by Team Virtual Ecology

  • 5,679 views
  • 2 comments
  • 42 respects

DIY Safe using Pattern lock Shield

Project showcase by Mahmoud Ahmed

  • 2,254 views
  • 0 comments
  • 15 respects

4x4x4 LED cube with Arduino Uno and 1sheeld

Project tutorial by Hassan Ibrahim

  • 35,140 views
  • 7 comments
  • 64 respects

Custom LED Lights on DIY Electric Skateboard - Raspberry Pi

Project tutorial by Matt Timmons-Brown

  • 3,907 views
  • 2 comments
  • 14 respects
Add projectSign up / Login