Skip to content

Instantly share code, notes, and snippets.

@Heidi-Negrete
Last active April 8, 2025 15:52
Show Gist options
  • Select an option

  • Save Heidi-Negrete/9d72991c3529a9b60f2bc6d2f6dc4692 to your computer and use it in GitHub Desktop.

Select an option

Save Heidi-Negrete/9d72991c3529a9b60f2bc6d2f6dc4692 to your computer and use it in GitHub Desktop.
v1 Arduino Controller for Unreal Engine 5 - version 1
// Version One (single 3-axis joystick and 2 LEDs + simple communication protocol)
// See the how-to: https://medium.com/@angelicgarbage/build-an-arduino-controller-for-your-unreal-5-game-v1-a9a081fe3990
// Save this file as controller.ino
#define greenLed 4
#define redLed 5
// Joystick Pins
int xPin = A0;
int yPin = A1;
int zButton = 2;
// Joystick Values
int xVal;
int yVal;
int buttonState;
void setup()
{
Serial.begin(115200);
pinMode(greenLed, OUTPUT);
pinMode(redLed, OUTPUT);
// Set pinmodes for Joystick
pinMode(xPin, INPUT);
pinMode(yPin, INPUT);
pinMode(zButton, INPUT_PULLUP);
// Establish contact with Unreal before transmitting data.
establishContact();
}
void loop()
{
// LED is green for transmitting
digitalWrite(greenLed, HIGH);
digitalWrite(redLed, LOW);
// Read Joystick values
xVal = map(analogRead(xPin), 0, 1025, 0, 100);
yVal = map(analogRead(yPin), 0, 1025, 0, 100);
buttonState = digitalRead(zButton);
// Output Joystick X, Y, and Z
Serial.print("D");
Serial.println(xVal);
Serial.print("E");
Serial.println(yVal);
Serial.print("F");
Serial.println(buttonState);
Serial.print("C");
Serial.println(1);
// Wait to full timeStep period
delay(100);
}
// Establish contact with unreal before transmitting data
void establishContact() {
while (Serial.available() <= 0) {
Serial.print('A');
digitalWrite(greenLed, LOW);
digitalWrite(redLed, HIGH);
delay(300);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment