Very Basic Pan Tilt Using Arduino

19,480

27

4

Introduction: Very Basic Pan Tilt Using Arduino

About: i like fish and technology.
for this instructable you will be learning the basics of arduino and codes for arduino.


video of pan/tilt arduino project (careful, this video contains aweful impressions of batman)



if anybody wants me to put up more photos on this project please message me.


Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Supplies and Wiring

things you will need:

-2 sub-micro servo motors

-one pan/tilt bracket

-various jumper wires

-mini breadboard

-joystick

-arduino

-(optional) batman's head, two LEDs, and a tiny hat

Step 2: Description of Wiring

i don't have any photos for this process but i will make some if i am asked enough.

wire the data wire of the bottom servo to pinhole ~9 and wire the data wire of the top servo to pinhole ~10, the data wire is usually the white or yellow wire of the servo.

the y axis pin of the joystick goes to A0, x axis pin goes to A1

for powering everything connect allpositives to the 5V pinhole on the arduino and allnegatives to the GND pinhole on the arduino, i used a mini breadboard for this

Step 3: CODE

below is code for the arduino, i suggest using this stuff if you want your cool new pan/tilt machine to work!

code:

// Controlling two servos positions using two potentiometers or a joystick
// modified knob example by kevin jones original code by Michal Rinott

#include

Servo myservo0;  // create servo object to control a servo
Servo myservo1;

int potpin0 = 0;  // analog pin used to connect the potentiometer
int potpin1 = 1;
int val;    // variable to read the value from the analog pin

void setup()
{
  myservo0.attach(9);   // attaches servo to pin 9
  myservo1.attach(10);  // attaches the servo on pin 10 to the servo object
}

void loop()
{
  val = analogRead(potpin0);            // reads the value of the potentiometer (value between 0 and 1023)
  val = map(val, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180)
  myservo0.write(val);                  // sets the servo position according to the scaled value
  delay(25);                           // waits for the servo to get there
  val = analogRead(potpin1);            // bananas are high in potassium
  val = map(val, 0, 1023, 0, 179);     //
  myservo1.write(val);                  //
  delay(25);                           //
}

Microcontroller Contest

Participated in the
Microcontroller Contest

Be the First to Share

    Recommendations

    • Backyard Contest

      Backyard Contest
    • Silly Hats Speed Challenge

      Silly Hats Speed Challenge
    • Finish It Already Speed Challenge

      Finish It Already Speed Challenge

    4 Discussions

    0
    gergerdgp
    gergerdgp

    3 years ago

    pan tilt motor dc with joystic forward n reverse and potensiometer for speed contro. please share code

    0
    alumpkins
    alumpkins

    4 years ago

    The code is not working

    0
    Robertlb56
    Robertlb56

    Reply 4 years ago

    It is missing the library reference. Try changing the first line of code to:

    #include <Servo.h>

    0
    katman101
    katman101

    Reply 4 years ago

    it could be outdated, this is an old instructable.