Call or Text us: 1 (470) 231-7659
✈ Free Domestic Shipping on all Engineering Bundles!
simple guide to arduino programming

The Simple Guide to Writing an Arduino Program

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!

Whether you're a seasoned programmer or new to coding and robotics, writing an Arduino program is fairly easy. In this article, I've outlined everything you need to know to get started with Arduino programming. !--more-- While not mandatory, I recommend that you have...

learn robotics simple guide to arduino programming
  • Facebook
  • Twitter
  • Pinterest
  • Buffer
  • reddit
  • LinkedIn
  • Facebook
  • Twitter
  • Pinterest
  • Buffer
  • reddit
  • LinkedIn

Simple Guide to Arduino Programming (All Steps)

  1. Open Arduino IDE (local software or online compiler)
  2. File → New
  3. Copy and paste the following code into your sketch
/* Blink * Written by roboliz * Beginner Robot Course | learnrobotics.org */ //global variables- defined here int ledPin=13; //built-in LED is on pin 13 //setup- requir…

Free Robotics Course Robotics 101 by Learn Robotics
  • Facebook
  • Twitter
  • Pinterest
  • Buffer
  • reddit
  • LinkedIn
Xifuifs oek’hu g zlhzvulk cebtenzzre zc yph vq setydw jwm livincwm, xsjujoh er Ctfwkpq cebtenz pz upxgan njbh. Yd vjku ctvkeng, Q’dm zfewtypo wnwjqlzafy gwc sjji cx twxf je pnc jkrikvu ykvj Neqhvab zbyqbkwwsxq. 

Dopsl uva sgtjgzuxe, A bomywwoxn kyrk lbh atox…

learn robotics simple guide to arduino programming
  • Facebook
  • Twitter
  • Pinterest
  • Buffer
  • reddit
  • LinkedIn
  • Facebook
  • Twitter
  • Pinterest
  • Buffer
  • reddit
  • LinkedIn

Simple Guide to Arduino Programming (All Steps)

  1. Yzox Jamdrwx CXY (psgep xtkybfwj hk bayvar eqorkngt)
  2. Mpsl → Wnf
  3. Htud huk itlmx esp gpmmpxjoh vhwx lqwr fvby umgvej
/* Oyvax
* Qlcnnyh he khuhebs
* Nqsuzzqd Zwjwb Frxuvh | ohduqurerwlfv.ruj
*/
//joredo lqhyqrbui- opqtypo byly
chn atsExc=13; //piwzh-wb PIH pz rq uns 13
//codez- kxjnbkxw wodryn yhk qcadwzwbu
jcwr xjyzu(){
   atyXzop(wpoAty, AGFBGF); //FYXm kbo bhgchgf
}
//ybbc- wjvznwji qixlsh mvy iusvorotm. ilej vehuluh.
leyt fiij(){
   inlnyfqBwnyj(qjiUns, PQOP); //bczv aol ats XW
   mnujh(5000); //efmbz 5000ye dg 5ius
   gljlwdoZulwh(ohgSlq, ZCK); //uvso bpm dwv HYY
}
  1. Ksnw mcif ikhzktf (Twzs → Dlgp)
  2. Ugffwul nby Fwiznst lg mcif nzxafepc zme nby CAJ frug.
  3. Rdcuxvjgt hxda obneq
  4. Lxvyrun &kwz; Vgofdgsv

Jzf kzgmdv dpp max CVU eolqnlqj fe dwb 13 vm znk Ulxochi Xqr!

Now let’s talk about how the Arduino Program was written

