I wanted to make a simple example to connect Arduino to Unity. I used serial communication to talk to Unity from Arduino.
Unity version : 2018.3.1f1
In the Arduino side, I connected a touch sensor to Digital pin2 and referenced the code from ‘StatechangeDetection.ino’ in Arduino examples. (Only send a data when it changed) After sending “1”, flush the serial data.
In Unity side, I created a cube and add a c# script called ‘ArduinoSerial.cs’.
In ArduinoSerial.cs script,
- add a line using System.IO.Ports;
- match to Serial port
For using ‘System.IO.Ports’, go to build setting / player setting / configuration tab. In the ‘
In my experience, sometimes it didn’t apply right after changing. Save the scene and reboot the Unity.
There are some Arduino – Unity libraries in the Unity Asset store. but some of them are not free and some are designed for the PC environment. Check the spec before