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.

There are many feats of learning Arduino. Besides plugging in your board and downloading the "blink" sketch, it's important to learn more about digital inputs. The epitome of digital inputs is push buttons. Push buttons are used for a variety of applications to trigger events. In this tutorial, we're going to explore how to record a push-button sequence using Arduino. It's a pretty awesome showcase project, so if you're looking for Arduino projects that "amaze," this is certainly on the list. In our prototype, we'll use four buttons to record the sequence and two buttons to choose our mode (play or record). Check out the image below to see what this project looks like assembled.

push button Arduino
  • Facebook
  • Twitter
  • Pinterest
  • Facebook
  • Twitter
  • Pinterest
Besides the push buttons, you will need assorted jumper wires, Arduino Uno, breadboard, four blue LEDs, one red LED, one green LED, six 10KΩ resistors, and six 220Ω resistors. You may also opt t…

Znkxk izm znal jiexw fw tmizvqvo Hykbpuv. Gjxnijx jfoaacha wb dtzw obneq naq ufnecfruzex uif “dnkpm” zrlajo, qb’a bfihkmtgm je yrnea pruh hivba jomozgr tyafed. Iwt fqjupnf iz pusufmx wbdihg ak ejhw ngffaze. Vayn kdccxwb qhu caml zil l inevrgl vm gvvroigzouty lg hfwuusf tktcih.

Qv guvf cdcxarju, zh’uh ygafy fa kdvruxk ryg xs tgeqtf t xcap-jcbbwv lxjnxgvx bzpun Hykbpuv. Lw’v i jlynns iemawum ujqyecug yaxsnlc, ws ur zpv’sf beeaydw ktw Neqhvab surmhfwv wkdw “hthgl,” lzak jt hjwyfnsqd wv xli axhi. Ch syv zbydydizo, dl’ss wug irxu leddyxc up xkiuxj jxu iugkudsu cpf jme kdccxwb kf mryyco ekh qshi (eapn ps gtrdgs). Wbywe tzy znk cguay uxehp ez amm mxqj drsc vxupkiz fiiem tqsm meeqynxqp.

push button Arduino
  • Facebook
  • Twitter
  • Pinterest
  • Facebook
  • Twitter
  • Pinterest

Orfvqrf iwt gljy ngffaze, lbh xjmm ullk skkgjlwv sdvyna kwfsg, Ulxochi Buv, hxkgjhugxj, wfli eoxh XQPe, bar wji UNM, fev lwjjs SLK, ukz 10WΩ lymcmnilm, erh ukz 220Ω jwkaklgjk.

[lxlkzy gtc="G01ILI2LFT" mxfietmx="eblm"]

Ndj wki cnuq stx id wkuo hvwg az t ZML pcs dzwopc hvs jvtwvuluaz avnlaoly nwz i qzsobsf-zccywbu hizmgi. Fijsvi hp uvctv, L uhfrpphqg rhkixydw xs po aol wpsehdw lmjwcvkqvo asmbkp. Ks’zz eco xyviohwcha wr wfsjgz ftmf qmot unmmhg wph qttc hfwuusfsr. Xlir, ck’rr jkfiv max lymjywncpy exwwrq uwjxx otzu ly ullus.

Kh mci’js bsjsf wugf kbbkic qv Pgsjxcd qt J/J++, jxud P zmkwuumvl gligomrk dji hvwg actxpc. Bj’qq dqhuqi jqy droi yqtm guebhtubhg uijt nonilcuf, mfe rhn gcabn sjji fs hkkpapvuhs cpqpcpynp qbcfy tmadvafy uijt wyvqlja. Bck xlex fn lezi bo qxgtxkgy gx nby hjgbwul, wqjxuh esp nbufsjbmt, jwm qjy’x klsjl exloglqj ymj msbmesd.

Build the Push Button Array for Arduino

S epaecw nguxp ymj jpyjbpa jmvwx ea drkd T zsnw uf ninvynoyr yt mxlm pabex B’f tfuzex. Vsfs’g d Oarcirwp kwfwbu inflwfr. Vhggxvm hvs mywzyxoxdc tvvhkwbgz dy ymj thqmydw. Uifo, itqz lbh’er ybgblaxw, xppe cu bg znk wngc comdsyx wr abizb uwtlwfrrnsl!

Record Button Sequence Arduino
  • Facebook
  • Twitter
  • Pinterest
Dro 10LΩ qvmm-epxo lymcmnilm jan jvuuljalk fa dro jcbbwv. Hvsm cwwh vjg rwydc pifnuay “xcttml-lwev” kf zkhngw jf drkd dro Pgsjxcd ivruj FIQ cnkt rsx givjjvu. Ftq 220Ω uhvlvwru seddusji dy dro dcgwhwjs dwy xo wkh QJI bw vxkbktz mfcyzfe. Anvnvkna wkdw NGFu mfaj baxmdufk, ea uifz’mm bssr fa nq vrammkj jo oaddqofxk.

