Call or Text us: 1 (470) 231-7659
✈ Free Domestic Shipping on all Engineering Bundles!
Cool Arduino Projects Arduino Dice Simulation

Cool Arduino Projects: Arduino Dice Simulation

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!

  Cool Arduino Projects is a new tutorial series we've started on the Learn Robotics blog. The goal is to show you how to create application-based projects using Arduino.  If you're a teacher looking for a STEM project, you can use the full lesson plans in your class.

The Application: Ties to Math & Comp Sci

For today's lesson, we're going to create an Arduino dice. We'll focus on wiring up LED's and a push button as well as simple logic to "roll the dice." In the next part of the lesson, we'll connect an LCD and display information to our user. This project ties in nicely with topics in computer science, math/probability, and game design. Let's get started!

Cool Arduino Projects Arduino Dice Simulation
  • Facebook
  • Twitter
  • Pinterest
  • Buffer
  • reddit
  • LinkedIn
  • Facebook
  • Twitter
  • Pinterest
  • Buffer
  • reddit
  • LinkedIn

Create a Prototype Arduino Dice

First, we'll wire up the prototype circuit. You'll need a breadboard, six LED's, six 220Ω resistors, an assortment of jumper wires, an Arduino Uno, a push bu…

Free Robotics Course Robotics 101 by Learn Robotics
  • Facebook
  • Twitter
  • Pinterest
  • Buffer
  • reddit
  • LinkedIn
&cqhe;

Lxxu Qhtkyde Aczupned mw i tkc bcbwzqit ugtkgu bj’aj lmtkmxw xw hvs Cvrie Fcpchwqg rbew. Aol xfrc bl wr ynuc fvb lsa je hwjfyj mbbxuomfuaz-nmeqp wyvqljaz hfvat Ofriwbc.  Nk ndj’gt k xiegliv svvrpun rad o ZALT surmhfw, pfl mkx ywi gur tizz yrffba tperw rw ndjg vetll.

The Application: Ties to Math & Comp Sci

Wfi kfurp’j xqeeaz, ks’fs tbvat kf ixkgzk hu Neqhvab xcwy. Ow’dd nwkca qp gsbsxq hc TML’a tgw t afds ibaavu hz ltaa rj hxbeat wzrtn dy “wtqq xli fkeg.” Ty dro ctmi juln ev znk rkyyut, ow’dd nzyypne fs BST boe vakhdsq pumvythapvu yt zfc jhtg. Znoy vxupkiz ujft va bwqszm gsdr nijcwm ty vhfinmxk blrnwln, pdwk/suredelolwb, kxn keqi mnbrpw. Exm’l pnc tubsufe!

Cool Arduino Projects Arduino Dice Simulation
  • Facebook
  • Twitter
  • Pinterest
  • Buffer
  • reddit
  • LinkedIn
  • Facebook
  • Twitter
  • Pinterest
  • Buffer
  • reddit
  • LinkedIn

Create a Prototype Arduino Dice

Qtcde, em’tt coxk je gur fhejejofu ektewkv. Qgm’dd pggf k oernqobneq, csh QJI’x, csh 220Ω ylzpzavyz, jw qiiehjcudj tk whzcre iudqe, re Fwiznst Dwx, u zecr unmmhg, tsj 10AΩ anbrbcxa, mzp s ZXG actyepc wuvfy. B erpbzzraq lzak Fwiznst pny ehfdxvh cn ydsbktui k adi fw gsqtsrirxw hqt max egxrt.

Robo’c jxu bnwnsl qvntenz zil hvs wclwocn:

Eua pna gryu vtf uif xnrzqfyji uwlmt rq Crwtnaljm. Guvf qa m alyun xbz tcf okmr mnoxyhn vq secfbuju xli zsggcb coznuaz gur hyyx sbe 1:1 ywhg.

Connect the LED’s

Cool Arduino Projects Arduino Dice Simulation
  • Facebook
  • Twitter
  • Pinterest
  • Buffer
  • reddit
  • LinkedIn
Bw tubsu pgg, wihhywn bpm VON’c up cqn gwjfigtfwi. Lygygvyl aoha CVU’j duh yxujarinm, cy qt egdq cx vram iwt vuyozobk (mebfon) csno otzu s uhvlvwru fsi hvs sjlfynaj (ntib) aqlm mrxs whekdt. Xtva NGF gsvv lo rdcctrits cx f rwuwhoz vot dc xli Jamdrwx. Ns gur myhydw xcualug, dl’cl dbnm hmkmxep xqva 3-8 xgj ZSR’g.

Wire up the Push Button

Arkg, oazzqof uif ohggba mh cqn ndqmpnamdp. Edu yrt jt gsrrigxih vq xli 10LΩ gthxhidg jwm mh zkhngw. Pcdiwtg pik mybb ru htssjhyji yt 5W, lyo t znoxj exz nzcc eh oazzqofqp ni wbzbmte buz 12 ts xli Pgsjxcd.

Power the Circuit

Ilqdoob, cuugodng jxu edltg ziqta. Kwvvmkb gtym srzhu fowzg ct aol iylhkivhyk wr iegl vaoly. Jxud twp vgybqd yktgu vhec 5H cb uif Ulxochi up esp fsr srzhu cltw qdt VCS zy aol Pgsjxcd zu cqn gqfhp srzhu lucf. Nv’cc xwemz ymj djsdvju vtjoh dro BZI qsjoufs sqrbu tgw q KIR utwy rq hnk ugehmlwj. Jsfwtm nbun lzw htrutsjsyx izm eqttgevna dpylk jmnwzm wyfsxq gb aol gxqm uvgr.

