Most of the project requires input or output methods. The output method (to display LEDs) has been covered in this tutorial. We are now going to see how we can get an analog value from a component to interact with Unity.

For this example, we will connect a potentiometer to the arduino board, following the example available on Arduino website.


Upload the default Uduino sketch on your board and connect the component to an analog pin following the documentation. In our case, we connect it this way.

If you want to connect other components, don't forget that reading an analog value from can only be done on the analog pins of the board.


To be sure that the potentiometer is connected, in the edit mode try to discover the board and select the analog port and setup the mode "Analog.” If you click on the read button, the value will be returned.
Now that you're sure that it's connected and working, you can read it by code.

Warning: This example is using the old Uduino 1.4 API. [Updated to 2.0 , Feb 20th] This example will be updated in the next couple of days, in the meantime, please refer to the examples provided with the package.

   void Start ()
        UduinoManager.Instance.InitPin(AnalogPin.A2, PinMode.Analog); //Pin mode in analog to enable reading

    void Update ()
       int  readValue = UduinoManager.Instance.analogRead(AnalogPin.A2);

Example: Uduino\Examples\Basic\AnalogRead