<?xml version="1.0" encoding="UTF-8" ?><!-- generator=Zoho Sites --><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><atom:link href="https://robolark.com/blog/tag/arduino-coding11111/feed" rel="self" type="application/rss+xml"/><title>Robolark - Blog #arduino-coding1111</title><description>Robolark - Blog #arduino-coding1111</description><link>https://robolark.com/blog/tag/arduino-coding11111</link><lastBuildDate>Sun, 29 Mar 2026 09:07:10 +0530</lastBuildDate><generator>http://zoho.com/sites/</generator><item><title><![CDATA[DIY Arduino Dice Roller using Vibration Sensor and LCD Display]]></title><link>https://robolark.com/blog/post/DIY-Arduino-Dice-Roller-using-Vibration-Sensor-and-LCD-Display</link><description><![CDATA[<img align="left" hspace="5" src="https://robolark.com/Digital Dice_Robolark.png?v=1752086285"/>Build your own digital dice roller with Arduino Uno, a vibration sensor, LCD display, and buzzer! Shake to roll and display a random number from 1 to 6. A perfect beginner project to learn about sensors, I2C communication, display output, and random number generation.]]></description><content:encoded><![CDATA[
<div class="zpcontent-container blogpost-container "><div data-element-id="elm_PlwmrT8zRPy601kjj5-kzQ" data-element-type="section" class="zpsection zpdefault-section zpdefault-section-bg "><style type="text/css"></style><div class="zpcontainer-fluid"><div data-element-id="elm_idpq1OAGRSKAqwb-hHllMQ" data-element-type="row" class="zprow zpalign-items- zpjustify-content- "><style type="text/css"></style><div data-element-id="elm_zEEkJaw4Q7ujw1hL6i__xg" data-element-type="column" class="zpelem-col zpcol-12 zpcol-md-12 zpcol-sm-12 zpalign-self- "><style type="text/css"></style><div data-element-id="elm_S0EbtOqvS4-WaditeUkyyQ" data-element-type="heading" class="zpelement zpelem-heading "><style></style><h2
 class="zpheading zpheading-align-left " data-editor="true"><div style="color:inherit;"><div><span style="font-size:16px;">Have you ever wanted to build your own digital dice roller? In this project, we’ll use an Arduino Uno, a vibration sensor, and an LCD display to simulate a dice roll. Shake the device and watch it roll a number from 1 to 6—just like a real dice! A buzzer will beep to confirm the roll. Let’s dive in!</span></div></div></h2></div>
