Using Unity to Make and Run UI to Arduino

Using Unity to Make and Run UI to Arduino © CC0

Just drag and drop prefabs to make a PC user interface to Arduino, without coding in PC.

  • 3,238 views
  • 0 comments
  • 13 respects

Components and supplies

Apps and online services

About this project

In this simple example, we press a button in Unity repeatedly. Then Arduino turns on and off the built-in LED and also changes the button text and color.

Unity windows will looks like above, if you import MiniLab unity package. There are 8 Controls (UI parts) as prefabs in Assets folder. Here a Push button Control is dragged from there into the scene. The corresponding Arduino code is as shown above.

The overall codes were generated by a menu in the Inspector when Bench selected in the hierarchy window. In the MiniLab's Inspector we set Baud Rate and Port (COM) number.

Press the Play button in Unity, and click the Push button repeatedly. You will see the button text change between "Hello" and "World", with button color changes. You will also hear system sounds.

Code

HelloArduino
communicates with a button in MiniLab: receives the start message and button-clicks, and send texts, colors and sounds.
#include <MiniLab.h>
String title = "Hello";

Push push(1);

void setup () {

  Serial.begin(9600);
  pinMode(13, OUTPUT);
}

void loop () {

  delay(100);

  if (Serial.available() == 0) return;
  int id = MiniLab.readInt();
  if (id == MiniLab.id_start) {
    if (!MiniLab.checkTitle(title)) return;

    return;
  }
  if (id == push.id) {

    int state = !digitalRead(13);
    digitalWrite(13, state);

    push.print(state ? "Hello" : "World");
    push.set(state ? yellow : cyan);
    MiniLab.beepSound();
    MiniLab.log("log() is useful for simple display or debugging");
  }
}

Comments

Similar projects you might like

DHT11 /DHT22 Temperature Sensor

Project tutorial by Daniel Porrey

  • 100,055 views
  • 107 comments
  • 147 respects

Getting started with IMU (6 DOF) motion sensor

Project tutorial by Aritro Mukherjee

  • 95,433 views
  • 19 comments
  • 63 respects

Door Knock Notifier

by Random Science Stuff

  • 3,851 views
  • 1 comment
  • 14 respects
Add projectSign up / Login