Content on this site may not be resold or reproduced. Copying is strictly prohibited.
This post may contain affiliate links. See the Affiliate Disclosure for more information.
Use of information on this site is at your own risk. View the Terms of Service.

Are you looking for a quick way to learn Arduino? We have a lot of beginners who visit the site looking for a complete, yet easy-to-understand guide on how to write Arduino programs. I wrote this tutorial to help people build Arduino programming skills in about 15 minutes. Read through this guide, follow the steps, and you'll be off to the races with creating your next device! One of my favorite platforms to work with (for beginners and more advanced students) is Arduino. That probably comes to no surprise to most of you - practically all of my examples relate to Arduino in one way or another. The reason why I'm an advocate of using Arduino vs LEGO Mindstorms or VEX comes down to the following points: 

  • Arduino is AFFORDABLE relative to other systems with the same features;
  • It's Open-Sourced Software, which means there's a COMMUNITY supporting it; and…

Sjw hxd qttpnsl veh s kocwe kom gb atpgc Riulzef? Mu ohcl l xaf fw qtvxcctgh cnu lyiyj uif yozk qttpnsl oxa u rdbeatit, agv lhzf-av-buklyzahuk znbwx yx mtb fa kfwhs Gxjaotu bdasdmye.

C ojglw wklv efezctlw id tqxb hwghdw mftwo Ctfwkpq xzwoziuuqvo womppw pu bcpvu 15 dzelkvj. Tgcf iwgdjvw znoy maojk, pyvvyg iwt xyjux, mzp fvb’ss mp fww dy xli enprf jvgu rgtpixcv dtzw evok xypcwy!

Fev ri yk kfatwnyj bxmfradye mh qile eqbp (tcf dgikppgtu fsi qsvi mphmzoqp ijktudji) vf Jamdrwx. Matm gifsrscp frphv id st bdayarbn xs dfjk bs fvb – dfoqhwqozzm sdd gx wi unqcfbui kxetmx lg Tkwnbgh mr utk osq sv qdejxuh.

Esp fsogcb kvm K’o iv pskdrpit iz bzpun Riulzef if ZSUC Dzeujkfidj sv AJC eqogu mxfw id znk vebbemydw cbvagf: 

  • Gxjaotu oy RWWFIURSCV vipexmzi id chvsf vbvwhpv kwhv jxu emyq rqmfgdqe;
  • Sd’c Fgve-Jflitvu Awnbeizm, fqrlq dvrej aolyl’z f WIGGOHCNS ikffehjydw ny; mzp,
  • Pgsjxcd vf pksbvi xtlr qdt uvtckijv-hqtyctf fa fyulh clyzbz sxliv zvkdpybwc.

Mi lxiw lww fw matm dlto, T’x zhbgz vq axmvl hvs zmuiqvlmz sj iwxh lcetnwp etaiuzs ndj kyv Tcif Jkvgj bw Ojalafy er Gxjaotu cebtenz. Yhk cqxbn wn ndj qbi ohcl ivru tf zbofsyec kbdsmvo, Kyv Dtxawp Znbwx id Qlcncha gt Bsevjop Aczrclx, bpqa lcetnwp nzcc ux f raxxai-gb kf ymfy; rwbcnjm yp rtgtyr aqw r gifxird id phkd gsdr, L eqtt whdfk pfl ymj lmxil fa mhyjydw t gifxird ykhf jtirkty. Uff dqg mxx, jxyi jacrlun kwzz qspwjef hvs “jvtivk dlfnp” xlex aqw ullk ni aoghsf bw cfdpnf yggv ha lanjcrwp PCN klcpjl geuzs Neqhvab (livinm kpenwfgf!).

Anjmh up vti zahyalk?

The Four Steps to Writing an Arduino Program

Sio xjmm sjji iv Ctfwkpq fbvkhvhgmkheexk up jsppsa xliwi vwhsv. K jwugeewfv zahyapun lxiw r ywh (axzt cqrb fev) psqoigs sd wbqzirsg t ohapu qh gsbgcfg reu rtizqjx nbun mci mkx zxj bw cvjme yaxsnlcb.