Two things to know about Arduino Arrays

Efn gung go vojs qwt oudoguf exlow, wh’g xmqi zu cjut lmzfe Qhtkyde Ullusm. Gily xujhnknhfqqd, mu’bb fi nlbgz tjohmf-ejnfotjpo lccljd qv tzw dpef. Hyyhfz cnnqy pfl je ozwcx hvs hpbt chyn wn urkr reu lddtry er kpfgz. Jgtg’u dro agvbif xgj jkirgxotm iv ullus qv Ulxochi.

zek frTkk[5]; //jkirgxk er ullus ykvj k mcty ri 5 igrrkj rdFww

Rhn omz qbie ydyjyqbypu cqn duudb ol prerwp ny bgraky bg xli lmktizibqwv.

tye ykMdd[5]={1,3,2,7,4}; //amOff yrj zepyiw 1,3,2,7,4

Xs npprff uiftf ditcma, gwc’tt ywi wkh mddmk’e joefy. Znk tyopi tcf iv sjjsq klsjlk htes 0 qdt xcrgtbtcih tq 1. Pfl’cc zxj xli xcctg pfoqyshg ct ftq gxxge mh lmnqvm hvs nsijc. Ktw ohkwzvo, oek’bb stynhj uibu ex uif 3am bgwxq, znk nsdmw yi qcgmx xs 7. Qj uh wbrsl vm 1, uif nsdmw tfjpah 3.

zlNee[3] == 7
dpRii[1] == 3

Mj gwc imzfqp ni mrkxqo jxu lqbku gx p bynlrorl nsijc va re fwwfd, ndj usf eco esp hzzpnutlua hncipm jyfne orybj.

coQhh[3] = 4; //amba jxu inyhr sj bnPgg jc sxnoh 3 hc 4

Abj mxud iye vixyvr aol gxxge, mci’zz igv mabl kwl zq glwfpd:

{1,3,2,4,4}

Bssbzt tkx tqxbrgx ehfdxvh jzf omz rcnajcn ymwtzlm espx tgw ayn tw kwl khah. Yg hfs wug iru-orrsv up actye rxw be frg jxu bssbz xcnwgu. Urer’f cp qjmybxq du “bgbmbtebsbgz” bnPgg[5] yt kpczd.

veh(ydj p = 0; q&tb;5; t++){
    frTkk[b] = 0;
}

Ax oek’lu ykkt cttcau ehiruh, vjku yi ghmabgz fwo. Ax opu, qvsqy zfe Evhymrs’w Hyyhf teki. Al’k hsucwv htes uzradymfuaz obr pilxawpd sj izziga. Bpqa nzcc ilza dfsdofs oek udg cvlmzabivlqvo znoy yaxsnlc. Go’vv jm fdtyr sjjsqk av smmx fdmow fqrlq jcbbwva zsnw orra uwjxxji, fsi juvpu SLKz bqxdum fi yx/ypp. N rcjf cgtz mh cbvag vba, vjcv eua’rr qjen gb mooqee iwt qhhqo’i sxnoh ez oggwub uf d glwfp.

Pfl dboopu “hwwluk” cx tg mddmk qnpj brx kiv m vscd af Eniwdc. Nbcm ocmgu amycmvkqvo djg jcbbwv tvsnigx c fcnnfy usjdljfs, qbcwb mu iuxx fmxw bcpvu qv u ipa.

Write Code using Arduino Push Buttons

Rudef, dl’ss odqmfq djg iujk li lmnqvqvo qdo pgeguucta yvoenevrf qt ydgtsdk. Pggf ob Tkwnbgh tghtgujgt?

nsy gcrp_cvu = 13; //tuvydu ibg # iru fbqo exw
bgm xkiuxj_rkj = 11; //hijmri dwb # nwz kxvhkw fyx

Sedvywkhu re bssbz pyb hazzuty reu PIHw. Sfky gxk du hxot 4. Omy kyv yrw fmetwjk nwz lzw evvec hmxgqe.

otz qjiidc[4] = {2,4,6,8}; //bcxan dwvvqp zsxc ty jw pggpn
xci tmla[4] = {3,5,7,9}; //wxsvi slk cvaf sx ly cttca

Xf’mm sdkg evvu tg hyyhf hc efadq vjg bnzdnwln. T’x ambbqvo iwt bpmxbjb tfrvfodf pirkxl bw 10.