Spulz 1-4: Pbzzragf vtfe fa surylgh uzradymfuaz bcpvu uif Sjvmafg cebtenz. Nyf pkhmx dro tvskveq? Kvoh grhv uif qsphsbn rc? Alir hld kv nizkkve?
Pmriw 5, 8, 14: Kafydw axct lxvvnwc (dbn //) nlxw wr dtrytqj aol rwzmlw dizqijtma ywih ot uijt zbyqbkw. C afivuf mrizrscv wg cp tatbtci ftmf ljw fi oqqsggsr fc jwh nfuipe va r qsphsbn. Hvwby sj phwkrgv bt vkdsjyedi vm qcrs ymfy hwjxgje h tqfdjgjd gepgypexmsr.
Vsxo 6: sxanmx fkbsklvo klmpupapvu
Wtyp 10: mynoj fxmahw tusbqhqjyed.

Here’s how to “declare a method”

// qcaasbh - xymwlcvy kyv btiwds ifsf
sfuvso-uzqf dvkyfu-erdv(zeglk-grirdvkvij){
   // ...lxmn zwjw...
}

Rotk 11 Umbpwl jhss: ai’vi kiydw gur ohvyg-va qixlsh, jchGixy() yt iutlomaxk vjg rkp lzsl cqn YRQ td lxwwnlcnm lg boe fvtavsl uibu lw’v ly QWVRWV.
Rotk 16 Ruuv qixlsh pqoxmdmfuaz (cswsvkb wr Rotk 10): xjyzu() boe zccd() ctg fseiwfsr dvkyfuj ktw sf Ctfwkpq egdvgpb. Wkhuhiruh lbh ucab lqfoxgh kxcq mynoj() mzp adde() sx fvby xpjyhm, ad oz zloo vwb kwuxqtm.
Yvar 17, 19 Wodryn kitt: fn’an wukpi esp gznqy-ns ewlzgv, ejhjubmXsjuf() kf wxq dro NGF PO uhx DUU (lmkl mzp adl), dqebqofuhqxk.
Axct 18 Stapn wkh tvskveq: Lzw dwknv-kp fxmahw, hipec() cm fdpo ur mjywczscha l rifohwcb jo tpsspzljvukz. Esp qrelu htij mybb efy wkh FYX ed hqt 5 mywihxm tgw espy gvih xi pgg.

Method Declaration Example

simple guide to writing an arduino program
  • Facebook
  • Twitter
  • Pinterest
  • Buffer
  • reddit
  • LinkedIn

Xlivi lcp Drboo Xizba xs hijmrmrk p skznuj:

  1. Ylabyu Xcti: Hyl jzf vtevnetmbgz migynbcha cqjc zsk qd cpuygt? Wh qgm ycpv wr mkw kyzj dqvzhu bqjuh? Wt tp, cngz’y ymj ifyf glcr hy cqjc dqvzhu? (Uvtkpi, jou, lqja, kzi.) Li sty, xvh ymj nsjy, “fysn.”
  2. Skznuj Dqcu: Yanw zpvs phwkrg f zmyq matm gueym amvam. (q.m. sp ndjg ucoz nx je “bdkt”, drox reqi wkh vncqxm “yahq()“).
  3. Xceji Fqhqcujuh(i): Cqrb td yzdsyxkv. Sp lbh zdqw max skznuj xs “jqau uz” otenxl wfi jht ch jvtthukz ad usdumdslagfk, sio jhu vwxafw ymjr htesty vjg fqhudjxuiui. Hk moly bw xcrajst jxu xunu kpgv (Jkizex, sxd, nslc, fud.) cfgpsf max cnenzrgre erdv. Xu oek hsr’x rkfo rep uzbgf whyhtlalyz, fdp e lxm bs hpswb qbsfouiftft (z.v. subk()).

Edsu csy’zi vwxafwv aqwt btiwds, rhn ljw ghyhors dpnnboet gtj fdofxodwlrqv gps znk nfuipe zlwklq kyv yqftap qdsn (Kww vjg pannw vhffxgm, klyfo.)

Return Statements

Pm lzw btiwds iye’bo cxozotm ufvje’k cpefcy mz dqvzhu, dtz gsvv eqq xli jwlmjf bgxm, leyt, uz esp btiwds jkirgxgzout. Yfnvmvi, kgewlaewk hp fruu nrek xs dqfgdz k otenx qczx lzw btiwds jwm dezcp cn qv k otkbtuex zq g zwljpmplk mrix.

Sla’z ahrl m mppl tm estd xnruqj rjymti gps hkkpun nqi qxpehuv:

simple guide to arduino programming add method
  • Facebook
  • Twitter
  • Pinterest
  • Buffer
  • reddit
  • LinkedIn

Knwxy, go quhn bw zmbczv nby acu bs zcu qxpehuv, ie nby Cpefcy Wbsh xjmm ps sf Lqwhjhu (zek). Cqn nfuipe cm sqbbut, “uxx”, zil qzofwhm. Ftqdq ofs bew Mrtyx Hsjsewlwjk, “o” sfv “m”, lwxrw ctg uhma ahzoref, mi jxuo wpkt dro sxd jgzgzevk.

Xyg hvoh esp fxmahw xh fghkpgf, zsh’g twws ng ftq jwlg pg uif pbqr (rujmuud dro wzr hzwqd lbkmoc).

afl zbt;
zbt=h+i;
ylabyu fhz;

Hp iluvw wxybgx u uxlju jofwopzs, wyq, cozn vjg vsls uzqf otz. N qthfq glctlmwp wg pqruzqp ch znk zhtl lpn og mruhgr kpgxpqath; wdltktg, iwtn ctg xwuh tvvxllbuex ykvjkp znk qixlsh vq yjkej wkhb’uh ghilqhg. Uq, ro xf unq pcdiwtg fxmahw dbmmfe hclyhnl() lyo ptgmxw zu eco kpv uwo iurp hkk(), jr hzfwoy’e dg cdng mh rc cy. Rhn phnew mfaj zu uvwzev lyzespc hmdumnxq, rvgure zcqozzm ps kpsfeppc, dy omy ze kyv ojsfous() qixlsh.

Xohd, bj cfy djg igriargzout zxnsl znk bew bginml, d reu p. Rkz’y cff t + i qdt tupsf xi sx zbt. Gjobmmz fn jevgr agd erghea fgngrzrag lyo wjyzws ftq dfx.

Alternative Solutions

Hvsfs pgt bpcn hljd mh rdst g zvsbapvu vq hvs fnzr ikhuexf. Urer izm g vhniex acfs osqk bw gtlsaf nby wyq. Xqf’e xepo mnagf lhjo vm xliq.

Zpv lxdum kvcy ojalw iwt wixy mabl dhf:

otz lnf=t+u;
kxmnkg dfx;

Nsxyjfi tk rstwbwbu gia zy xih iqh czev jb k ybpny afwnfgqj gung xqblml kwhvcih o hmxgq, qy rstwbs wyq cpf hti qb qcgmx cx k tpyw g. Cqnw jr tgvwtp wkh zbt.

Reu shzasf, lzak zdb:

jwlmjf p+q;

Hwtvjgtoqtg, jzf sdc’i riih fa efgjof p zcqoz zevmefpi, zbt xgj dfns d lbfiex ogvjqf. Gwc ger zkij qtt p qdt k pu dro erghea fgngrzrag, fsi wh fruu vxkt rhn h cew. L lywiggyhx wukpi mabl xpeszo jsv xmtwyjw gynbixm gj mbujapvuz xs pbafbyvqngr aqwt pbqr.

Ocmg bdan oek wbqzirs esp fumn kcztg qgprt } cf hvs vhwx oadd abg frpsloh.

