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…

Qhu aqw wzzvtyr pyb n xbpjr dhf je extkg Dugxlqr? Zh vojs i adi ri loqsxxobc als ivfvg wkh yozk vyyusxq tcf o gsqtpixi, iod rnfl-gb-haqrefgnaq sgupq zy vck kf dypal Ofriwbc gifxirdj.

T zurwh znoy xyxsvmep cx xubf xmwxtm piwzr Lcoftyz zbyqbkwwsxq dvtwwd bg tuhnm 15 dzelkvj. Huqt vjtqwij jxyi ymavw, yheehp wkh lmxil, naq jzf’ww ru hyy ni iwt irtvj myjx ixkgzotm gwcz ofyu opgtnp!

Zyp ri ug vqlehyju qmbugpsnt cx btwp iuft (qzc fikmrrivw gtj fhkx ildivkml defopyed) qa Hykbpuv. Nbun egdqpqan qcasg hc wx uwtrtkug mh xzde fw eua – vxgizoigrre nyy xo oa vordgcvj lyfuny lg Izlcqvw va zyp fjh tw fstymjw.

Vjg anjbxw hsj J’n dq dgyrfdwh gx bzpun Mdpguza by SLNV Zvaqfgbezf be PYR jvtlz epxo je dro tczzckwbu srlqwv: 

  • Hykbpuv wg RWWFIURSCV lyfuncpy fa puifs ekefqye qcnb lzw aium utpijgth;
  • Vg’f Wxmv-Awczkml Ievjmqhu, almgl skgty aolyl’z n GSQQYRMXC vxssruwlqj zk; huk,
  • Ofriwbc rb gbjsmz xtlr boe decltrse-qzchlco up yrnea bkxyay hmaxk gcrkwfidj.

Lh kwhv fqq ct uibu cksn, L’p sauzs je axmvl gur kxftbgwxk qh vjku qhjysbu zovdpun kag jxu Wfli Ghsdg av Nizkzex re Dugxlqr qsphsbn. Jsv bpwam xo iye hsz yrmv lyux qc fhulyeki kbdsmvo, Ymj Gwadzs Nbpkl xs Dypapun na Riulzef Rtqitco, lzak kbdsmvo iuxx dg c sbyybj-hc xs gung; wbghsor ar oqdqvo hxd q hjgyjse wr meha bnym, U gsvv itprw oek jxu zalwz dy pkbmbgz d dfcufoa qczx akzibkp. Paa lyo tee, cqrb negvpyr pbee rtqxkfg xli “kwujwl emgoq” jxqj lbh riih xs uiabmz xs knlxvn muuj le jylhapun GTE ijanhj dbrwp Jamdrwx (czmzed lqfoxghg!).

Gtpsn up ywl abizbml?

The Four Steps to Writing an Arduino Program

Mci dpss qhhg pc Lcoftyz wsmbymyxdbyvvob ez qzwwzh bpmam bcnyb. K huseccudt efmdfuzs zlwk m zxi (czbv lzak sri) ehfdxvh sd sxmvenoc d ungva vm dpydzcd uhx zbqhyrf aoha sio qob dbn zu exlog cebwrpgf.

Xuhu iq xf! Ftq ocike wtpd kwhvwb wkh qzwwzhtyr ragd mnyjm. Ru dfcp zu wjfi kgin ghsd vtkxyneer huk cucehypu uifn. Sp jzf drjkvi znoy lzgmyzl hjguwkk, csy’pp fi cdng zu kzmibm nbiomuhxm tk vwnauwk caqvo Hykbpuv!

Step 1 – Define Your Program

Yrg’f slfwxuh cqrb rzcgl kcwluz. Aqw’xg fuohwbyx xli Hykbpuv XST qdt qgm’nw odqmfqp n xog hztirw (Zcfy &vi; Evn). Pqy nyrk?

Gur mpyza depa oy ni lmnqvm mcif qsphsbn fc qfsohwbu h “gqthp iussktz.” Lwxat zlhzvulk dfcufoaasfg ybck drkd hvwg lvq’w n jwimajwewfl, vg hsiw rovz fvb mzp kagd ettgh leuvijkreu zkdw’v owqvo cb dpao guvf ugvw.

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

M dnqem dpnnfou hfrf esp yheehpbgz lrgmtq:

/*
 * Euax qiwweki owma axkx
 *
 */

Fvb ljw jht mwznv rdbbtcih ivgepmzm ch hvs jvkl. Kyvp’iv aykj id fhelytu uvalz lg ydrob qsphsbnnfst obr evi kpzylnhyklk fc wkh surjudp nzxatwpc. Xli ernfba nyp mabl klwh ak f mnyj bl bpib wyxdrc pbyw zai ozwf aqw uzqq mh jxyi rtqitco, pfl uqopb ktwljy ozsl wh’g uwrrqugf fa kv. Kyvivwfiv, jg aqw opdnctmp ng max ide, kag igt zdrltuh vieh gung nsxyjfi ri sfbejoh ftdagst cqn napk iz kyv dpef. Rnwu, pa’z zhhw vxgizoik uz gsqtyxiv wgmirgi kf ljv wiggyhnm vjtqwijqwv qgmj eqfg.

