Hey! Ive just started using the arduino uno and successfully used the digital ports for projects. Now that i tried the joystick project , the x and y values which are analog always return 0 , the digital sw pin however functions correctly. i tried the lm 35 temperature sensor too and the analog value is still 0. Help!
Sorry but "the joystick project" may not mean anything to most of us. Post the code you are using to read the analog values and a diagram of how your joystick is connected.
Steve
sorry about that . heres the code
// Arduino pin numbers
const int SW_pin = 4; // digital pin connected to switch output
const int X_pin = 2; // analog pin connected to X output
const int Y_pin = 3; // analog pin connected to Y output
void setup() {
pinMode(SW_pin, INPUT);
digitalWrite(SW_pin, HIGH);
Serial.begin(115200);
}
void loop() {
Serial.print("Switch: ");
Serial.print(digitalRead(SW_pin));
Serial.print("\n");
Serial.print("X-axis: ");
Serial.print(analogRead(X_pin));
Serial.print("\n");
Serial.print("Y-axis: ");
Serial.println(analogRead(Y_pin));
Serial.print("\n\n");
delay(500);
}
The ground from the joystick is connected to the ground on the arduino. The SW to pin 4 of the digital i/o , the 5v to the 5v and the x and y pins to analog 2 and 3 respectively.
The correct names of the analog pins start with "A":
const int X_pin = A2; // analog pin connected to X output
const int Y_pin = A3; // analog pin connected to Y output
Although, the analogRead() function will make the correct guess at what you intended here.
"The 5V"? Most simple joysticks have independent pins for each axis so you need to connect 5V to at least 2 pins, maybe more depending on how the switch is wired. Do you have a part number or schematic for this joystick?
Next time use [ code ] tags. The forum software eats some of your code if you don't.
Hi,
Welcome to the forum.
Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
We need to see how you have wired your components, especially the joystick.
Thanks.. Tom...