The ArduSensor Plugin is a Unity plugin that receives sensor values from an Arduino board that communicates serially with Android. It supports various sensors such as temperature, humidity, barometric pressure, gas resistance, altitude, CO2, TVOC, and Lux, as well as IMU sensors. The plugin is implemented using Android native code and calls are made from Unity. The sensor values are updated at different intervals, with IMU values updated every 0.1 seconds and other sensors updated every 4 seconds.
To use the plugin, import the package and build the demo scene to verify the AAR plugin is being imported correctly. If not, refer to Unity's official documentation for proper import procedures. The implementation details are written in the UnityProject/Assets/Scripts/AarBridge.cs file. Create a Java instance to communicate with Arduino through Android's Native Methods.
Note that this plugin only works when built for the Android platform and requires Android SDK 29 or higher.
The plugin includes code for implementing USB serial communication in Android, which is contained in the aar plugin. The aar plugin includes a library and Android Activity for USB serial connection, which opens the port, retrieves the vendor ID and device ID of the sensor connected to the Arduino, receives sensor data, and transmits the measured sensor data to Unity.
In Unity, the measured values from the Arduino sensor are displayed using corresponding C# scripts that implement the methods in the aar plugin. Android Java Object and Android Java Instance are used, and the implementation of the UI connected to this C# script is also included. It can be customized by assigning to button events.
The asset uses some elements of [usb-serial-for-android.aar], under the MIT License. Please see the Third-Party Notices.txt file in the package for more details.