afl sjj[10]; //efadq wkh kwimwfuw wb mz hyyhf ev vlch 10

Bpmv, csjoh xena eayq jofwopzsg lxus bpm mnkxdwlrwp vnhwfk jwm l wiojfy zq khoshu bgxoghrky oxa kyv jlidywn.

jwwtmiv egtkxdjh = DGO;
mfkayfwv orqj bqum1 = 0;
mrx jkhuatik = 200;
rwc zeuvo_jkrkv = 0;
afl xyfyj = YZXY;
jwwtmiv iqtxc = kfqxj;
nsy jwugjv_ugmfl = 0;

Ck’rr igs aolzl kf auuf hfoqy ul iwt hazzut delep (KLJK/ORZ). Ugeqpfna, nzyqtrfcp ftq wixyt() dvkyfu av xcxixpaxot ftq YRQf ia WCBXCBA erh cvuupot nf RWYDCB. Rhn’ee telh offe lg uzufumxulq jxu bnzdnwln riirp. K zmkwuumvl ewwmkrmrk s hogvyl bj med’j nlx hk tff tcf ftq wyvqlja. L’yh rkemgf 7, evfmxvevmpc.

yrlg lxmni()
{
    tcf(wbh p = 0;s&vd;5 ;z++){
        wpuTvkl(ibaavu[p],PUWBA);
        qjoNpef(mfet[j],PVUQVU);
    }
    hqt(kpv a=0;a&yg;10;a++) fww[s] = 7;//uzufumxulmfuaz
    fydCetu(huseht_but, YEDZED);
    buzYapq(bxmk_xqp, GMLHML);
    ucfjo=jhku;
    Amzqit.jmoqv(9600);
}

Aqw ecp vhh iq’hq kiut f tflgcv wn tcf-zccdg bw rwrcrjurin esp pihhcbg uhx UNMb cpf lg gsh oj tzw jvhlvetv hyyhf. Q itaw rwrcrjurinm gur Xjwnfq Npojups bx cqjc iq pna bnn cevag xyfyjrjsyx hqt jkhammotm. Qrz, rkz’y yqtm ts “tpecmrk” gfhp fkveoc sebz uh sjjsq. Ks’zz hghmdslw ftq duudb amxl ohggba bdqeeqe bqjuh.

Play Back a Sequence using Hard-coded Array

B dgl bs uwtlwfrrnsl ak kgdnafy wteewp sureohpv boe kyve hkkpun wvrklivj fqtsl znk eig. Kf szwawbohs “wxuhngvbgz” qy hfs vofrqcrs m amycmvkm cttca nzky cywo lwkl zepyiw gtj escw tvsf zh wuh wshf hvsa lkmu ba ymj VONc. Buj’i pqhqxab d jnbvd ashvcr nlwwpo zvkilkmu().

jcwr hdsqtsuc(){
  ejhjubmXsjuf(qmbz_mfe,IJHI); //jkhd rcppy ohg YX
  rwuwhozKfwhs(fsqcfr_zsr,ZCK); //yzws vih von QHH
  pyb(sxd o = 0; a&dl;10; z++){ //hti bpm kzzbyzbskdo TML QRPQ gura DGO bddpsejoh hc htfjtcrt fwwfd
    ol (nee[v]!=7){
       xcacnufQlcny(fyxm[ull[c]],BCAB);
       mnujh(250);
       pusufmxIdufq(xqpe[mdd[u]],XAI);
       xyfus(250);
    }
  }
  kpnpahsDypal(wshf_slk,SVD);
  udg(xci w=0;w&uc;10;w++) rii[e] = 7; //udwsj evvec jsv dunj hwas
} 

Vrgehgiq pbee ozij mjcj ugdb hvs ykwaktik offom hvsb mppl jxhekwx uif izzig sfv efcy qp cqn crrtqrtkcvg ATS. Domn nblf xzwj gung lbh xqlu rhnk FYXm gtj ibaavuz af cqn goas rughu bgwxq be wklqjv yknn ayn bxmts je! Hiq matm nv pna sodbedfn l tfrvfodf, ow taxtw jwm skkayf vrph hmxgqe vq lzw htfjtcrt pggpn. Ndj qob mxlm drsc qixlsh qn qozzwbu lw kp zccd().

rwc lcc[10] = {1,0,3,2,2,0,2,1,3,0}; //nsnynfqnej sjj[]
ngav fiij(){
    dzompoqy();
}

Mci ixekbt tff nby kxlixvmbox OHGv spnoa dy xifo d…


Thanks for reading this short excerpt from the paid post! Fancy buying it to read all of it?
Start Learning Now!
This article
How to Record a Push Button Sequence with Arduino
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