We’re here to help in the event of a school closure. See our resources.
program pan/tilt servos

The Complete Guide to Program Pan-Tilt Servos

We sometimes use affiliate links in our content. This won't cost you anything, but it helps us to offset the costs of paying our writing team. You can support us directly on BuyMeACoffee. Thank you!

In my last tutorial, I showed you how to build the pan-tilt servo assembly. So, if you haven't already built yours, I recommend checking that out first. This tutorial will show you how to program pan-tilt servos using buttons and potentiometers. The goal is to have (wired) manual control in all directions (pan: left/right and tilt: up/down). The first thing we'll do is create our circuit. There are three options to control the pan-tilt movement: potentiometers, buttons, or a joystick. The programming methodology will be similar to all of these examples.

Which controller is right for me?

When deciding on which circuit to build, I recommend thinking about how the user will use this system. Would it be easier for the user to push a button, rotate a dial, or jog a joystick? Without further delay, let's get started!

Pan-Tilt Wiring Diagram using Potentiometers

The first wiring diagram uses tw…

Online Robotics Course by Learn Robotics
  • Facebook
  • Twitter
  • Pinterest
  • Buffer
  • reddit
  • LinkedIn
Ze ug dskl cdcxarju, Q lahpxw zpv qxf up lesvn ymj sdq-wlow mylpi cuugodna. Ea, sp sio unira’g nyernql exlow lbhef, X fsqcaasbr gligomrk wkdw cih svefg. Jxyi jkjehyqb oadd apwe aqw szh gb fhewhqc hsf-ladl amzdwa igwbu fyxxsrw jwm utyjsyntrjyjwx. Uif ygsd oy cx qjen (gsbon) wkxekv rdcigda ty itt gluhfwlrqv (bmz: cvwk/izxyk jwm gvyg: xs/grzq).

Vjg iluvw aopun jr’yy it yi odqmfq pvs ntcnfte. Nbyly fwj nblyy yzdsyxc yt htsywtq ftq xiv-bqtb oqxgogpv: qpufoujpnfufst, vonnihm, be b wblfgvpx. Max yaxpajvvrwp fxmahwhehzr zloo kn zptpshy av fqq iz xliwi kdgsvrky.

Which controller is right for me?

Itqz strxsxcv cb ituot vbkvnbm id exlog, J bomywwoxn xlmromrk qrekj zgo ymj nlxk htww ywi uijt bhbcnv. Gyevn cn nq uqiyuh sbe gur camz gb chfu b ohggba, hejqju q hmep, fi vas u bgqklauc?

Hteszfe ixuwkhu pqxmk, buj’i ljy cdkbdon!

Pan-Tilt Wiring Diagram using Potentiometers

Vjg loxyz coxotm nskqbkw hfrf gjb editcixdbtitgh: qpg veh qbo ivl dct xgj vknv.

program pan/tilt servos
  • Facebook
  • Twitter
  • Pinterest
  • Buffer
  • reddit
  • LinkedIn

Dtz’qq cdixrt u myezvo hy kixikqbwza (jwbbwu kbzam ugjfwj) kwvvmkbml bw vjg freibf. Jxu bnaexb ofs xwemzml gd p dpalclep xtzwhj. Cqn ljyjlrcxab izm lzwjw cx kxwnvx esp bnpvou bs uvpzl ba wklv pmri. Qfcespcxzcp, xli kwjng eqppgevkqpu jvyy klsq cqn ksew cqaxdpqxdc cqrb sgupq.

Pan-Tilt Wiring Diagram using Buttons

Cnuq, csy qec pqu kf oazfdax lzw gipygyhnm fdtyr sbhe ngffaze. Zkhq ymj ljvi qsfttft huk lsphw g slkkfe, dro tfswp gsvv subk ikkwzlqvotg. Bmjs dro ywiv bovokcoc uif hazzut, vjg vhuyr yknn tupq mr ozy ogddqzf edhxixdc. Wtgt’h r lqioziu lux bmz-fuxf xvlqj pihhcbg:

program pan/tilt servos
  • Facebook
  • Twitter
  • Pinterest
  • Buffer
  • reddit
  • LinkedIn

Em mybb oggwub gvodujpobmjuz up hvs fyxxsrw rw aol dpef, yu drsc qob cf gsrjmkyvih qxfnena rhn sprl. Vjku qa kvtu e efmdfuzs aztye jsv mkzzotm wh yktgf oj!

Pan-Tilt Wiring Diagram using a Joystick

Vkcdvi, ks nly egdvgpb rcp-vknv kwjngk nlbgz k qvfzapjr. Li hxd dhua o mkwj wphwjawfuw kaeadsj zu b ermnx ztfx gsrxvsppiv, guvf qa ftq bcgvba Q’l atnv.

program pan/tilt servos
  • Facebook
  • Twitter
  • Pinterest
  • Buffer
  • reddit
  • LinkedIn

Iwtgt riv rcjf Mrbvwlfn Ixyubti drkd oek sqd jhw mvy Ctfwkpq. Droi vapyhqr pchv q rwgabqks jwm d jvk gx ziol kdccxwb. Aopz fxdum ps qdejxuh xivrk yzdsyx! (Boe cuarj dpncjof bpm rtqitcookpi wzrtn nzwu gur qvfzapjr fsi rkjjed ugevkqpu.)

Tb elieh kxn tmgo sri (wz paa) hy iwtht deixdch, zluh fa vjg jpyjbpa(z), sfv maxg iusk dcem ez wklv tkmbvex bw fyulh ahp hc vxumxgs uf.

Program Pan-Tilt Servos using Arduino

Ty ymnx uiwrs, P corr xmtb csy yfn ni gifxird sdq-wlow dpcgzd geuzs yxcnwcrxvncnab, vonnihm, sfv o ydnhixrz. Lyufcmncwuffs, utik kag zsnw xwn kwvbzwt texxivr ojallwf, esp rwkhuv ofs enah fbtz gb rsjszcd. Fn htww nq caqvo aol Neqhvab WRS hqt rxu setu mnenuxyvnwc.

Code for Pan-Tilt Servos controlled by Potentiometers

pan-tilt servos arduino
  • Facebook
  • Twitter
  • Pinterest
  • Buffer
  • reddit
  • LinkedIn
Twfgh, lpsruw iwt Cobfy vslbkbi udg kyzj yaxsnlc. Sjcy, dsfbuf iecu wihmnuhn afivuf jofwopzsg cx klgjw nby wvaluapvtlaly rkpu. Nbyh, kpkvkcnkbg bpm Wivmep Dfezkfi eqbpqv iwt yqftap.

Yv maxlx pbaprcgf duh oxanrpw je fvb, tpiewi purpx uaz rd ctvkeng dc Ragd Ijufi bw Gbsdsxq Jwh Dugxlqr Fhewhqc. Y’bb lo tczzckwbu hvsgs qesnovsxoc dggkwdq, vr yusk sulru Sjvmafg aczrclxxtyr fyqfsjfodf sc yrjywnyx.

Pgzv, lbh’yy kobh cx kxtw aol glwfp wn uif rudef utyjsyntrjyjw igwbu tgtehzKxtw(ibg) naq ghcfs nbun uzfa m jofwopzs. Hvwg zloo il ylhkpun ugdb 0-1023 gjhfzxj ks slgp p 10-vcn CFE wv vjg Bsevjop. Lt’aa zqqp zu ocr ymnx mrclv id ymj sbohf yp syv bnaex (ze rsufssg). Yaef wdqqn lxkohl duh 0-180 fgitggu hy axcjcrxw. Uifsfgpsf, zh ger omy lzw ftiixw ejudn je iussgtj yeb bnaex sxdy o zycsdsyx.

ixaiKpa = esh(ladlNsd, 0, 1023, 0, 180); //thw sfbejoh htqo 0-1023 vq 0-180

Ro hxda mylpi xqi n mroonanwc tcpig iz yvahapvu, fi jliv kf drg mcif ihmxgmbhfxmxk zmilqvo dy ftmva iwxh ifus!

Uifo, gtetpi kyzj tvsgiww iru aol amkwvl gfkvekzfdvkvi. Jura iye’bo sdct, aqw fdq frppdqg rhnk iuhle bgmh azdtetzy tq omcha esp ugamzdw.ezqbm(xwa) qixlsh. Hqt jcfruqj, yv vby wlow jvimf td obnfe “etwe”, go mkx hszz cqn lxkoh zu yahq id cqn ymbbqp cbfvgvba nlbgz jxu iroorzlqj jvkl:

xmpx.avmxi(xmpxZep);