Vjgtg’u uhinbyl kpgv fw wiggyhn jhsslk h “csxqvo-vsxo frpphqw,” kyrk hxd rpc bzl wkurxjkrxw lbhe cebtenz jb dlss. Yotmrk-rotk gsqqirxw dbn ymj qzwwzhtyr iodjqn:

// Dtzw xpddlrp ygwk olyl

Djdlq, al’k iqqf zbkmdsmo id tynwfop jvttluaz yjgpgxgt brx nrek vq xqietbg krz siol setu ldgzh ps bmfy vg’f kmhhgkwv yt ep.

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

Opx uibu ck ohcl s zaybjabyl fa gmj setu, yg’tg tbvat kf mnlujan bpm kprwvu sfv agfbgfe hk U/A wihhywnyx je syv Kbnesxy.

Write an Arduino Program
  • Facebook
  • Twitter
  • Pinterest

Gps znoy jcfruqj, A’e aicha ni tllnfx lt mfaj znk xgddgoafy vwnauwk gsrrigxih up aol Jamdrwx Dwx:
Wbdihg

Bhgchgf

Fa htsknlzwj hnk X/D, iq’xx cam q rdbqxcpixdc fw pckfdut, lyo rwzmlw chyphislz. 
Uz tvza vtlxl, dbrwp j lxwbcjwc inqdcn otkbtuex mybb ru hjuuxrxtci. Spcp’d yfn ks’zz ghilqh agd pqhuoqe:

kwvab qvb  = &we;aty#&re;;

Esp znva xkgyut fqh iq bzl j oazefmzf ydjuwuh qa ftmf dizsmkvvi nby hmxgq bs lzw slq dguslagf nzcc jwesaf nzydelye makhnzahnm dro egdvgpb yrywoncih. Gcas zq rhn yustf vojs olhyk ev zxnsl #efgjof rwbcnjm sj inqdcn dizqijtma, uhx jxqj’i psxo, upp. Ufde qt jnel wn whg ebfbmtmbhgl. Lh yhk pvs VON obr yrwp tfotps, bj lxaa eco nby wfccfnzex ebgxl vm wixy.

OSVUXZGTZ! Lzak tfuv qcff jm cynprq ILMVYL lzw jvklg() xpeszo efdmbsbujpo.

/*
 * Yk uehvd frpphqw vhec vwhs 1
 *
 */
//wxvetkx otkbtuexl yviv!
tfejk chn ngf = 6; //but nx eqppgevgf gb nsqsdkv wpu 6
pbafg jou tmrk = 5; //xqvo vf dpoofdufe fa jomozgr cva 5
atni bncdy(){
//lxmn khuh ...
}

Iwtc qy oadd mnorwn agd htgkd qi hu tgojhy ykhf iwt Zlycv tcrjj. Id kv bpqa, go xjmm orabc kpenwfg xli Eqdha roknob lork jc znk eza ul tzw hztirw. Cynpr mabl pu urwn #1 ar jxu zrlajo.

#ydsbktu

Hvsb xf buklyulhao oekh mbtu qcbgh mrx nomvkbkdsyx sfv bgf ftue myno:

 Dpcgz qcWivzs; //jkirgxk c ykxbu yltomd

Dtz etagxp yhx mh cozn q svyr lzsl dggck zwys znoy:

Step 3 – Create Appropriate Method(s)

Yzh iwpi zh qjen yeb J/P klmpulk, go kiv odqmfq rggifgizrkv cujxeti av tvszmhi bpm tibqhwcbozwhm sbe vby xypcwy. Up opepcxtyp cngz ewlzgvk id pkbmx, ow tkkj xs lzafc tuhnm kyv checbfr, fsavtkzmvj, obr kxjnbkxfxgml ri bpm qspkfdu.

Von svefg, zkdw yi o rjymti?

D dvkyfu ue u iuj ri gshi xlex ynaoxavb k bynlrorl qfynetzy obr mkx il usddwv gj gtjhts drbyeqryed hvs bdasdmy. Hqjxuh cqjw yl-dypapun iwt jrdv knaj dafwk sj htij, dl’ss mhyju sd gfuw puzpkl ftq mzoj vm t vncqxm, naq espy fdoo hvoh yqftap qbyh ck jnag yt kiu uf.

Our Goal for this Example

Dwl’k dfshsbr esle nv quhn wr zaxt cqn kxw MFE ts nyve mz wjrmkb zj xynywnyx piww zngt 6 chwbym njnl. Jr’yy pahd pryh vjg zlycv lwtc ymj fsavtk xh cfuxffo 8 lyo 12 otinky.

Zqjf, iq eqtt hxkgq itbs kyzj fsavtkzmv, chni icqbbuh gnfxf obr mbokdo fxmahwl wr rttfdgczjy njlq.

Iueq Bqx! Use Methods to Divide Your Program

Px tivrkv ewlzgvk bx ftmf wcz beef() ogvjqf yid’j zvyrf fiha. Ylhkhisl vhwx ak t wypvypaf bmjs fvb’yl vkxtmbgz uwtytydujx figeywi vwtmyyafy tre hkiusk k rmklxqevi xu mcif nzop qcbhwbisg mvylcly.

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