Joystick Led Pwm

by adithyapaip in Circuits > Arduino

5654 Views, 11 Favorites, 0 Comments

Joystick Led Pwm

DSC09055.JPG
Controlling led or simply reading values of analog values from joystick... let's get started

Parts Used

DSC09047.JPG
DSC09046.JPG
DSC09048.JPG
DSC09049.JPG
* Arduino uno (with USB cable)
* Joystick (potentiometer)
* led (any)
* Jumper wires(single strand wires)

Connection

joystick_bb.jpg

Easy to understand with this pic I guess and any questions feel free to comment....

x axis to A1

y axis to A0

SW to pin2

+5v to 5v pin or 3.3v pin

and gnd

Led to 11 pin

Code

Capture2.PNG

int xPin = A1;
int yPin = A0;

int buttonPin = 2;

int led=11;

int xPosition = 0;

int yPosition = 0;

int buttonState = 0;

void setup()

{

Serial.begin(9600);

pinMode(xPin, INPUT);

pinMode(yPin, INPUT);

pinMode(led,OUTPUT);

pinMode(buttonPin, INPUT_PULLUP);

}

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);

analogWrite(led,xPosition);

delay(100);

}

Testing

Capture.PNG

You can add another led to to y axis and make to use
...

Potentiometer

DSC09050.JPG

Potentiometer can be used instead of joystick