Home » Arduino, Jobs, PHP, Real Time Collaboration, _Favourites

Arduino: manage two servos using a joystick and create multiple movements with the Lynx Tilt Kit

15 November 2009 One Comment

We’ll use the Arduino microcontroller and an analog joystick to control two servos: the first one will be connected to the horizontal axis, and the second one to the vertical axis.
We also use a the Lynx B-Pan Tilt Kit (BPT-KT) to connect servos together. Check the video and imagine what kind of robots or cool stuff you could create using more devices and a lot of pacience ; )

To create this prototype I have used a protoshield board but you can avoid it using only your Arduino microcontroller.

The Lynx B-Pan Tilt Kit is also optional but it allows to create really cool multiple movements.

Furthermore, to manage more then 3 or 4 servos i suggest to use a separate Servo Controller, a cool way to control 8, 16 or more servos using only one pin from your Arduino. Maybe in the future I’ll write something about it.

So, create the prototype getting inspiration from following images:
2009_11_16_mange-2-servo-motors-with-arduino_image

14112009513
14112009514

The Processing code is full-commented:

/*
 
Hardware:
- Arduino Duemilanove
- ProtoShield Board
- Mini Thumb Joystick
- 2 servo HS-422
- Lynx B-Pan Tilt Kit (BPT-KT)   
 
Features: 
- Move 2 servo using a Joystick 
 
The circuit:
- First Servo attached to digital PWM pin 10
- Second Servo attached to digital PWM pin 3
- Joystick attached to analog pins 4 and 5
 
 Author:
 Fabio Biondi  <http://www.fabiobiondi.com/blog>
 
*/
 
#include <Servo.h> 
 
const int servo1 = 3;       // first servo 
const int servo2 = 10;       // second servo
const int joyH = 4;        // Joystick Horizontal Axis
const int joyV = 5;        // Joystick vertical Axis
 
int servoVal;           // variable to read the value from the analog pin 
 
Servo myservo1;  // create servo object to control a servo 
Servo myservo2;  // create servo object to control a servo 
 
 
 
void setup() {
 
  // Servo   
  myservo1.attach(servo1);  // attaches the servo
  myservo2.attach(servo2);  // attaches the servo
 
  // Inizialize Serial
  Serial.begin(9600);
}
 
 
void loop(){
 
    // Display Joystick values using the serial monitor
    outputJoystick();
 
    // Read the horizontal joystick value  (value between 0 and 1023)
    servoVal = analogRead(joyH);           
    servoVal = map(servoVal, 0, 1023, 0, 180);     // scale it to use it with the servo (result  between 0 and 180) 
 
    myservo2.write(servoVal);                    	  	 // sets the servo position according to the scaled value     
 
    // Read the horizontal joystick value  (value between 0 and 1023)
    servoVal = analogRead(joyV);            
    servoVal = map(servoVal, 0, 1023, 70, 180);     // scale it to use it with the servo (result between 70 and 180) 
 
    myservo1.write(servoVal);                      	    // sets the servo position according to the scaled value 
 
    delay(15);                                  		   // waits for the servo to get there 
 
}
 
 
/**
* Display joystick values
*/
void outputJoystick(){
 
    Serial.print(analogRead(joyH));
    Serial.print ("---");  
    Serial.print(analogRead(joyV));
    Serial.println ("----------------");
}

RELATED CONTENT:
- Arduino and Pololu Micro Serial 8 Servo Controller
- Arduino: control a LED and one servo motor using a joystick

One Comment »

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.