

PinMode (Push_Button, INPUT_PULLUP ) // This will activate pull-up resistor on the push-button pin PinMode ( y_key, INPUT ) // Selecting Arduino analog A1 pin as input

PinMode ( x_key, INPUT ) // Selecting Arduino analog A0 pin as input
MICRO SERVO MOTOR ARDUINO SERIAL
Serial.begin (9600) // initializing serial communications at 9600 bps: Int button_State = 0 // Declaring a variable for storing the value Int y_Position = 0 // Declaring a variable for storing the value Int Horizontal_Position = 0 // Declaring a variable for storing the value Int Push_Button = 2 // initializing digital pin 2 for joystick’s press to select button Int y_key = A1 // initializing A1 for storing the joystick’s y key value int x_key = A0 // initializing A0 for storing the joystick’s x key value Moreover, the switch output will be shown as well. This sketch will display on the serial monitor, the Joystick physical positions in terms of x and y coordinates. Open your Arduino IDE and go to File > New to open a new file. The values of VRX, VRY, and SW changes according to the picture shown below.Īrduino Sketch: Reading analog/digital input from Joystick Module When we press it in the middle position, the SW pin becomes high. When we move it in diagonal direction values of both VRX and VRY vary. When we move this module up or down, the value of VRY varies. When we move joystick module on the left or the right side value of VRX varies. Only these analog pins of Arduino can be used to measure analog signals. They have 5 built-in analogs to digital converter channels. Analog pins in the Arduino board are marked with the letter ‘A’ e.g. This change is measured through the ADC pins of the Arduino board. The resistance of the potentiometer changes as the joystick’s physical position is varied. The position is interpreted as analog values from the Arduino board. They are used to determine the position of the rod. These two mechanisms make it easier to determine the position of the Joystick (right, left, up, and down) using the Arduino board.Įach potentiometer is connected to each of the Joystick’s shafts. The Joystick Module works on the basic principle of two potentiometers and a Gimbal Mechanism.
