Tuesday 4 September 2012

Joystick controlled Servo

Introduction:




This project involves the use of a single dual axis joystick to control the rotational direction a a servo.
Here, I've used an Arduino Uno as the main processing unit and the Arduino IDE to develop the code.

Let's talk about the servo. It is a negative feedback system. Every time it turns, a signal is fedback to an error amplifier which compares it with the actual signal given to the servo. This error amplifier finds the difference and then feeds it back to the servo to produce the necessary motions to bring the spline or the horn to the correct angle.

A normal servo is also limited to a maximum rotational angle of 180 degrees/half a circle. However, it can be modified to reach 360 degrees/a full circle by hacking the servo. Servo hacking is unfortunately not part of the scope for this post.


Schematic:
Figure 1. Routing using fritzing
 Components list:
1 x Arduino Uno
1 x servo
1 x dual axis joystick
1 x LED (as an indicator)

Operation:

For ease of code design, this setup uses the servo library for Arduino to control the servo.

Initially, when the joystick is not pressed downwards, the system remain inactive. Once the joystick is pressed, the LED light turns on to indicate that the system is ready.

The Arduino then waits for an input on the joystick. Since the joystick is connected to an analog pin on the Arduino, the Arduino is coded to receive the electrical signals (0 ~ 1024) as the joystick is moved left or right and convert it into the angular positions 0~180. 

Once the conversion is done, the value is fed to the servo using the servo.write( ) function. Normally, the rotation of the servo depends on the pulse width of the signal given to it. Below is an illustration obtained a while ago (thus, source is unknown) which illustrates the pulse width required for each servo position.

Figure 2. Duration of pulse required for each position
As seen in Figure 2, to remain stationary, the servo will also need to be constantly pulsed with a pulse width of 1.5ms.

Figure 3. Duration between pulse
 Besides pulse width, the period between pulse must also be at least 20ms in order to ensure good functionality.

Fortunately, the coding for all these is made simple with the servo.write( ) function in the servo library.

No comments:

Post a Comment