The Best DIY STEM Tutorials and Projects

Joystick LED’s controller

OVERVIEW

In this project, we use a joystick to control LEDs, just like a game controller! Moving the joystick in different directions will turn LEDs on and off, helping us understand how input from sensors can be used to control outputs. It’s a fun way to learn about analog signals and Arduino programming! 🚀✨

You can follow this video and the instructions below.

Video

Components Required

Here is a list of Components that we will need to make this Project.

Electronic-Dice_Componnets.
Sr #Item NameQuantity
1Arduino Uno1
2Breadboard1
3Joystick 1
4Jumper wires9
5LEDs3
6Arduino cable1
7Buzzer1

Wiring Diagram

Here is a Complete Wiring Diagram along with Instructions for this Project

Electronic-Dice_Circuit-diagram

Program / Code

Code is Explained in the Comments of the Code

const int joystickX = A0;
const int joystickY = A1;
const int redLed = 3;
const int yellowLed = 5;
const int greenLed = 6;
const int buzzer = 4;

void setup() {
  // put your setup code here, to run once:
  pinMode(redLed, OUTPUT);
  pinMode(yellowLed, OUTPUT);
  pinMode(greenLed, OUTPUT);
  pinMode(buzzer, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  int xValue = analogRead(joystickX);
  int yValue = analogRead(joystickY);
  int threshhold = 400;
  //updirection
  if (yValue < threshhold){
   digitalWrite(yellowLed, HIGH);
   digitalWrite(redLed, LOW);
   digitalWrite(greenLed, LOW);
   noTone (buzzer);
  }
  //downdirection
  else if (yValue > 600){
     tone(buzzer, 1000);
     delay(50);
     digitalWrite(yellowLed, LOW);
     digitalWrite(redLed, LOW);
     digitalWrite(greenLed, LOW);
  }
  // right direction
 else if (xValue > 600){
     noTone(buzzer);
     digitalWrite(yellowLed, LOW);
     digitalWrite(redLed, HIGH);
     digitalWrite(greenLed, LOW);
  }
  // left direction
else if (xValue < threshhold){
     noTone(buzzer);
     digitalWrite(yellowLed, LOW);
     digitalWrite(redLed, LOW);
     digitalWrite(greenLed, HIGH);
  }
}

Thank you so much for going through our tutorial, we hope it was easy to follow and you enjoyed it, please share your feedback and pictures of the project (if you have made it) in the comments below .!

Share your love

Leave a Reply

Your email address will not be published. Required fields are marked *