DEV Community

Cover image for Arduino Giga R1 WiFi Joystick
Arduino ESP32 Raspberry Pi Tutorials
Arduino ESP32 Raspberry Pi Tutorials

Posted on Originally published at newbiely.com

Arduino Giga R1 WiFi Joystick

An analog joystick gives you two-axis position plus a button, which makes it a nice way to add directional control or servo positioning to a project without writing your own input logic. This tutorial covers wiring it up to the Arduino Giga R1 WiFi, how the dual-potentiometer design produces readable voltages, and how to turn those readings into usable coordinates in code.

The full tutorial, with every detail and the line-by-line code explanation, is on our site: Arduino Giga R1 WiFi Joystick

What you need

Wiring

Arduino Giga R1 WiFi Joystick wiring diagram

Connect GND to Arduino ground and VCC to the Arduino 5V output. VRX and VRY are the X and Y analog outputs, each going to one of the analog input pins (A0-A7). SW, the pushbutton output, goes to a digital GPIO pin configured with its internal pull-up resistor, since the switch is normally-open and pulls the pin to ground when pressed.

Double-check that VCC and GND aren't swapped, since reversed power can damage the internal circuits. Also avoid sharing analog pins between VRX and VRY, as that causes crosstalk, and don't forget the pull-up on SW or the pin will float.

How it works

Each axis is a 10kΩ potentiometer wired as a voltage divider. Moving the stick slides the wiper along the resistive element, so the output voltage swings from near 0V at one mechanical limit to near 5V at the other. The Arduino's ADC turns that into a digital value, roughly 0 to 1023 in 10-bit mode, with the center resting around 511.

Code

The core of the sketch is just two analogRead() calls, one for the X-axis pin and one for the Y-axis pin, each returning a value from 0 to 1023 that represents the stick's position on that axis. From there you can map those raw readings into directional commands, servo angles, or polar coordinates depending on what you're controlling.

arduino-giga-r1-wifi-joystick.ino

/*
 * This Arduino Giga R1 WiFi code was developed by newbiely.com
 *
 * This Arduino Giga R1 WiFi code is made available for public use without any restriction
 *
 * For comprehensive instructions and wiring diagrams, please visit:
 * https://newbiely.com/tutorials/arduino-giga/arduino-giga-r1-wifi-joystick
 */

#define VRX_PIN  A1 // The Arduino Giga R1 WiFi pin connected to VRX pin
#define VRY_PIN  A0 // The Arduino Giga R1 WiFi pin connected to VRY pin

int xValue = 0; // To store value of the X axis
int yValue = 0; // To store value of the Y axis

void setup() {
  Serial.begin(9600) ;
}

void loop() {
  // read analog X and Y analog values
  xValue = analogRead(VRX_PIN);
  yValue = analogRead(VRY_PIN);

  // print data to Serial Monitor on Arduino IDE
  Serial.print("x = ");
  Serial.print(xValue);
  Serial.print(", y = ");
  Serial.println(yValue);
  delay(200);
}
Enter fullscreen mode Exit fullscreen mode

Things that go wrong

If readings seem stuck or erratic, check for reversed VCC/GND wiring or a shared analog pin between the two axes. A floating or unreliable button state usually means the pull-up isn't configured on the SW pin. Since axis polarity depends on how the module is assembled, test which direction increases or decreases each reading before writing control logic, rather than assuming up/down or left/right mapping.

Full tutorial

The complete tutorial - wiring diagram, code explanation and troubleshooting - is here: https://newbiely.com/tutorials/arduino-giga/arduino-giga-r1-wifi-joystick

Top comments (0)