# How to control x and y axis with accelerometer

I am trying to use arduino uno and an accelerometer to control the x and y axis of a flat plane. I have the x axis working but when I try to do the same for the y axis, it uses the same serial for both axes. Is there an easier way to do this?

Personally, I would set Arduino to output the data in this way:

``````Serial.print(analogRead(xpin));
Serial.print(",");
Serial.print(",");

delay(100);
``````

This should create an output like XXXX,YYYY,ZZZZ

Then create a function to split it into individual values and convert to floats, like so:

Finally, connect the output of your ReadSerial node to this function and you end up with separate float values for each axis in a single go.

Okay now it is able to read each value perfectly! For some reason when the output from the vector is put into the SetWorldRotation, it only reads the one value. I don’t know if this is the right conversion node or not. to alt text By default it uses RotationFromXVector for conversion, which is not what you want in this case.

Simplest solutions would be to replace the MakeVector node with MakeRotator or right-click on the New Rotation pin and select Split Struct Pin, like so: Then connect the float outputs (green wires) into corresponding axes.

For future, if you want to convert Vector to Rotator you can use one of those methods:

Ah okay, I used the make rotator method and it works perfectly. My last problem is with arduino itself but I’m trying to figure out a way to fix it in Unreal. Basically I changed the code a bit to produce the serial as degrees but now each axis will jump from 0 to 35/-35 degrees. Is there any way to fill in the gap of rotation in unreal, or is this just a arduino code problem? Not really an Unreal problem, but:

• x_offset is incorrect - you want (min+max)/2 = 508, not 536
• x_range is also incorrect - should be 153
• check y_offset and y_range as well
• use range variables inside constrain functions

Assuming the range -153 to +153 corresponds to -180 deg to +180 deg, you just need to do a simple mapping of values, like so:

``````x = analogRead(xpin);