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.

  • 1,867 views
  • 0 comments
  • 10 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

  • 82,670 views
  • 106 comments
  • 133 respects

WIZnet S2E Deadbolts

Project tutorial by Team S2E Lock

  • 2,775 views
  • 2 comments
  • 9 respects

Door Knock Notifier

by Random Science Stuff

  • 2,650 views
  • 1 comment
  • 14 respects

A UV Measurer for Umbrellas

Project showcase by Team NTPC Young Maker Studio

  • 1,062 views
  • 1 comment
  • 7 respects

Windows Remote Arduino

Project tutorial by Team Windows IoT

  • 166,222 views
  • 167 comments
  • 339 respects

Home Smart Home

Project tutorial by Syed Sanoor

  • 68,551 views
  • 10 comments
  • 193 respects
Add projectSign up / Login