Introduction: Arduino Chessclock
I could not find instructions on a good Arduino chess clock so instead I built my own which I will describe here.
Step 1: Parts List
here are the things you will need:
Arduino nano (or any arduino UNO type will do)
PCB board or vero board
2 dual AA battery holders
3 X 10k OHM resistors
2 X earth pins from 2 UK plugs
2 X 4 digit 7-segment displays
1 toggle switch
1 button small (press to make type)
USB 1 cable (or whatever fits in your Arduino)
mics fittings and nuts bolts. For this I bid and won a meccano set on ebay and used what I found
breadboard and jumper cables (optional but recommended to prototype it first)
time, plenty of time!
I attached an image but this was from my spares after my build so some components are missing as noted.
Step 2: Prototyping
The whole project can be split into these parts:
1. getting the circuit right
2. the program
3. the physical layout
This step is optional since I will give you the circuit diagram but I do highly recommend that you give it a go in a breadboard first as it will confirm (or not) that you have all the parts that you need and enable you to think about the physical layout of all the pieces for a housing or base.
I have attached here a picture of my prototype in a breadboard and also a circuit diagram. Some notes on the circuit:
1. In the top left of the circuit diagram shows the pin on the display that is connected to the segment (Cathodes) or the digit (Anodes).
2. You will note that for each display the segments (Cathodes) are connected to the respective segment on the other display. This is because the display is multiplexed to display the correct digits
3. the reset switch and the rocker is wired up with pull down resistors so as to keep the input LOW when the respective button is not depressed. see http://www.arduino.cc/en/tutorial/button for more details on this.
4.The power circuit is completely separate but simple. It is 4 AA batteries in serial with a switch are soldered into the red and black leads of to a cut USB cable. The USB cable then goes into the arduino.
Step 3: The Program
Once you have it on a breadboard then you need to write the controller. Fortunately for you I have attached my code here but I would encourage you to have a go or tweak this code. If you are going to write it from scratch you first work out which pins to set to what to make all the 10 digits, I have then coded an additional 2 patterns, one for when time is run out and one to represent 10 in a single digit (see image).
The next step is to multiplex the digits so you can potentially display a different number or pattern on each of the 8 digits. I tweaked the speed of the multiplexing until it looked right, too fast and the numbers merge between neighboring digits and too slow and the naked eye can notice the multiplexing.
The next step is to count the numbers down as 2 sets of 4 numbers representing 2 countdowns. I chose to use the first digit for minutes, the next 2 for seconds and the last one for tenths of seconds but you could chose to have 2 for minutes and 2 for seconds.
The countdown can be calibrated with a simple for loop that does nothing so that a tick of a 'second' on the display is actually a real second. I got mine pretty close but I figured that it doesn't matter too much for an informal game of chess if each play has the same number of units. I guess you might want to make it more accurate if you want to use your chess clock for a tournament or even to time an egg!
The clock loads into reset mode when turned on. Then it waits for the rockers to be hit on either side and counts down from the (default) 5 mins. The code listens to the reset button when the rocker is balanced. if it is hit then the clock goes into reset mode again. At this point the reset button can be used to cycle through the minutes desired for each play from 1 to 10. when the desired time is displayed the rocker can be hit again to start the clock.
lastly you need it to do something to indicate that the time has run out in my case it displays all dashes (-) and plays a series of beeps, then it shows one side as 0000 (the loser) and the other side as whatever time was unused by the winner.
Step 4: Physical Build
The next phase is the physical build.
The first piece is to build the rocker switch. This switch must close one of two connections but never both. Also it must be able to balance in the middle where it closes neither connection. This pauses the clock. Here I used a small length of wood and screwed a UK ground pin to either end. Then a pivot is built in the middle to raise the rocker off the board. Again I used my ebay meccano extensively for this bit. When the rocker is mounted onto the board the ground pins need to go into the fuse holder clips to close the connection. To make this have a smooth feel I filed down the edges of the ground pins so the go into the fuse holder move easily (see image).
I first mounted the empty PCBs onto a perspex sheet with a gap for the pivot of the rocker switch. Then I took it back off and soldered the components and wire in with the same gap. If you do not do this you may find it difficult to bolt the resulting boards back onto the perspex of base.
Draw the layout out on paper first and bear in mind:
- how high the 'up' side of each rocker will be for the housing
- some components like the battery holders and Arduino USB port need to be accessible after completion
- If switches are to be mounted on a lid of the housing then connect their wires with connectors so the lid can be completely removed. (mine only has a hinge but I did this anyway)
- I tilted the 7-segment displays by extending the pins on one side with fuse wire which allows that side to sit higher out of the board
I had planned to build a custom housing but in the end I did not have enough time and the perspex is difficult to cut so I bought a box that was similar size to what I needed and modified it a bit. I think it is good to have transparent casing so the workings can be seen but make sure that the batteries and the USB port remain available for program tweaks.
That's it have fun and good luck!
Step 5: Other Options...
Possible enhancements or options:
- play a different sequence of beeps depending on which side wins
- play a tune on completion I believe this to be possible with the analogue pins and an appropriate buzzer.
- different official chess timing patterns (for example add time for each move played)
- use the 7 segment to be 2 digits for minutes and 2 for seconds
Step 6: 2019 Update!
so I returned to my first Instructable and made this chessclock again!
I followed the same steps more or less but with the following improvements:
- The whole build is more compact and on a wooden base (see photos)
- Switched to a single 9v battery connected direct to the VIN and GND by a switch
- The rocker switch is meccanno where each side is held down when pressed by superstrong magnets.
I also improved the code which is attached here. improvements are:
- Ditched the display of 10ths of a second and shifted digits right
- Added increments. Added 5 mins plus 5 secs per/move and 10 mins plus 5 secs per/move as options
- Added a coupe of lines to switch the displays (L <=> R) if you find after the build that the rocker switch does not start the correct clock
- Added a physical switch to disable / enable the buzzer