Introduction: DIY Virtual Reality Skateboard Experience With Arduino and Google Cardboard

Picture of DIY Virtual Reality Skateboard Experience With Arduino and Google Cardboard

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 virtual reality game I made 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.h...

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

Picture of 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.

However, the SDA could go to A4 and SCL could go to to A5.

Step 2: Upload This Code to Your Device/transmitter/input Thing

Picture of Upload This Code to Your Device/transmitter/input Thing

IMPORTANT: Unplug the RX and TX pins and upload this code to your board.

#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;
}

Step 3: Almost Done! Download App to Your Phone!

Picture of 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.

Before your bluetooth module will connect to the game you must pair it with your phone. Do not change the name of the module when you pair it or this won't work. The name should be HC-06 from the factory and the default password is 1234.

Notes:

This is my first Unity Game...It is terrible.

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).

Comments

abnavepushpak (author)2017-09-03

Will it work with a google cardboard??

AnandK66 (author)2016-05-14

awesome project! I'm gonna try this for my IIT (Indian Institute of Technology) presentation this year(if you check my profile it says i'm 13 years old(it's true!) but me and my friend probably know about as much code as you guys!)Could you send me the code for a CPR training version! (By the way, I moved to India from America, so are all the parts you mentioned internationally available?)Thanks!

markroxor (author)AnandK662017-01-09

Dude you're funny.

angeltea4 (author)2016-11-18

Can we use Arduino UNO instead of arduino micro by using software i2c?

yashrajs1 (author)2016-11-16

I have the application. I have connected it and the light blinks every 2 seconds. But the character is not moving at all. He is stuck in the air. Please help me. He is also not progressing forward.

bbogle (author)2016-08-26

I have set all the devices and run the application.

But, how can I start?

bbogle (author)bbogle2016-08-26

I download the android App.

Bluetooth communication of App is available?

javierv1 (author)2016-05-10

Really nice project, What unity asset or plugin are you using in your unity app?

ILKER06 (author)2016-04-25

i need to unity project codes pls help me :(

SpykeK (author)2016-03-19

Matt, really cool project! I teach at Pennsylvania College of Technology in our Gaming & Simulation program. Any chance you would share the Unity project so we can look at it in class?

One way or another, I plan on hooking this up with my endo board in the next week or so!

Thanks in advance!

matthewh8 (author)SpykeK2016-03-19

Thanks so much! I just can't share the Unity project because it uses a paid plugin. However to replicate your own experience its really easy, you need the google cardboard plugin, the android for microcontrollers ($20), and first person character controller. Then you have to just make the character controller move manually based on the bluetooth inputs in the character controller C# code. If you run in to any trouble let me know.

SpykeK (author)matthewh82016-03-24

So, I have yet another question. I got my arduino and everything hooked up. The bluetooth seems to be connecting to phones/tablets properly, but I am not getting any feedback from my accelerometer. When I start the game and bluetooth is connected, the board drops down but doesn't move at all. How is the game supposed to start? Thanks again!

matthewh8 (author)SpykeK2016-03-24

I would plug in the input device to the computer via usb, unplug the bluetooth module, and open up the serial monitor at 9600 baud in the Arduino IDE. With the board standing still you should see 's' or 'f' being written to the monitor continuously. If that isn't working your character is not going to move, so I would check all the connections from the IMU, and make sure all the solder connections are good. Also, I think the red light on the IMU should be solid when you turn on the device, if the connections are all good. Keep me posted.

SpykeK (author)matthewh82016-03-23

Matt, thanks for getting back to me so quickly. I will be purchasing the plugin soon so that I can play with it on my own. In the meantime, would you be able to build an iOS version for me? Thanks in advance.

matthewh8 (author)SpykeK2016-03-24

I would but the plugin only works with Android. I have an iphone too but I bought a cheap Android phone on ebay to experiment with making apps and playing with VR.

Gorilla22 (author)2016-03-15

So cool! I wish i could build it... :(

Dayal (author)2016-03-11

Hi Mathew , Great Project , Please share the APP code , i am starting to learn coding for android.

Thank you

Dayal

BenjaminJ9 (author)2016-03-08

Very cool. Take my vote!

matthewh8 (author)BenjaminJ92016-03-10

Thanks!

Gelstronic (author)2016-03-07

Hi,

very impressive project !

i've got problems with the unity demo using my google cardboard. I never had problems with the cardboard demos but now the splitscreen won't fit with the glasses and i get no fullscreen(2xhalfscreen). Maybe the screen layout is not compatible to google cardboard ?!

Help appreciated

matthewh8 (author)Gelstronic2016-03-07

It hope it is lol! I tested it on two different Android phones before I made this. The only thing I could think to try is hit the wrench thing and hit switch viewer while in the app, and try scanning your QR code again for whatever viewer you have.

Gelstronic (author)matthewh82016-03-07

i use several qr-codes now, no success, hmmmmm....

by the way, the arduino code and bluetooth connection works fine !

matthewh8 (author)Gelstronic2016-03-07

Thanks! Wait, I think I misunderstood, do you want one that is full screen (no split screen)? If so, I can build one really quick and send it to you, it only takes like 30 seconds. Let me know.

Gelstronic (author)matthewh82016-03-08

No you don't misunderstood, i need the splitscreen view for my google cardboard. Have a look at the pictures. Do you see what i mean ? The snowboard is not centered enough. First pic too much right, second pic too much left. Maybe the specs of you VR-Box are much different from Google Cardboard. Are there any options for google cardboard when you build the app ?

aperepel (author)2016-03-07

Matt, great project, congrats. One note - on Arduino UNO R3 the SCL/SDA pins are also duplicated next to AREF, so it's the same as in your picture. The A4/A5 are hardwired to those, just now checked with a multimeter.

I understand this was a regular Bluetooth connection, not the BLE?

matthewh8 (author)aperepel2016-03-07

Good catch I had no idea, I will change that right now.

rockon47 (author)2016-03-05

awesome project..
ill soon try to make one

About This Instructable

7,915views

21favorites

License:

Bio: My name is Matthew and I attend the University of Pittsburgh. Currently I am a senior, going for a bachelors in Information Science with a ... More »
More by matthewh8:Apple ArKit Augmented Reality AppAugmented Reality Fidget SpinnerFacial Recognition With Tracking.js
Add instructable to: