Haven’t posted here in a while 🙂 But I’ve been very busy. And bought lots of new “electronic toys”. One of the things I bought is a small plastic pan tilt kit. I got it on Ebay. It didn’t come with the servos. But I still had some small Micro 9G servos that fit the kit. To try it out I hooked up the little servos to one of my Bajduinos. I then wrote a sketch to control the pan/tilt kit with a simple analog joystick. The kit is ideal to mount a small webcam on it. Well that was my original plan. But I recently bought the official Raspberry Pi camera board. The camera fits perfectly on the kit 🙂 My goal is to control the pan/tilt kit over wifi through the Raspberry Pi and an Arduino. But that is a project that will take me some time. Need to learn some python first.
Here is the simple Arduino code I used in the above video:
// http://www.bajdi.com
// Pan/tilt kit controlled by joystick
#include <Servo.h>
// Define servos
Servo panServo;
Servo tiltServo;
// Servo positions
byte panServoLeft = 10;
byte panServoCenter = 95;
byte panServoRight = 160;
byte panServoPos;
byte tiltServoUp = 160;
byte tiltServoCenter = 90;
byte tiltServoDown = 15;
byte tiltServoPos;
// Analog values of the joystick
int X; // center = 519 up = 866, down = 77
int Y; // center = 512 left = 996, right = 18
#define runEvery(t) for (static typeof(t) _lasttime;(typeof(t))((typeof(t))millis() - _lasttime) > (t);_lasttime += (t))
void setup()
{
Serial.begin(9600);
panServoPos = panServoCenter;
panServo.attach(7); // (min=10/max=160)
panServo.write(panServoPos);
tiltServoPos = tiltServoCenter;
tiltServo.attach(6); // (min=15/max=160)
tiltServo.write(tiltServoPos);
delay(250); // Give servos time to move to start position
}
void loop()
{
runEvery(20) // Runs every 20ms, slow down servo movement
{
X = analogRead(A0); // read analog value from joystick X-axis
Y = analogRead(A1); // read analog value from joystick Y-axis
if (X > 540 && tiltServoPos < tiltServoUp)
{
tiltServoPos += 1; // move servo up
}
if (X < 500 && tiltServoPos > tiltServoDown)
{
tiltServoPos -= 1; // move servo down
}
if (Y > 532 && panServoPos < panServoRight)
{
panServoPos += 1; // move servo right
}
if (Y < 490 && panServoPos > panServoLeft)
{
panServoPos -= 1; // move servo left
}
//move servos
panServo.write(panServoPos);
tiltServo.write(tiltServoPos);
}
// Serial printing of variables for debugging
runEvery(500){
Serial.print("X = ");
Serial.println(X);
Serial.print("Y = ");
Serial.println(Y);
Serial.print("tiltServoPos = ");
Serial.println(tiltServoPos);
Serial.print("panServoPos = ");
Serial.println(panServoPos);
}
}
Can you post the ebay link of the pan/tilt kit?
Here is the kit: http://www.benl.ebay.be/sch/i.html?LH_BIN=1&_sop=15&_sacat=0&_from=R40&_nkw=pan+tilt+kit&LH_PrefLoc=2
You will also need 2 small 9G/SG90 servos.
Hi there Bajdi, by any chance do you have the schematic por wiring this application?
has been a while but if you can let me see i will appreciate
thanks
other question, besides of the schematic for wiring you said you made a home board to make it work, how was that?
thanks
I don’t draw schematics of such simple circuits. I design my own “Arduino’s” in Eagle and have the PCB’s made in China. Like this one: http://www.bajdi.com/bajduino/bajduino-3a-3/
Sir can you please write code for DC geared motor instead of servo motor for above pan and tilt application for joy stick, I am new to arduino please.