Lost in Space

Project Hybrid: Lost in Space, with HTC VIVE and Arduino
  • Date:
  • Language:
    C#, Arduino Language
  • Software:
    Unity, VisualStudio, Arduino IDE
  • Platform:
  • Tags:
    Game Development, Arduino, Unity

The LOST IN SPACE project was created for the purpose of creating an experience in which a user could fly (EVA) aimlessly around in space. To create this experience, we used the HTC Vive and a custom built chair with custom controls. That way, we wanted te create the most immersive experience we could possibly get.

We tried to create feelings of true despair and anxiety by recreating a disastrous scene in which you are an astronaut who has to fix something on the outside of his spacecraft while in space. Once the player is busy mending the broken part on the outside, something goes terribly wrong and the player get's launched off in to empty space caused by an explosion. Whilst the player is slowly drifting away from the spacecraft, he tries to get back to it.

Slowly it becomes clear that it is a lost cause and that the player will slowly die. Alone in space.


We used Unity for this project with C#.

The biggest challenge in this project was getting the Arduino to work with Unity simply because this was the first time I attempted this.

The class below I wrote to auto detect the arduino at the correct COM port. It also get's the input from the input streams and translates it to usable information. It may not be the prettiest class, but back then when I made it, it sufficed

using UnityEngine;
using System.Collections.Generic;
using System.IO.Ports;
using Microsoft.Win32;

public class ArduinoConnector : MonoBehaviour {

    private Vector2 inputRight;
    private Vector2 inputLeft;
    SerialPort serialPort;
    public bool hasInput;
    void Start() {

        serialPort = new SerialPort(AutodetectArduinoPort(), 9600);

        if (serialPort != null) {
            if (serialPort.IsOpen) {
                serialPort.ReadTimeout = 1;
        } else {
            Debug.LogError("COM PORT NOT FOUND");

    public Vector2 GetLeftInput() {
        try {
            string value = serialPort.ReadLine(); //Read the information
            string[] vec3 = value.Split(',');
            inputLeft.x = int.Parse(vec3[1]);
            inputLeft.y = int.Parse(vec3[0]);

            hasInput = true;
        } catch (System.Exception e) {
        return inputLeft;

    public Vector2 GetRightInput() {
        try {
            string value = serialPort.ReadLine(); //Read the information

            string[] vec3 = value.Split(',');
            inputRight.x = int.Parse(vec3[2]);
            inputRight.y = int.Parse(vec3[3]);
            hasInput = true;
        } catch (System.Exception e) {
        return inputRight;

    public static string AutodetectArduinoPort() {
        List<string> comports = new List<string>();
        RegistryKey rk1 = Registry.LocalMachine;
        RegistryKey rk2 = rk1.OpenSubKey("SYSTEM\\CurrentControlSet\\Enum");
        string temp;
        foreach (string s3 in rk2.GetSubKeyNames()) {
            RegistryKey rk3 = rk2.OpenSubKey(s3);
            foreach (string s in rk3.GetSubKeyNames()) {
                if (s.Contains("VID") && s.Contains("PID")) {
                    RegistryKey rk4 = rk3.OpenSubKey(s);
                    foreach (string s2 in rk4.GetSubKeyNames()) {
                        RegistryKey rk5 = rk4.OpenSubKey(s2);
                        if ((temp = (string)rk5.GetValue("FriendlyName")) != null && temp.Contains("Arduino")) {
                            RegistryKey rk6 = rk5.OpenSubKey("Device Parameters");
                            if (rk6 != null && (temp = (string)rk6.GetValue("PortName")) != null) {
        if (comports.Count > 0) {
            foreach (string s in SerialPort.GetPortNames()) {
                if (comports.Contains(s)) {
                    return s;
        return "COM1";

This website uses cookies to ensure you get the best experience on my website