IAN LANG ELECTRONICS
On the left you can see a thumb joystick rather like the ones on a games console. This particular one is made by Sparkfun and I purchased it at rather a reasonable price from Proto Pic - click on the picture and it takes you to their webpage for all the details about it.
It is an analogue device and works in three dimensions. There are two axes, horizontal and vertical, and moving the joystick further or lesser along these axes causes a change in the attached potentiometers, which act as voltage dividers. At one extreme, zero voltage is passed to the output, at the other it's the full voltage. The third dimension is a downward push, and this causes a small tactile button to be activated. Under normal circumstances this will pass somewhere around 2V, but once activated this goes down to zero. It's too little to be of use as a digital signal and so the selector has to be passed to an analogue input too.
If you are going to be using one of these devices on your Arduino and especially if you are breadboarding I strongly recommend that you buy a breakout board designed for it such as the one on the right which is also available from Proto Pic. Although they are green in the advertising, when mine turned up it was red, apart from that it's exactly the same. The five holes you can see to the left of this image are pitched well enough to allow you to use a header that is very breadboard friendly and later if you want to make a permanent device the headers are good enough for a ribbon connector too. It's a very easy solder, about five minutes if you're experienced and perhaps half an hour for a beginner.
Once you've soldered together the best way to test it is with your Arduino. Wire up like this:
And upload the following sketch to your Arduino:
Serial.print(" Horizontal ");
Serial.print(" Select ");
Now open your serial monitor and you'll see that both the horizontal and vertical axes hover about 500. The select button should be up in the 400s somewhere, floating up and down.
Push the whole joystick gently down towards the breadboard by putting your fingers on top and gently pushing down towards the breadboard. You'll feel resistance, but eventually the whole thing will go down and you'll hear a click. That's the button activating. Do it again and watch the serial monitor. Select goes down to zero until you release it and then goes instantly up again. Now waggle the joystick slowly across one axis and then the other. You'll see that the value on the horizontal and vertical rises and falls depending on the position of the joystick.
Let's make it determine the position of a servo. Wire up like this:
And here's the sketch:
What should happen if all goes well is that the servo should follow the movements of the vertical axis of the joystick. The further one way you push the joystick, the further the servo goes. When you release the joystick, it goes back centre and the servo follows.
It would be better if we could get that servo to move right as the joystick does, but not move back until we move the joystick left, and vice versa. It'd be even nicer if we could do that so that if we moved the joystick a bit one way, the servo went slowly, and hard over the servo went fast. It'd be lovely if we could instantly centre the servo too. Hmm. I wonder how we can do this? Perhaps there's a solution on the next page........