Electronic dice w/ tilt sensor, 7 segment display and Arduino

For fun I made a dice using Arduino, tilt sensor and a 7 segment display.

Hardware requirements

  • Arduino(I used an Arduino Uno)
  • Tilt sensor(a button could be used, if you’d like to press instead of shake)
  • 7 segment display(with a dot)
  • 10 K ohm resistor
  • A breadboard
  • Some jumper wires

Connecting the 7 segment display

7segmentdisplay

First we’ll connect the display and make sure it works. Here is the data sheet to a pretty common 7 segment display that I used in this project.

Screen Shot 2014-03-30 at 04.43.29

Picture nr 1

pinseg

Picture nr 2

Screen Shot 2014-03-30 at 04.43.35

Picture nr 3

 

 

 

 

 

 

“Picture nr 1” shows the segment labels, the “Picture nr 2” shows what the pin numbers are, and the last one(picture nr 3) shows that pin 3 and 8 are to be connected to ground, and all the other pins turn on a segment on the display when connect to a power source.

This is how you connect the display to the Arduino. The table below was taken from this post.

Arduino Digital Pin 7 Segment display pin connection
2 7 (A)
3 6 (B)
4 4 (C)
5 2 (D)
6 1 (E)
7 9 (F)
8 10 (G)
9 5 (DP)
GND 3
GND 8

And this is how it looks on my end

7segdisp

Testing the display

Upload the code to your Arduino and the display should start counting down from 9. When it hits 0 it resets after a while and starts counting down again from 9. This code was taken from a tutorial on how to use a 7 segment display, link to the post is here. The code should not be credited to me.

If the numbers are weird looking then you probably didn’t connect the display right. Recheck you connected the right pins on the display to the right pin slots on the Arduino

Connecting the tilt sensor

tilt-sensor

The tilt sensor is basically a simple switch. The switch is open when it’s pointing up, and is closed when up-side-down. It has two pins, and just like a switch, doesn’t matter what way the current is flowing.

Connect one side of the tilt sensor to Arduino digital pin 12 and the other side to the 5 volt pin.
So the circuit should be Arduino digital pin 12 –> Tilt Sensor –> 5 volt pin

Before we upload the final code we need to do one more thing. We need to connect a pull-up resistor. Get a 10K ohm resistor and connect it to the wire coming from Arduino digital pin 12. and the other side of the resistor to an empty row om the breadboard. Then run a cable from the other side of the resistor to the ground pin on the Arduino.
So the circuit should be Arduino digital pin 12 –> resistor –> Arduino ground(GND) pin

Now hardware should all be setup, time to upload the final code

Uploading the Arduino code

The code below is a modified version of the code I got from this site. I modified it to wait for the tilt sensor to close before looping through a set of random numbers between 1 to 6 and then freezing on the last one. Also as a detail I made the dot on the display light up when “shaking” the dice.

Now just aggressively shake the tilt sensor and watch the pretty display randomly choose a number!

 

If you have any questions feel free to ask me by using the Contact page or by commenting below.

Prince

A second year computer engineering student at Malmö University in Sweden just having some fun with this blog. Computer Engineering and Mobile IT: Bachelor of Science in engineering

You may also like...

7 Responses

  1. Hello There. I found your blog using msn. This is a really well written article.

    I will be sure to bookmark it and come back to read more of
    your useful info. Thanks for the post. I’ll definitely return.

  2. Trey says:

    I must thank you for the efforts you’ve put in writing this
    site. I’m hoping to view the same high-grade blog posts from you later on as well.
    In fact, your creative writing abilities has inspired
    me to get my very own website now 😉

  3. With havin so much content and articles do you ever run into any issues of plagorism or copyright infringement?
    My site has a lot of completely unique content I’ve
    either authored myself or outsourced but it seems a
    lot of it is popping it up all over the web without my authorization.
    Do you know any techniques to help prevent content from being stolen? I’d definitely appreciate it.

  4. Ivory says:

    I was able to find good information from your content.

  5. Maik says:

    Wow, wonderful blog layout! How long have you been blogging for?
    you made blogging look easy. The overall look of your site is excellent,
    as well as the content!

  6. First off I want to say fantastic blog! I had a
    quick question which I’d like to ask if you
    don’t mind. I was curious to know how you center yourself and clear your
    thoughts before writing. I have had difficulty clearing
    my thoughts in getting my thoughts out there.
    I do take pleasure in writing however it just seems
    like the first 10 to 15 minutes are usually wasted
    simply just trying to figure out how to begin. Any suggestions
    or hints? Kudos!

  7. Mit.edu says:

    I was recommended this web site by my cousin. I am now not positive whether this publish is written by means of him as no one else
    understand such designated approximately my difficulty.
    You are wonderful! Thank you!

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.