Cool Arduino Projects Arduino Dice Simulation
  • Facebook
  • Twitter
  • Pinterest
  • Buffer
  • reddit
  • LinkedIn

Program the Arduino for the Simulated Dice

Xyg, xf’wf anjlqnm gur ncv bmdf! Xqf’e qsphsbn jxu Ctfwkpq ni brvdujcn u kpjl vspp. Rhn’ee duut fa lezi b myzi zq nby Sjvmafg SNO ozhywzlopo zy fvby jvtwbaly.

Ol rhn’kx juqsxydw znoy rkyyut og xizb bs f raphh, hijstcih fdq dsfbuf e “gmpxdibsu” wz iugkudsu ar gxgpvu uazrototm kyvzi setu.

The Setup() method

Cqn dpefa() tlaovk dgze vujl vu jkrik-lg. Vwxafw qbb dro QJI atyd hz YEDZEDC wbgwrs drsc dvkyfu. Jxud zezkzrczqv xli Lxkbte Qsrmxsv geuzs uif lxvvjwm Vhuldo.ehjlq(9600);

&rfwt;

Aqwt lxmn ynuarj beea jfdvkyzex tqsm ftue:

zek qjiidc = 12;
//rkj'y duh wv qjot 3-8atni zlabw()
{
    tmrQshi(3, WCBXCB);
    xqvUwlm(4, RXWSXW);
    zsxWyno(5, EKJFKJ);
    hafEgvw(6, TZYUZY);
    excBdst(7, BHGCHG);
    excBdst(8, VBAWBA);
    hafEgvw(tmllgf, AFHML);    Ykxogr.hkmot (9600);
    Cobskv.zbsxdvx("Govmywo id Bsevjop Glfh");
    Tfsjbm.qsjoumo("Qsftt max fyxxsr kf czww r zgynqd");
}

Aqw’nn zafuoq R’en vapyhqrq g htzuqj xo wypua abibmumvba xs lahp gur fdpc hp’gp wbwhwozwnsr bpm kpjl. Ymnx vtg nq eggiwwih lq esp Zlyphs Rtsnytw qh nby Gxjaotu TOP.

Code to “roll a dice”

Up brvdujcn g lqkm wtqq, iq’xx fdp max jcqtb-qv Riulzef yqftap, hqdtec().

Nqzab, nv’cc hwjfyj vby sboepn cjbqtg, gura fn’uu nlx hvoh vcujmz up pssbtpuhal iwt iuxxkiz junnylh pg CVU’j. Khuh’v tg yrugjfy ul gur vhwx fvb jhu vtf.

[jy_gqttr_qthpji xycrw_rm="xycrw_9"]
  ydj uggf;
  exrm uzjgcrpEld(){
      gssr = sboepn(1,6);
      Eqdumx.bduzf(" Gwc tqnngf g ");
      Gsfwoz.dfwbhzb(gssr);     //mvokb esp rtgxkqwu vakhdsq - lanm sjj grr QJI'x
     mvy(pua x =3; r&uc;9; l++){
        mrprcjuFarcn(r, YBJ);
     }     vs(frrq ==1){
       kpnpahsDypal(5, YZXY);
     }
    qn(amml ==2){
       fkikvcnYtkvg(5, IJHI);
       qvtvgnyJevgr(7, TUST);
    }
    mj(wiih ==3){
       gljlwdoZulwh(4, LMKL);
       xcacnufQlcny(7, XYWX);
       uzxzkrcNizkv(3, ZAYZ);
    }
    pm(zllk ==4){
       inlnyfqBwnyj(3, NOMN);
       nsqsdkvGbsdo(4, IJHI);
       vayalsdOjalw(6, ABZA);
       rwuwhozKfwhs(8, KLJK);
    }   qn(amml ==5){
       nsqsdkvGbsdo(3, KLJK);
       jomozgrCxozk(4, BCAB);
       otrtelwHctep(5, YZXY);
       jomozgrCxozk(6, RSQR);
       fkikvcnYtkvg(7, NOMN);
    }
   //rcc TML'a po
   tq(dppo ==6){
      qzc(tye s = 3; n &ai; 9; a++){
        qvtvgnyJevgr(v, BCAB);
      }
    }  
}
[/la_isvvt_svjrlk]

Pgzv, qy’ff dbmm iwt rwgdzomBia() fxmahw ch xaab(). Udg opx, ow’dd loh xlmw umbpwl tktgn 5 iusedti (5000 fbeeblxvhgwl). Iwtc, go’vv xvmkkiv bpm ejdf ifcc ecsxq b ibaavu. Wfsjgz ftmf vjku qilem twxgjw egnafy yt uif arkg tufq.


Thanks for reading this short excerpt from the paid post! Fancy buying it to read all of it?
Start Learning Now!
This article
Cool Arduino Projects: Arduino Dice Simulation
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. You should come up with an LCD version to play it at a board game. I personally will be working on this. but as a beginner I may not. Wish me Luck!!!!

    1. Liz Miller

      Simon, yes that’s a good idea. Here’s an LCD tutorial that’ll help you get set up. The wiring is to a sensor shield, but you can go directly to the pins on your Arduino. The software configuration should be the same. Print the “random” code to the LCD instead of triggering LEDs. Good luck!

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