joystick push button how to

Hello. Im having trouble wiring the push button to the arduino. How do i wire it up? I've tried using a resistor to ground off the 'sel' pin of the breakout board, but i cant seem to get a reading from my arduino. I've tried to just put wire from 'sel' to my input digital pin with pinMode(mybtn, INPUT_PULLUP) but that didnt work either. Can someone help me PLEASSSSSSSSSSSEE !!

Many thanks in advance.

https://www.sparkfun.com/products/9110

If you can identify two wires that are switched between open circuit and closed circuit when you press the button, then wiring it to the Arduino from there is easy. But with no idea what joystick or breakout board you're using, I have no idea whether they provide that type of output or whether the wires you're using are the appropriate ones. I suggest you start with a simple normally-open momentary switch and the DigitalInputPullup example sketch. The sketch contains a description of how to connect the switch up.

The breakout board is in the link provided. The joystick is the same one on one of the pictures as well. The pin outputs from the breakout board are shown. Im using the 'sel' and sending a wire to the digital input (which did not work). Then i tried a wire from 'sel' to the digital input and a resistor from 'sel' to ground. Also did not work. Kinda stuck on what to do :/

I've used the switch on my similar joystick, with success.

So, you need to post the code you tried, and a schematic of the wiring (rather than a description like "I connected this to that"). Easiest way to do a schematic for a simple setup is to sketch it on paper and take a pic with your phone. Or try Fritzing

Edit... PS: the mods are going to take you to task for posting the same question in your other thread. First because you shouldn't post twice: that just pisses everyone off and Second, because the place you posted the other thread is to do with Arduno install problems, not project problems. You might like to go delete that.... 8)

hehe. thanks for that. Tried to delete but didnt let me. :frowning:

Here we go. Picture of circuit. (I couldnt figure out how to put it directly on here)

Imgur

and as for the code, the idea is to push one button on a joystick and move it to a certain position, and then use the other button on another joystick to move it to another position. This code is kind of a trial as well … Here it is:

(sorry im just now learning arduino)

#include <Servo.h>

Servo servo1;
int pos = 90;
int leftbtn = 1;
int rightbtn = 2;
int lbtnstate = 0;
int rbtnstate = 0;

void setup() {
	Serial.begin(9600);
	pinMode(leftbtn, INPUT);
	pinMode(rightbtn, INPUT);
	servo1.attach(9);

}
void loop() {
	
	lbtnstate = digitalRead(leftbtn);
	rbtnstate = digitalRead(rightbtn);

if (lbtnstate == HIGH){
	digitalWrite(pos, 45);
	servo1.write(pos); 
	delay(15);
	}	
		
if (rbtnstate == HIGH){
	digitalWrite(pos, 135);
	servo1.write(pos); 
	delay(15);
	}	
}

hehe. thanks for that. Tried to delete but didnt let me. smiley-sad

Here we go. Picture of circuit. (I couldnt figure out how to put it directly on here)

Hmmm, I thought we could delete our own posts? To add a pic, go to Additional Options at the bottom of the posting area.

I’m just leaving for work (515 am here 8) ) so I don’t have a chance to look at that right now sorry!

Edit… ps: you should put your voltmeter across that sel pin and the joystick gnd pin to see what happens: it should give 5v in one or other of the button positions and 0v in the other. Alternatively, check for continuity across those pins. Either way will verify if the switch is actually working. Even put an led with series resistor across sel and gnd and see which switch position lights it up.

snaps finger

darn. Thanks for trying ! Maybe i'll figure it out

Edit: Ok. Thanks. I will definitely try that !!

Wire the switch according to the #2 sketch. Set pinMode() on the switches to INPUT_PULLUP. The switches will bring the digital input LOW when pushed so change your if statements. What do you want this to do?

digitalWrite(pos, 45);

What it does is write a HIGH to pin 90.

I FIGURED IT OUT !!!

I did +5V to ‘sel’ and a parallel circuit (wire to pin input and resistor to ground) from GND on the breakout board. Not sure if it’s most convenient but it’s the one that is working for me so far. Thanks a bunch for all the help guys !!

mrecengr: I FIGURED IT OUT !!!

I did +5V to 'sel' and a parallel circuit (wire to pin input and resistor to ground) from GND on the breakout board. Not sure if it's most convenient but it's the one that is working for me so far. Thanks a bunch for all the help guys !!

I can't quite picture that in my mind: post a drawing?

Glad you got it going though!

mrecengr: Not sure if it's most convenient but it's the one that is working for me so far. Thanks a bunch for all the help guys!!

No, that's not how you do it. "groundfungus" has explained it - you follow the diagram, connect Gnd on the breakout to ground, Vcc on the breakout to 5V, and "Sel" to your input pin. You do not need a pull-up, you simply set pinMode(leftbtn,INPUT_PULLUP);on that pin.

You note that the pin will of course, be LOW when it is pressed and write the code accordingly.