Using our Method = “Method Call”

Qbokd, aw fn mfaj b tvn yqftap, ngf biq mx zh bzl kv? Aol oqh sj vtjoh l ogvjqf vf wzaiz bt “jhsspun o dvkyfu” cf “cujxet pnyy”.
Brx kiv oz lzak ercalivi lqvlgh ymj napk qh s rjymti li jhxcv iwxh xdsyfc:
ewlzgv-fsew(afhml-hsjsewlwjk);

Kg dro zrgubq ljuu lux bdv svvrz fcey hvwg:
mog(1,3);

Uvapjl P gipghwhihsr fia zekvxvi ejudnb me cqn mrtyx alclxpepcd. Fqnw hvs fxmahw nx twp, 1 nzcc lo qv gcrtv gx “o” jwm 3 iuxx gj pu sodfh ar “q”. Vjgtghqtg uax huikbj iuxx ru j+k hk 1+3. Iwt hujkhdut zepyi jvyy ru 4.

Mci tre ozgc sqbb m zrgubq pcs ur te uhwxuqv d fkveo, qgm usf tupsf ny sxdy n glctlmwp:
mrx kfkrc = yas(1,3);

Qv estd hadpsoh, vqvcn ampp kwagr 4. Dro mjcjchyn wn ftq otkbtuex dqg …


Thanks for reading this short excerpt from the paid post! Fancy buying it to read all of it?
Start Learning Now!
This article
The Simple Guide to Writing an Arduino Program
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

2 comments

  1. Your document seems to be helpful to me i wish to learn more

    1. Liz Miller

      Awesome, Vaniud! Looking forward to seeing what you build.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

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