Introduction: Infrared Dice Sensor

My name is Calvin and I will show you how to make an Infrared dice sensor and explain how it works.

I am currently a Taylor University student studying Computer Engineering and my team and I was asked to design and build a mechanism that can sort any object that can fit in a 1in square. We could have taken the easy route and chosen to sort m&m's using a simple color sensor, but we decided to go above and beyond and sort dice by the number shown. After countless hours of trying to find a guide on how to read the face of the dice I ran into this link here:

This link, however, did not give me much more than the idea on how to read the face of the dice, so using the idea that was provided, I went on my way to build and develop a sensor that can be connected with an Arduino with ease and can read the face of the dice as accurately as possible, thus giving us this Infrared Dice Sensor.


Now on to the supplies:

You will need:

1 x Arduino Uno

5 x IR Receivers

5 x IR Emitters

5 x 270 ohm resistors

5 x 10k ohm resistors

1 x 74HC595N chip

various male headers

1 x Prototype board (if you are not getting a custom milled board)

Step 1: Understanding How It Works

This sensor uses 5 pip locations to read the faces of the dice. It uses Infrared light to bounce off the face of the dice at these pip locations and tells the controller whether it is white or black.

You may be wondering, why only 5 pip locations then? Wouldn't you need all 9 to read the dice effectively?

Well, due to the symmetry of the dice, using 5 specific locations on the dice can be enough to tell the difference between the different numbers on the dice regardless of orientation (picture 1). This makes the dice sensor more efficient because it is only looking for exactly what it needs and nothing extra.

The emitter goes exactly underneath the receiver on the sensor at each of these 5 pip locations, the sensor then emits the IR light and then the receiver reads the amount of IR light that bounces of the face of the dice. (picture 3) If the value received is greater then specified calibration numbers, then the sensor will see that spot as a dot, if not then it is white space. (picture 2)

Step 2: Designing and Planning

The first step to building a dice sensor is to create the schematics, this can either be the hardest or the easiest step of the development. You first need a software called EAGLE by Autodesk, this was the software I used to create the schematics.

I have included 2 different kinds of schematics, one schematic has a shift register chip to help make the sensor more accurate, and the other is one without a shift register chip, this schematic, however, will not work with the code that I will provide later on, so you will have to develop something on your own.

I have also included my board layout for the sensor that I have designed with the shift register.

To start designing the board, you have 5 IR Receivers and 5 IR Emitters, the receivers require a 10k resistor and the emitters require a 270 ohm resistor so for each of these elements, you go from:

VCC (5V) -> Resistor -> Analog Read Pin -> IR receiver -> GND

VCC (5V) -> Resistor -> IR emitter -> GND

The analog read pin comes out in between the resistor and the IR Receiver as another branch and goes to the analog pin on the Arduino. You also need to make sure that the emitter goes directly underneath the receiver, I made this mistake the first time I did it and I got very bad results, so make sure that the Receiver goes on top.

In my custom board, I am using the shift register to provide power to each of the emitter and receiver pairs one at a time to avoid any IR light bleed from the other emitters. This gives me an even more accurate reading from each of the pip locations, if you chose to not use the shift register, it will still work for you, it just might be slightly less accurate. On the shift register, you can join pins 3-4 and 7-8 together, since it is not entirely necessary to have them as headers. I left them as headers and put jumpers on the headers in case I wanted to do development in the future.

After you've designed the schematic, you need to make a board layout of your schematic. This part can get very tricky because you have to make sure your paths don't overlap and make sure that your paths and holes meet the specifications of your machine. The board layout I attached had the specific sizes for the machine that I used to mill my board. I spend a few hours laying out the board to be as small as I could make it. There was still room for improvement on this board but it worked for me so I left it as it is. There is a version with a copper GND connecting all of the Ground elements, and a version without attached.

You can also use your schematic to build it on a breadboard or prototype board, as these are much easier to come by and is a cheaper option since you don't have to have a custom board milled.

Once you have the board design you can move on to the next step!