<div data-element-id="elm_9EDUghtzQ6m5OmpjgxDeJQ" data-element-type="text" class="zpelement zpelem-text "><style></style><div class="zptext zptext-align-left " data-editor="true"><p style="margin-bottom:12pt;"><span style="font-size:15pt;">Project Overview</span></p><div style="color:inherit;"><div>This project mimics a 6-sided die. When you shake the device, the vibration sensor sends a signal to the Arduino Uno, which randomly generates a number between 1 and 6. That number is displayed on a 16x2 LCD screen, and a buzzer beeps to indicate a roll is complete.</div><br/><div>It’s a fun and beginner-friendly project that introduces you to working with sensors, I2C communication, random number generation, and user interaction via sound and display.</div></div></div>
</div><div data-element-id="elm_sJgOSsLW9rWmPMYNDdMhhg" data-element-type="text" class="zpelement zpelem-text "><style></style><div class="zptext zptext-align-left " data-editor="true"><div style="color:inherit;"><div><span style="font-size:24px;">Components Used:</span></div><div><span style="font-size:24px;"><span style="color:inherit;"><ul><li style="font-size:11pt;"><p><span style="font-size:11pt;font-weight:700;"><a href="https://robolark.com/categories/boards/313657000000479001" title="Arduino Uno R3&nbsp; &nbsp;" target="_blank" rel="">Arduino Uno R3&nbsp; &nbsp;</a></span></p></li><li style="font-size:11pt;"><p><span style="font-size:11pt;font-weight:700;"></span></p><p><span style="font-size:11pt;font-weight:700;"><a href="https://robolark.com/products/programming-cable-for-arduino-uno-and-mega/313657000000678037" title="Programming Cable for Arduino Uno" target="_blank" rel="">Programming Cable for Arduino Uno</a><br/></span></p></li><li style="font-size:11pt;"><p><span style="font-size:11pt;font-weight:700;"><a href="https://robolark.com/products/lcd-16x2-i2c-soldered/313657000007461429" title="16x2 LCD Display with I2C Module" target="_blank" rel="">16x2 LCD Display with I2C Module</a><a href="https://robolark.com/products/lcd-16x2-i2c-soldered/313657000007461429" title="16x2 LCD Display with I2C Module" target="_blank" rel=""><br/></a></span></p></li><li style="font-size:11pt;"><p><span style="font-size:11pt;font-weight:700;"></span></p><p><span style="font-size:11pt;font-weight:700;"><a href="http://robolark.com/products/d5ff58e0fb/313657000002731573" title="Vibration Sensor Module" target="_blank" rel="">Vibration Sensor Module</a><br/></span></p></li><li style="font-size:11pt;"><p><span style="font-size:11pt;font-weight:700;"></span></p><p><span style="font-size:11pt;font-weight:700;"><a href="https://robolark.com/products/5v-active-buzzer/313657000000678442" title="Piezo Buzzer" rel="">Piezo Buzzer</a><br/></span></p></li><li style="font-size:11pt;"><p><span style="font-size:11pt;font-weight:700;"><a href="https://robolark.com/products/jumper-wires-male-male/313657000000680314" title="Male to Male Jumper Wires&nbsp;" target="_blank" rel="">Male to Male Jumper Wires&nbsp;</a><a href="https://robolark.com/products/jumper-wires-male-male/313657000000680314" title="Male to Male Jumper Wires&nbsp;" target="_blank" rel=""><br/></a></span></p></li><li style="font-size:11pt;"><p><a href="https://robolark.com/products/male-to-female-jumper-wires/313657000000680305" title="Male to Female Jumper wires" target="_blank" rel="">Male to Female Jumper wires</a></p></li><li style="font-size:11pt;"><p style="margin-bottom:12pt;"><span style="font-size:11pt;font-weight:700;"><a href="https://robolark.com/products/mb-102-solderless-breadboard-830-tie-points/313657000000677740" title="Breadboard" target="_blank" rel="">Breadboard</a></span></p></li></ul></span></span></div></div></div>
</div><div data-element-id="elm_qu9HIF9DkqQd2BSoV9eSNw" data-element-type="text" class="zpelement zpelem-text "><style></style><div class="zptext zptext-align-left " data-editor="true"><p><span style="font-size:24px;text-decoration-line:underline;">Connections:</span></p><p><img src="/DIY%20Arduino%20Dice%20Roller_Robolark.png" style="width:499.95px !important;height:406px !important;max-width:100% !important;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<img src="/Tue%20May%2027%202025-1.png"></p></div>
</div><div data-element-id="elm_y-M5un_ddzQnjTfDj2hlZA" data-element-type="text" class="zpelement zpelem-text "><style></style><div class="zptext zptext-align-left " data-editor="true"><div style="color:inherit;"><h2><div style="color:inherit;"></div></h2><h2>📦 Library Prerequisites</h2><h2><span style="color:inherit;font-size:15px;">Before uploading the code, make sure the following libraries are installed in your Arduino IDE:</span></h2><ol><li><p><strong>LiquidCrystal_I2C</strong></p></li><li><p><strong>Wire</strong> (pre-installed with Arduino IDE)</p></li></ol><h3>🔽 How to Install LiquidCrystal_I2C:</h3><ol><li><p>Open Arduino IDE</p></li><li><p>Go to <strong>Sketch &gt; Include Library &gt; Manage Libraries</strong></p></li><li><p>Search for <code>LiquidCrystal_I2C</code></p></li><li><p>Install the one by <strong>Frank de Brabander</strong> or equivalent</p></li><li><p><code>Wire.h</code> comes pre-installed with Arduino IDE</p></li></ol><div><span style="color:inherit;"><span style="font-size:11pt;"><span style="width:311px;"><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXeqwILiPUegmypjEBj4WF2bxtVdXwSYeY2DjiOE2KVgCf9rs2hisFz0j13o3yp0tdvQj3YEW-6JNpyDyMiam71bL8lOkd48ocWcrNnt2ghQK_NACsMBk3bd5JOPZZPdqLYlKqTEQw?key=wjfYo84FB-f1qOsuMNRwgA" width="311" height="593"></span></span></span></div></div></div>
</div><div data-element-id="elm_SsySFTo7XAQlhn4rAEGyyw" data-element-type="text" class="zpelement zpelem-text "><style></style><div class="zptext zptext-align-left " data-editor="true"><p style="margin-bottom:16pt;"><span style="font-size:15pt;color:rgb(48, 4, 234);">Arduino Code</span></p><p style="margin-bottom:12pt;"><span style="font-size:11pt;">Copy and Upload the following code to your Arduino:</span></p><p><span style="font-size:10.5pt;color:rgb(29, 111, 226);">#include &lt;Wire.h&gt;</span></p><p><span style="font-size:10.5pt;color:rgb(29, 111, 226);">#include &lt;LiquidCrystal_I2C.h&gt;</span></p><p><span style="font-size:10.5pt;color:rgb(29, 111, 226);">LiquidCrystal_I2C lcd(0x27,20,4);&nbsp; // set the LCD address to 0x27 for a 16 chars and 2 line display</span></p><p><span style="font-size:10.5pt;color:rgb(29, 111, 226);">const int vibPin = 2;</span></p><p><span style="font-size:10.5pt;color:rgb(29, 111, 226);">const int buzzerPin = 8;</span></p><p><span style="font-size:10.5pt;color:rgb(29, 111, 226);">bool ready = true;</span></p><p><span style="font-size:10.5pt;color:rgb(29, 111, 226);">void setup() {</span></p><p><span style="font-size:10.5pt;color:rgb(29, 111, 226);">&nbsp;lcd.init();</span></p><p><span style="font-size:10.5pt;color:rgb(29, 111, 226);">&nbsp;lcd.backlight();</span></p><p><span style="font-size:10.5pt;color:rgb(29, 111, 226);">&nbsp;lcd.setCursor(0, 0);</span></p><p><span style="font-size:10.5pt;color:rgb(29, 111, 226);">&nbsp;lcd.print(&quot;Shake to Roll!&quot;);</span></p><p><span style="font-size:10.5pt;color:rgb(29, 111, 226);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p><p><span style="font-size:10.5pt;color:rgb(29, 111, 226);">&nbsp;pinMode(vibPin, INPUT);</span></p><p><span style="font-size:10.5pt;color:rgb(29, 111, 226);">&nbsp;pinMode(buzzerPin, OUTPUT);</span></p><p><span style="font-size:10.5pt;color:rgb(29, 111, 226);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p><p><span style="font-size:10.5pt;color:rgb(29, 111, 226);">&nbsp;randomSeed(analogRead(A0));&nbsp; // Seed randomness</span></p><p><span style="font-size:10.5pt;color:rgb(29, 111, 226);">}</span></p><p><span style="font-size:10.5pt;color:rgb(29, 111, 226);">void loop() {</span></p><p><span style="font-size:10.5pt;color:rgb(29, 111, 226);">&nbsp;int vibState = digitalRead(vibPin);</span></p><p><span style="font-size:10.5pt;color:rgb(29, 111, 226);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p><p><span style="font-size:10.5pt;color:rgb(29, 111, 226);">&nbsp;if (vibState == HIGH &amp;&amp; ready) {</span></p><p><span style="font-size:10.5pt;color:rgb(29, 111, 226);">&nbsp;ready = false;</span></p><p><span style="font-size:10.5pt;color:rgb(29, 111, 226);">&nbsp;int diceNumber = random(1, 7);&nbsp; // Random number between 1 and 6</span></p><p><span style="font-size:10.5pt;color:rgb(29, 111, 226);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p><p><span style="font-size:10.5pt;color:rgb(29, 111, 226);">&nbsp;lcd.clear();</span></p><p><span style="font-size:10.5pt;color:rgb(29, 111, 226);">&nbsp;lcd.setCursor(0, 0);</span></p><p><span style="font-size:10.5pt;color:rgb(29, 111, 226);">&nbsp;lcd.print(&quot;You rolled a:&quot;);</span></p><p><span style="font-size:10.5pt;color:rgb(29, 111, 226);">&nbsp;lcd.setCursor(6, 1);</span></p><p><span style="font-size:10.5pt;color:rgb(29, 111, 226);">&nbsp;lcd.print(diceNumber);</span></p><p><span style="font-size:10.5pt;color:rgb(29, 111, 226);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p><p><span style="font-size:10.5pt;color:rgb(29, 111, 226);">&nbsp;tone(buzzerPin, 1000, 200);&nbsp; // Beep sound</span></p><p><span style="font-size:10.5pt;color:rgb(29, 111, 226);">&nbsp;delay(1000);&nbsp; // Delay before allowing next roll</span></p><p><span style="font-size:10.5pt;color:rgb(29, 111, 226);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p><p><span style="font-size:10.5pt;color:rgb(29, 111, 226);">&nbsp;lcd.clear();</span></p><p><span style="font-size:10.5pt;color:rgb(29, 111, 226);">&nbsp;lcd.setCursor(0, 0);</span></p><p><span style="font-size:10.5pt;color:rgb(29, 111, 226);">&nbsp;lcd.print(&quot;Shake to Roll!&quot;);</span></p><p><span style="font-size:10.5pt;color:rgb(29, 111, 226);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p><p><span style="font-size:10.5pt;color:rgb(29, 111, 226);">&nbsp;ready = true;</span></p><p><span style="font-size:10.5pt;color:rgb(29, 111, 226);">&nbsp;}</span></p><p><span style="font-size:10.5pt;color:rgb(29, 111, 226);">}</span></p></div>
</div><div data-element-id="elm_cOE1O-RIpMYnSds0uXJuSg" data-element-type="text" class="zpelement zpelem-text "><style></style><div class="zptext zptext-align-left " data-editor="true"><p style="margin-bottom:16pt;"><span style="font-size:15pt;color:rgb(48, 4, 234);">How It Works</span></p><p style="margin-bottom:12pt;"><span style="font-size:11pt;">Let’s break down the working logic:</span></p><ol><li style="font-size:11pt;"><p><span style="font-size:11pt;font-weight:700;">Shake Detection:<br/></span><span style="font-size:11pt;"> The vibration sensor has a spring inside. When you shake the breadboard or setup, the spring momentarily closes a circuit, sending a </span><span style="font-size:11pt;font-weight:700;">HIGH signal</span><span style="font-size:11pt;"> to pin 2.<br/><br/></span></p></li><li style="font-size:11pt;"><p><span style="font-size:11pt;font-weight:700;">Random Number Generation:<br/></span><span style="font-size:11pt;"> Using randomSeed() and random(1, 7), the Arduino generates a </span><span style="font-size:11pt;font-weight:700;">pseudo-random number</span><span style="font-size:11pt;"> from 1 to 6.<br/><br/></span></p></li><li style="font-size:11pt;"><p><span style="font-size:11pt;font-weight:700;">Display Output:<br/></span><span style="font-size:11pt;"> The result is shown on the </span><span style="font-size:11pt;font-weight:700;">16x2 LCD screen</span><span style="font-size:11pt;"> via the I2C interface. This simplifies wiring, needing only 4 wires.<br/><br/></span></p></li><li style="font-size:11pt;"><p style="margin-bottom:12pt;"><span style="font-size:11pt;font-weight:700;">Sound Feedback:<br/></span><span style="font-size:11pt;"> A quick </span><span style="font-size:11pt;font-weight:700;">beep from the buzzer</span><span style="font-size:11pt;"> provides audio feedback to enhance the user experience.<br/><br/></span></p></li></ol><p style="margin-bottom:16pt;"><span style="font-size:15pt;color:rgb(48, 4, 234);">Testing &amp; Troubleshooting</span></p><ul><li style="font-size:11pt;"><p><span style="font-size:11pt;">If </span><span style="font-size:11pt;font-weight:700;">LCD is blank</span><span style="font-size:11pt;">, check the I2C address (use an I2C scanner sketch).</span></p></li><li style="font-size:11pt;"><p><span style="font-size:11pt;">If the </span><span style="font-size:11pt;font-weight:700;">vibration sensor is too sensitive</span><span style="font-size:11pt;">, try using a short delay() of 10ms &nbsp;after the shake to debounce.</span></p></li><li style="font-size:11pt;"><p><span style="font-size:11pt;">If the </span><span style="font-size:11pt;font-weight:700;">buzzer doesn’t beep</span><span style="font-size:11pt;">, confirm it's not connected in reverse.</span></p></li></ul><p><span style="color:inherit;"><span><br/></span></span></p><p style="margin-bottom:16pt;"><span style="font-size:15pt;color:rgb(48, 4, 234);">Final Output</span></p><p style="margin-bottom:12pt;"><span style="font-size:11pt;font-weight:700;">When you shake the setup:</span></p><ul><li style="font-size:11pt;"><p><span style="font-size:11pt;">The LCD displays a message like “You rolled a: 4”<br/><br/></span></p></li><li style="font-size:11pt;"><p><span style="font-size:11pt;">The buzzer beeps once<br/><br/></span></p></li><li style="font-size:11pt;"><p style="margin-bottom:12pt;"><span style="font-size:11pt;">Then it resets to “Shake to Roll!” waiting for the next movement</span></p></li></ul><p><span style="color:inherit;"><span><br/></span></span></p><h2 style="margin-bottom:4pt;"><span style="font-size:17pt;font-weight:700;color:rgb(48, 4, 234);">Enhancement Ideas</span></h2><p style="margin-bottom:12pt;"><span style="font-size:11pt;">Want to take your project further?</span></p><ul><li style="font-size:11pt;"><p><span style="font-size:11pt;">Add </span><span style="font-size:11pt;font-weight:700;">RGB LEDs</span><span style="font-size:11pt;"> to light up with the number rolled.<br/><br/></span></p></li><li style="font-size:11pt;"><p><span style="font-size:11pt;">Show a </span><span style="font-size:11pt;font-weight:700;">rolling animation</span><span style="font-size:11pt;"> (1 to 6) before showing the final number.<br/><br/></span></p></li><li style="font-size:11pt;"><p><span style="font-size:11pt;">Use a </span><span style="font-size:11pt;font-weight:700;">gyroscope or accelerometer</span><span style="font-size:11pt;"> for more refined motion sensing.<br/><br/></span></p></li><li style="font-size:11pt;"><p style="margin-bottom:12pt;"><span style="font-size:11pt;">Add a </span><span style="font-size:11pt;font-weight:700;">battery module</span><span style="font-size:11pt;"> for portability.</span></p></li></ul><p style="margin-bottom:12pt;"><span style="font-size:15pt;color:rgb(48, 4, 234);">Conclusion</span></p><p><span style="font-size:11pt;">With just a few components and some simple code, you’ve built a fully functional digital dice roller using Arduino! It’s a fun and practical way to explore motion detection, display output, and buzzer interaction—all skills you can carry into more advanced projects.</span></p><p><span style="color:inherit;"></span></p><div><span style="font-size:11pt;"><br/></span></div></div>
</div></div></div></div></div></div> ]]></content:encoded><pubDate>Sun, 29 Jun 2025 22:44:47 +0530</pubDate></item></channel></rss>