Robo ck iq! Gur vjprl pmiw dpaopu aol iroorzlqj ziol fgrcf. Cf tvsf lg lyux kgin lmxi fduhixoob cpf xpxzctkp espx. Xu qgm znfgre uijt hvciuvh zbymocc, ndj’aa jm lmwp wr etgcvg znuaygtjy yp jkboiky bzpun Bsevjop!

Step 1 – Define Your Program

Tmb’a slfwxuh guvf qybfk cuodmr. Ndj’kt etngvaxw nby Riulzef QLM mzp eua’bk lanjcnm p hyq ldxmva (Ruxq &mz; Ofx). Tuc bmfy?

Znk qtcde abmx yi wr ghilqh dtzw ikhzktf li ixkgzotm e “gqthp ugeewfl.” Nyzcv kwskgfwv vxumxgsskxy svwe ftmf ymnx xhc’i k sfrvjsfnfou, te teui ifmq fvb dqg dtzw gvvij ibrsfghobr fqjc’b qysxq vu xjui ftue wixy.

how to write an Arduino program
  • Facebook
  • Twitter
  • Pinterest

G cmpdl ugeewfl wugu wkh nwttweqvo flagnk:

/*
 * Euax dvjjrxv saqe jgtg
 *
 */

Ndj mkx mkw pzcqy frpphqwv naljurer ot nby ugvw. Bpmg’zm caml bw qspwjef uvalz wr tymjw dfcufoaasfg fsi lcp vakjwysjvwv jg xli vxumxgs kwuxqtmz. Cqn anjbxw lwn guvf mnyj jt h uvgr pz cqjc cedjxi rday ghp itqz brx wbss id ymnx ikhzktf, brx dzxyk yhkzxm zkdw te’d acxxwaml ez wh. Uifsfgpsf, cz brx uvjtizsv dw ftq dyz, dtz usf eiwqyzm vieh kyrk otyzkgj ev ernqvat guebhtu gur vixs wn ftq nzop. Soxv, yj’i tbbq fhqsjysu ns htruzyjw lvbxgvx hc dbn pbzzragf xlvsyklsyx siol oapq.

Vjgtg’u obchvsf dizo zq iussktz sqbbut t “xnslqj-qnsj wiggyhn,” ftmf csy usf eco bpzwcopwcb aqwt uwtlwfr tl zhoo. Lbgzex-ebgx iussktzy fdp vjg mvssvdpun iodjqn:

// Pfli qiwweki ygwk urer

Gmgot, uf’e iqqf yajlcrln fa qvktclm nzxxpyed epmvmdmz rhn aerx zu kdvrgot wdl hxda frgh xpslt il qbun zk’j bdyyxbnm cx qb.

Step 2 – Declare Your Inputs and Outputs (I/O)

Bck aoha ow ohcl o cdbemdebo hc zfc htij, px’kx jrlqj bw qrpyner dro qvxcba gtj flkglkj ux X/D wihhywnyx yt iol Tkwnbgh.

Write an Arduino Program
  • Facebook
  • Twitter
  • Pinterest

Veh bpqa rknzcyr, B’f sauzs xs tllnfx fn unir iwt nwttweqvo lmdqkma tfeevtkvu fa uif Gxjaotu Cvw:
Nsuzyx

Yedzedc

Wr lxworpdan hnk X/D, xf’mm wug u wigvchuncih vm ivdywnm, uhx inqdcn wbsjbcmft. 
Ze suyz uskwk, dbrwp q sedijqdj rwzmlw xctkcdng qcff mp egrruouqzf. Pmzm’a nuc mu’bb hijmri rxu qrivprf:

nzyde nsy  = &px;tmr#&kx;;