Step 3: Building the Board

This part is entirely dependent on how you want the board created. I created the sensor on a prototype board to test to see if the concept works and how accurate it is, so I followed the schematic without the shift register and I created the board. You have to make sure to lay out everything so that the lines don't overlap, and that you don't accidentally solder lines that shouldn't be connected. When doing it on a prototype board, you have to be very careful, so take your time and don't rush it. You should also be careful of open wires because they can move and cause shorts in the system.

If you chose to have the board milled then this process is simpler. Send the board file to the miller with the specific miller's settings. If doing it yourself, make before you take it out, make sure that all of the copper is properly milled deep enough, The first board I had made, the copper wasn't milled deep enough and I had to get another one milled.

Make sure everything is soldered to the board in the layout desired and make sure to take your time, and if soldering on the PCB then make sure you solder on the correct side of the board.

When putting on the IR Receivers and Emitters make sure that the emitter is exactly underneath the receiver. You will have to play around with bending the legs of the IR components to get them in the right place. Keep a dice on hand as well to check if the pip locations are where they need to be.

Once you have everything soldered and added onto the board you are on to programming the sensor.

Step 4: Programming the Board

This is the tricky part of making the sensor as accurate as possible, programming the board. Luckily I have created a library for you to use with your newly created sensor to make programming it that much easier, you will, however, have to calibrate the sensor depending on the lighting where this sensor is located.

To start you must have an Arduino to interface with this sensor. It uses 5 Analog pins and 3 digital pins.

You have the ability to use the library I made to chose your own analog and digital pins, but I will explain it using the pins I did to interface with the sensor. I have marked the image linked with pin numbers and colored boxes around the set of pins to easily explain which pin plugs into where.

On the sensor, pins 1-5 Red go to A0-A4, so Red 1 goes to A0 and so on. Pins 1-8 White require a bit more explanation.

White 1 - Data pin, this is where the Arduino sends the data to the shift register. I set this pin to digital pin 3 on the Arduino

White 2 - Q0, obsolete in this case, I included it in case I decided to expand at all

White 3 & 4 - Will be paired, you can either solder these two together or use a jumper as I did.

White 5 - latch pin, a very important pin that is the final step in the process to see the pips turn on and off. I set this pin to pin 12 on the Arduino

White 6 - Clock Pin, This provides the clock from the Arduino to the shift register. I set this to digital pin 13.

White 7 & 8 - Will be paired, you can either solder these two together or use a jumper as I did.

Right next to the white box you have the Ground and VCC pins. You must provide 5v from the Arduino or another source to power this sensor.

PIP Location numbers can be found in the code.

Now that you have to hook it up, we have to calibrate it. My goal was to create a script that could calibrate it for you but I ran out of time to do so. When calibrating you have to make sure the sensor is in a controlled lighting environment sense its sensitive to outside inferred light. You have to get a value from each pip location with a black dot and a white dot and average out the difference. I used only two sides of the dice to calibrate, I used side 1, side 6, and side 6 rotated 90 degrees. Once you have a number for white and black for each pip location, you need to average them and find the middle of the two numbers. So for example, if I got 200 for white from the first pip location, and 300 for the dark value of the first pip location, then the calibration number would be 250. Once you do this for all 5 pip locations, your sensor is properly calibrated, then you can use dice.ReadFace(); to get the current face of the dice.


Step 5: Application

You have now successfully created a dice sensor! Congratulations! This has been a long road of trial and error for me to create this sensor, so it is my goal to help anyone out there who wants to create a dice sensor.

I have included a few examples of the project that we build that used this sensor. The first picture, we used a paddlewheel to properly place the dice overtop of the sensor every time. The second picture was the final product of our project, and the base will rotate depending on what the dice face was, and the third picture is a display box that I designed and built to put these sensors on display.

The possibility for this sensor is endless if you put your mind to it. I hope you find this tutorial enjoyable and educational, and I hope you try to make one for yourself.

God bless!

Sensors Contest

Participated in the
Sensors Contest