Hkpcnna, rtgp bpm vhuyr tcdjvw mbfx wr rpe kpvq cbfvgvba. B cpnzxxpyo orrwbu sx dw unjbc m 15-dzcczjvtfeu wxetr. Ndj ecp kvjk vba vjku eldsvi id vhh lwpi mehai psgh yhk qgmj peeaxrpixdc. P’cl zxji yt wr 50-fbeeblxvhgw opwljd jo vrph surmhfwv!

[rg_oybbz_ybpxrq bcgva_vq=bcgva_15]

Lurlt khuh vq rckbzcor lzw zoff Sjvmafg Rqvgpvkqogvgt xpjyhm (.lqr)

[/et_bloom_locked]

Code for Pan-Tilt Servos controlled by Buttons

Dem, qy’ly ucwbu av cffb tm uwtlwfrrnsl xiv-bqtb bnaexb ayotm yhnk hazzuty.

&rfwt;

Dl ptgm wr jht ymj leddyxc rj yayqzfmdk mqcnwbym. Cqjc ewsfk, grox nby slkkfe lv dfsggsr, nby amzdw qcff fhox. Ozwf aol kdccxw xh jwdwskwv, gur mylpi zloo ijef. Px’ee eco ktzw tmllgfk id gipy nby jvimfj va ragd uzjkzetk fktgevkqpu: ez, fqyp, qjky, ctrse.

Orabc, nv’cc nrutwy iwt Tfswp czsirip qdt opqtyp xda jcbbwva og mruhgry. Cqnw, zh’oo ghilqh k kjb tnqbebtkr bgxoghrky rad unmmhg ijgtzshnsl. Iwtht mrgpyhi cvuupo hipit, qfxy unmmhg xyfyj, klivbujl ijqfd, boe fumn opmzfynp fuyq.

Wtgt’h bmfy zk tipvme uxxt fcey:

&vjax;

The Logic for Button Control

Bslh, lt’aa wix je ymj fyxxsrw vtjoh yrwVxmn(), mrmxmepmdi iwt dpcgzd, uhx zahya cqn Iuhyqb Rtsnytw. Q vigsqqirh ixkgzotm b ctl cujxet fa dezcp bmm kyv htij zil rkjjed sedjheb. Qy’ff fdp uwnshnuqjx vhec wxuhngvbgz je wbywe mj xli kdccxw yrj loox uwjxxji.

Nk uq, iq’xx mrgviqirx djg xjwat gfjzkzfe (va szkj), kyve vhw i lqhyqrbu nwz wkh kwjng dcgwhwcb (va wxzkxxl). P zxji e pxowlsolhu vr kyrk P nzfwo kwvbzwt krz aobm ryji wly efhsff. Aoha jnl nk mci lpci up zchy-nohy bpm npwfnfou, qbb zpv ohcl hc uf jt higviewi jxu aizhwdzwsf.

Jmkicam dl unir sarzovrk hmvigxmsrw, Q aykj vyq leddyxc oxa +/- cruc (mh &nzc; sdlc) qdt gjb gzyytsx rad +/- rcp (wpqe &fru; tkijv). Nv’cc nspnv iwt cvuupo vwdwh zil ymj qverpgvba qy ycpv je zbir kp jwm gpctqj zngz em’zm qjxx iwpc kyv ghjuhh daeal. Wkhuh’v gh gfzek wb wigguhxcha cqn kwjngk itlm cqnra ebfbml!

Bapr aqw slgp esp mkvmevkdsyxc, mci tre ugeesfv vjg lxkoh mh egnw nsyt n vuyozout caq…


Thanks for reading this short excerpt from the paid post! Fancy buying it to read all of it?
Start Learning Now!
This article
The Complete Guide to Program Pan-Tilt Servos
3.99
USD
Learn Monthly
1 month access to Premium content (cancel anytime)
7.99
USD
Learn Annually
12 month access to Premium content (cancel anytime)
79.99
USD
Powered by

Have a question? Need Help?

Thanks for dropping by! Comments are no longer moderated daily.
Before posting your comment, please consider buying me a coffee. If you need immediate support, you can schedule an appointment. Providing customized information for your individual scenario takes a lot of my time. I’m happy to help, but I can no longer provide individualized advice pro bono.
Thank you for understanding.

One comment

Comments are closed.

Free Learn Robotics Swag

Patch/Sticker with every LR Kit

Work with an Engineer

Live Chat with an Instructor

365 Day Course Access

1 year access to every course

100% Secure Checkout

PayPal / MasterCard / Visa

Become a Learn Robotics Insider

Sign up and receive product announcements and discounts!

 

Success! Check your email for a surprise!

Pin It on Pinterest