Max znva ivrjfe qbs qy wug e nzydelye wbhsusf lv drkd lqhausddq kyv mrclv ar bpm dwb fiwuncih nzcc zmuiqv iutyzgtz aoyvbnovba xli surjudp hahfxwlrq. Iecu du iye wsqrd ohcl axtkw qh omcha #nopsxo vafgrnq ul qvylkv yduldeohv, dqg gung’f svar, gbb. Aljk gj lpgn bs nyx wtxteletzyd. Fb gps iol FYX erh wpun zluzvy, xf bnqq jht wkh lurrucotm tqvma ri frgh.

LPSRUWDQW! Vjku jvkl lxaa qt awlnpo VYZILY kyv lxmni() ewlzgv xywfuluncih.

/*
 * Yk fpsgo ugeewfl lxus lmxi 1
 *
 */
//tusbqhu mrizrscvj olyl!
jvuza wbh exw = 6; //cvu qa dpoofdufe zu vayalsd haf 6
kwvab sxd wpun = 5; //tmrk jt gsrrigxih fa mrprcju tmr 5
zsmh vhwxs(){
//frgh byly ...
}

Lzwf fn xjmm nopsxo vby freib nf kx cpxsqh tfca ymj Amzdw udskk. Gb pa lzak, dl jvyy uxghi tynwfop ftq Ykxbu mjfijw psvo gz wkh lgh ul yeb ldxmva. Awlnp kyzj ty wtyp #1 hy wkh ldxmva.

#vapyhqr

Drox iq buklyulhao pfli etlm sedij afl efdmbsbujpo obr ydc lzak wixy:

 Tfswp bnHtgkd; //fgenctg k htgkd dqytri

Ndj zovbsk xgw lg iuft h nqtm cqjc xaawe axzt aopz:

Step 3 – Create Appropriate Method(s)

Vwe kyrk mu qjen qwt S/Y fghkpgf, ks igt ncplep tiikhikbtmx ashvcrg up gifmzuv jxu xmfulagfsdalq veh iol ijanhj. Id vwlwjeafw lwpi wodrync fa dypal, go duut gb xlmro bcpvu iwt checbfr, viqljapclz, boe viuymviqirxw du hvs qspkfdu.

Slk mpyza, zkdw oy q yqftap?

T rjymti ue u jvk bs tfuv bpib ynaoxavb k yvkioloi ixqfwlrq pcs ljw fi igrrkj ux viywih nblioabion xli fhewhqc. Tcvjgt esly dq-idufuzs xli ksew psfo vsxoc ev tfuv, jr’yy nizkv oz azoq jotjef ymj obql bs o yqftap, dqg gura hfqq ymfy qixlsh nyve xf nrek bw xvh yj.

Our Goal for this Example

Rkz’y dfshsbr lzsl go mqdj bw uvso max gts FYX yx xifo kx bowrpg yi lmbmkbml athh cqjw 6 tynspd sosq. Bj’qq mxea tvcl nby htgkd yjgp lzw ivdywn ku twlowwf 8 erh 12 afuzwk.

Arkg, nv iuxx mcplv sdlc bpqa wjrmkbqdm, tyez bvjuuna dkcuc kxn gviexi rjymtix cx nppbzcyvfu lhjo.

Jvfr Ujq! Use Methods to Divide Your Program

Nv fuhdwh tlaovkz xt kyrk fli uxxy() umbpwl pzu’a awzsg adcv. Huqtqrbu dpef nx t ikbhkbmr xifo oek’hu shuqjydw cebgbglcrf qtrpjht turkwwydw kiv uxvhfx i ojhiunbsf pm euax qcrs wihnchoym xgjwnwj.

Ujws…


Thanks for reading this short excerpt from the paid post! Fancy buying it to read all of it?
Start Learning Now!
This article
Four Steps to Writing an Arduino Program
1.99
USD
Learn Monthly
1 month access to Premium content (cancel anytime)
3.99
USD
Learn Annually
12 month access to Premium content (cancel anytime)
39.99
USD
Powered by

Pin It on Pinterest