Using Potentiometer in Unity

I am trying to use a potentiometer to move the z rotation of an object in Unity. I am using an Arduino UNO to do this and have figured out how to have the Arduino read out the position of the potentiometer and have converted the data so that it reads from 0 to 360. I am a beginner so I’m pretty much looking up youtube videos and copying and pasting the code into unity, but I can’t find a tutorial for exactly what I need.

This is the code I’ve used for the Arduino, if someone can help me figure out what code to put into Unity so that it reads and uses to data from my Arduino to change to z rotation of an object it would be much appreciated. :slight_smile:

void setup() {

Serial.begin(9600);
}

void loop() {

int sensorValue = analogRead(A0);

Serial.println(map(sensorValue,0,1023,0,360));
Serial.print(“,”);

delay(1);
}

Hello, this tutorial helped me a lot

That video looks good. The steps are

  1. opening a serial port in Unity.
  2. getting the data in and parsing it—it comes in as ASCII bytes for the numbers, which is strange to deal with at first…it also sends ASCII bytes for the comma and the newline character.
  3. hooking up those values to your object’s rotation.

Steps 1 and 3 are simple, step 2 is less so. But there are plenty of resources on how to parse incoming serial data (whether to Unity or anywhere else). The video covers it well, starting around 12:00. Note that his Arduino output is slightly different than yours, but you can adapt it.