loading

A joystick is an input device consisting of a stick that pivots on a base and reports its angle or direction to the device it is controlling.

Joysticks are often used whith Arduino to control robots.

Step 1: Step 1:You Will Need

  • Jumper wire
  • Joystick Module
  • 4 resistor 220hom
  • Arduino UNO
  • 4 leds

Watch the video tutorial

Step 2: Step 2: Connect Joystick Module to an Arduino Uno

Joistic Module----Arduino

wire yellow y--------pin A0

wire brown x--------pin A1

wire wite bt----------pin 8

wire red vcc---------5v

wire black gnd------gnd

Step 3: Step 3: Connect Led to Arduino

Step 4: Step 4:THE CODE

int UD = 0;

int LR = 0;

/* Arduino Micro output pins*/

int DWN = 13;

int UP = 12;

int LEFT = 11;

int RT = 10;

/*Arduino Micro Input Pins */

int IUP=A0;

int ILR=A1;

int MID = 10; // 10 mid point delta arduino, use 4 for attiny

int LRMID = 0;

int UPMID = 0;

void setup(){

pinMode(DWN, OUTPUT);

pinMode(UP, OUTPUT);

pinMode(LEFT, OUTPUT);

pinMode(RT, OUTPUT);

digitalWrite(DWN, HIGH);

digitalWrite(UP, HIGH);

digitalWrite(LEFT, HIGH);

digitalWrite(RT, HIGH);

//calabrate center

LRMID = analogRead(ILR);

UPMID = analogRead(IUP); }

void loop(){

UD = analogRead(IUP);

LR = analogRead(ILR);

// UP-DOWN

if(UD < UPMID - MID){

digitalWrite(DWN, HIGH);

}else{

digitalWrite(DWN, LOW);

}

if(UD > UPMID + MID)

{ digitalWrite(UP, HIGH);

}else{

digitalWrite(UP, LOW);

} // LEFT-RIGHT

if(LR < LRMID - MID){

digitalWrite(LEFT, HIGH);

}else{

digitalWrite(LEFT, LOW);

}

if(LR > LRMID + MID){

digitalWrite(RT, HIGH);

}else{

digitalWrite(RT, LOW);

}

delay(400);

}

About This Instructable

4,042views

87favorites

License:

More by BlueMatter:Connect and use Joystick with Arduino Arduino Tutorial - Laser security system Arduino Tutorial - Easy secret knock detector 
Add instructable to: