# Arduino Chess Clock

2,657

23

1

There are various rates of play in use. The following indicates the different options available:

Blitz has typical time limits of 5 minutes for each player for all of the moves.
Rapidplay is played with typical time limits of 30 minutes for each player for all the moves.
Local league chess has typical time controls of 75 minutes.
International chess has a standard time control of 40 moves in 2 hours and then an extra hour to reach move 60. After this, if the game is still in progress a quickplay finish decides the game.

### Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

## Step 1: Parts List

• 2 momentary push buttons
• 14 220ohm resistors
• Potentiometer
• One red led, one blue led
• 10-Leds ledsbar (Bargraph)
• Piezo buzzer
• Copper Tape
• Wires
• Arduino Pro Mini

## Step 2: Connections

Buttons :
Each button is connected to 5v at one joint and to a pulldown resistor wich connected to ground.
Also the red button is connected to the arduino digital pin 2 and the black button is connected to arduino digital pin 3.

Leds :
The red led is connected to at the anode to a limiting resistor (220 ohm) and then to arduino digital pin 4, the black (blue) led is connected the dame but to arduino digital pin 5.
both are connected to ground at the cathod.

Buzzer :
Anode is connected to arduino digital pin 9, wich is also capable of PWM.
Cathod is connected to ground.

Potentiometer :
Joint 1 is connected to 5v.
Joint 2 is connected to arduino analog pin 3 (A3)
and the 3rd joint is connected to ground

Leds Bar :
The leds bar is actually 10 leds, so each on is connected at the cathod to a limiting resistor and then to ground.
The anodes are connected to pins 6 to 8, 10 to 13 accordingly and then to pins 14 to 16 wich are actually A0, A1, A2 (since you can also use them as digital pins).

Toggle Switch :
Is connected to battery at one joint and to arduino RAW

Battery :
Anode is connected to Toggle Switch, Cathod is connected to arduino GND

## Step 3: CODE

`#define buzz 9`
```#define redB 2
#define blackB 3
#define redLed 4
#define blackLed 5```
`#define selectorP A3`
```int leveler[10] = {6, 7, 8, 10, 11, 12, 13, A0, A1, A2};
long gameType[6] = {300000, 1800000, 4500000, 7200000, 60000, 120000};
int gameTypeSelector;
long redStart = 0, blackStart = 0;```
`long startTime;`
`boolean redTurn = true;`
```void setup() {
pinMode (buzz, OUTPUT);
pinMode (redB, INPUT);
pinMode (blackB, INPUT);
pinMode (redLed, OUTPUT);
pinMode (blackLed, OUTPUT);

for (int i = 0; i <= 9; i++) {
pinMode (leveler[i], OUTPUT);
}
Serial.begin (9600);
}```
```void fillLevel (int level) {
digitalWrite (leveler[0], LOW);
digitalWrite (leveler[1], LOW);
digitalWrite (leveler[2], LOW);
digitalWrite (leveler[3], LOW);
digitalWrite (leveler[4], LOW);
digitalWrite (leveler[5], LOW);
digitalWrite (leveler[6], LOW);
digitalWrite (leveler[7], LOW);
digitalWrite (leveler[8], LOW);
digitalWrite (leveler[9], LOW);

for (int i = 0; i <= level - 1; i++) {
digitalWrite (leveler[i], HIGH);
}
}```
```void justLevel (int level) {
digitalWrite (leveler[0], LOW);
digitalWrite (leveler[1], LOW);
digitalWrite (leveler[2], LOW);
digitalWrite (leveler[3], LOW);
digitalWrite (leveler[4], LOW);
digitalWrite (leveler[5], LOW);
digitalWrite (leveler[6], LOW);
digitalWrite (leveler[7], LOW);
digitalWrite (leveler[8], LOW);
digitalWrite (leveler[9], LOW);

digitalWrite (leveler[level], HIGH);
}```
```int timeBar(boolean timeBaseGame) {
int TB;
if (!timeBaseGame) {  // if not a time based game
gameTypeSelector = map (analogRead (selectorP), 0, 1023, 0, 5);
long endTime = gameType[gameTypeSelector] + startTime;
Serial.println (gameType [gameTypeSelector]);
/*Serial.print ("Start Time : ");
Serial.print (startTime);
Serial.print (" End Time : ");
Serial.print (endTime);
Serial.print (" Now time : ");
Serial.println (millis());*/
TB = map (millis (), startTime, endTime, 0, 10);
if (TB >=10) {
startTime = millis ();
buzzer ();
redTurn = !redTurn;
return 10;
} else {
return TB;
}
} else {  // if time based game
if (redTurn) {
TB = map (redStart + (millis() - startTime), 0, gameType[gameTypeSelector], 0, 10);
} else {
TB = map (blackStart + (millis() - startTime), 0, gameType[gameTypeSelector], 0, 10);
}
if (TB >=10) {
while (redStart >= 0 && blackStart >=0) {  //Lost by clock action
if (millis () % 500 == 0) {
buzzer ();
}
return 10;
}
if (digitalRead (blackB)) {  //Game RESET
redTurn = true;
redStart = 0;
blackStart = 0;
startTime = millis ();
}
}  // End of Game RESET
} else {
return TB;
}
}
}```
```void buzzer () {
tone (buzz, 400);
delay (300);
noTone (buzz);
}```
```void loop() {                                  //*****************************************************************************************************
gameTypeSelector = map (analogRead (selectorP), 0, 1023, 0, 5);
if (gameType[gameTypeSelector] <= 120000) {  //The 1 minuts and 2 minuts regular move time counter
if (redTurn) {
digitalWrite (redLed, HIGH);
digitalWrite (blackLed, LOW);

startTime = millis ();
redTurn = false;
buzzer ();
}
} else {
digitalWrite (redLed, LOW);
digitalWrite (blackLed, HIGH);
startTime = millis ();
redTurn = true;
buzzer ();
}
}
fillLevel (timeBar(false));
} // end of regular move time counter
else {
if (redTurn) {
digitalWrite (redLed, HIGH);
digitalWrite (blackLed, LOW);

fillLevel (timeBar(true));
redStart = redStart + (millis () - startTime);
Serial.print ("Red Time stands : ");
Serial.print (redStart);
Serial.print (" out of : ");
Serial.println (gameType[gameTypeSelector]);
startTime = millis ();
redTurn = false;
}
} else {
digitalWrite (redLed, LOW);
digitalWrite (blackLed, HIGH);

fillLevel (timeBar(true));

if (digitalRead (redB)) {    // Game RESET
digitalWrite (redLed, HIGH);
digitalWrite (blackLed, HIGH);
redTurn = true;
redStart = 0;
blackStart = 0;
startTime = millis ();
} // end of Game RESET

blackStart = blackStart + (millis () - startTime);
Serial.print ("Black Time stands : ");
Serial.print (blackStart);
Serial.print (" out of : ");
Serial.println (gameType[gameTypeSelector]);
startTime = millis ();
redTurn = true;
}
}
}
} // end void loop ************************************************************************************************************************************```

1 54 2.9K
71 11K
102 7.0K