No products in the cart.
Joy Stick

14
Jul
Joy Stick Sensor
Ever wonder how the joystick sensor in a controller works? Well, essentially it’s 2 variable resistors (potentiometers) with springs that keep them centered. This means that we can set them up as voltage dividers and read there positions via an analog input with the Arduino.
Overview:
This is a very simple tutorial on how to hook up a joystick for the Arduino
Components:
1X Arduino Compatible Board
1X Female – Male Jumper Cables
1X Joystick
The Joystick is what I like to call a “compound device” because it has multiple signals on a single device. It can read a X positions (up/down) Y position (side to side) and a button. The position sensors are potentiometer are set up the exact same way. The button is slightly trickier but can easily be handled using an internal pull up resister
Code:
We will be ultilizing very basic functions such as digitalWrite, digitalRead, and analogRead
//Defines the 3 device inputs button, Y Axis, X Axis # define button 8 # define posX A0 # define posY A1 void setup() { pinMode(button,INPUT); //button will read as an input digitalWrite(button,HIGH); //ultilizes the arduino internal //pull up resister pinMode(posX,INPUT); //X axis as an input pinMode(posY,INPUT); //Y axis as an input Serial.begin(9600); //set up serial Com } void loop() { int ibutton = digitalRead(button);//stores button state int iposX = analogRead(posX);//stores X position int iposY = analogRead(posY);//stores Y position Serial.print("button is "); if(ibutton){ //check to see if button is high or low prints appropriately Serial.println("ON"); }else{ Serial.println("OFF"); } Serial.print("X posisition is "); Serial.println(iposX); //prints X position Serial.print("Y posisition is "); Serial.println(iposY); //prints Y position Serial.println(""); delay(500);//delay so that the results are readable }