top of page
Writer's pictureRamesh G

JoyStick Controlled Relay Board

Updated: Jul 2, 2021



In this project, we are interfacing Joystick with Arduino simply by controlling four Channel relay Board as per the movement of the Joystick. We have placed 4 relays in the such a way that it represents the direction of the joystick shaft movement. This joystick also has a push button which can be used for various other purposes or can be left idle.


The first thing that comes in our mind listening to the word Joystick is the game controller. Yes, it’s exactly the same and can be used for gaming purpose. Apart from gaming, it has many other applications in DIY electronics. This joystick is nothing but a combination of two potentiometers for X and Y plane respectively. It reads the voltage through the potentiometer and gives analog value to the Arduino, and the analog value changes as we move the joystick shaft (which is simply the potentiometer pointer).


Circuit Diagram



Components Required

  • Arduino UNO

  • PS2 Joystick Module Breakout Sensor

  • 4 Channel Relay Board

  • Jumper wires

JoyStick

This is JoyStick Module PS2 Breakout Sensor very similar to the ‘analog’ joysticks on PS2 (PlayStation 2) controllers. Directional movements are simply two potentiometers – one for each axis. Pots are ~10k each. This joystick also has a select button that is actuated when the joystick is press down.


With the help of this Joystick Module, you can measure position coordinates on the X and Y axis by moving the “hat”. It also contains a switch that is press-able by pushing the “hat”.It also contains a switch that is press-able by pushing the “hat” down. Similar to the XBOX controller.

The X and Y axes are two 10k potentiometers which control 2D movement by generating analog signals. When the module is in working mode, it will output two analog values, representing two directions. This module uses the 5V power supply, and value, when reading through analog input, would be about 2.5V, a value will increase with joystick movement and will go up till maximum 5V; the value will decrease when the joystick is moved in other direction till 0V.


OVERVIEW

  • Dimensions: 40 x 27 x 15 (LxWxH) mm.

  • Weight: 10gm (without Hat).

  • 2.54mm pin interface leads.

  • Operating Voltage: 5V.

  • Long service life and stable performance.

  • Standard interface and electronic building blocks.

  • Widely use in Arduino DIY projects.

Applications:

1.As square wave signal generator which generates a square wave signal

2. To provide a signal to the stepping motor driver

3. Adjustable pulse generation for chip use

4. Produce variable pulse signal, the control-related circuit (PWM dimming, speed)


Subscribe and Download code.

Installing the Arduino_Library

No special Library require for this project.


Testing of Joystick Arduino code

int xPin = A1;

int yPin = A0;

int buttonPin = 2;


int xPosition = 0;

int yPosition = 0;

int buttonState = 0;


void setup() {

// initialize serial communications at 9600 bps:

Serial.begin(9600);

pinMode(xPin, INPUT);

pinMode(yPin, INPUT);


//activate pull-up resistor on the push-button pin

pinMode(buttonPin, INPUT_PULLUP);

// For versions prior to Arduino 1.0.1

// pinMode(buttonPin, INPUT);

// digitalWrite(buttonPin, HIGH);

}


void loop() {

xPosition = analogRead(xPin);

yPosition = analogRead(yPin);

buttonState = digitalRead(buttonPin);

Serial.print("X: ");

Serial.print(xPosition);

Serial.print(" | Y: ");

Serial.print(yPosition);

Serial.print(" | Button: ");

Serial.println(buttonState);


delay(100); // add some delay between reads

}


Result in serial monitor

Subscribe and Download code.

Main arduino code

#define joyX A0

#define joyY A1


int button=2;

int buttonState = 0;

int buttonState1 = 0;


void setup() {

//pinMode(7,OUTPUT);

pinMode(button,INPUT);

digitalWrite(button, HIGH);

Serial.begin(9600);


pinMode(8,OUTPUT);

pinMode(9,OUTPUT);

pinMode(10,OUTPUT);

pinMode(11,OUTPUT);

}

void loop() {


int xValue = analogRead(joyX);

int yValue = analogRead(joyY);

Serial.print(xValue);

Serial.print("\t");

Serial.println(yValue);

buttonState = digitalRead(button);

Serial.println(buttonState);

if (xValue>=0 && yValue<=10)

{

digitalWrite(10, HIGH);

}

else{digitalWrite(10, LOW);}


if (xValue<=10 && yValue>=500)

{

digitalWrite(11, HIGH);

}

else{digitalWrite(11, LOW);}


if (xValue>=900 && yValue>=400)

{

digitalWrite(9, HIGH);

}

else{digitalWrite(9, LOW);}


if (xValue>=400 && yValue>=900)

{

digitalWrite(8, HIGH);

}

else{digitalWrite(8, LOW);}


if (buttonState == LOW)

{

Serial.println("Switch = High");

digitalWrite(8, HIGH);

digitalWrite(9, HIGH);

digitalWrite(10, HIGH);

digitalWrite(11, HIGH);

}

else{//digitalWrite(7, LOW);

}

// buttonState1 = digitalRead(7);

Serial.println(buttonState1);

delay(100);

}


Result in serial monitor


802 views1 comment

Recent Posts

See All

1 commentaire


vijayalaxmi potdar
vijayalaxmi potdar
29 avr. 2023

can I have circuit diagram from tinkercad for Relay controlling with joystick pls. email.id vijayapk123@gmail.com

J'aime
bottom of page