How to Make a Chess Clock With Arduino

Introduction: How to Make a Chess Clock With Arduino

About: My name is Simao and I love eletronics ,glass art,metal working,casting,paint ,draw... But above all... Trains

You play chess?Probably.If you are seen this instructable and you never play a game of chess I think it some strange .OK , you can never played a game of chess and you are trying to learn ,in first place ,in this time I don't gonna teach you how to play ,but the true answer is how to make a chess clock ,if you seen on TV or played on a championship of chess you see that every table have a clock a little double display clock.

There are many brands that fabricate this clocks the international clock authorized by FIDE is DGT this clock are many models ,practically every two ears goes out a new model but this clocks are very expensive a clock non authorized by FIDE can cost you about 100 euros in portugal ( like Excalibur ,a model of a clock non authorized but very good quality) can cost 150 euros .

OK let's make a chess clock !:-D

Supplies

  1. Arduino board (can be anyone).
  2. Breadboard.
  3. Jumper wires.
  4. 10k rotary potenciometer
  5. two 10k resistors
  6. two 220R resistors.
  7. two LED
  8. LCD display 16*2 chars
  9. Two momentary push buttons
  10. USB cable to program Arduino

Step 1: Schematic...

Wire everything like on the schematic.

PAY ATTENTION:

  • Polarity of the LED's because it have an inconstant polarity!
  • Polarity of Push Buttons!
  • Make everything like on the picture!

Step 2: The Code. ArduinoCode


#include <LiquidCrystal.h>

LiquidCrystal lcd (7, 8, 9, 10, 11, 12);
const int buttonPin = 2; // the number of the pushbutton pin const int ledPin = 13; // the number of the LED pin // Variables will change: int ledState = HIGH; // the current state of the output pin int buttonState; // the current reading from the input pin int lastButtonState = LOW; // the previous reading from the input pin unsigned long lastDebounceTime = 0; // the last time the output pin was toggled unsigned long debounceDelay = 50; // the debounce time; increase if the output flickers

double whiteTime = 600000; int whiteMinutes = 0; int whiteSeconds = 0; double whiteLastCheck = millis(); double blackTime = 600000; int blackMinutes = 0; int blackSeconds = 0; double blackLastCheck = millis(); bool isWhiteTurn = true; bool gameOver = false; void setup() { Serial.begin(9600); lcd.begin(16, 2); lcd.setCursor(0, 0); pinMode(buttonPin, INPUT); pinMode(ledPin, OUTPUT); UpdateWhiteTime(); UpdateBlackTime();

//int whiteButtonState = 0; //int blackButtonState = 0; } void loop() { int reading = digitalRead(buttonPin); Serial.println(ledState);

if (reading != lastButtonState) { lastDebounceTime = millis(); } if ((millis() - lastDebounceTime) > debounceDelay) { // whatever the reading is at, it's been there for longer // than the debounce delay, so take it as the actual current state:

// if the button state has changed: if (reading != buttonState) { buttonState = reading;

// only toggle the LED if the new button state is HIGH if (buttonState == HIGH) { ledState = !ledState; } } }// set the LED: digitalWrite(ledPin, ledState); if(ledState==1){ StartWhiteTurn (); Serial.println("White"); UpdateWhiteTime(); } else if(ledState==0){ StartBlackTurn (); Serial.println("Black"); UpdateBlackTime(); } lastButtonState = reading; } void UpdateWhiteTime() { lcd.setCursor(10,0); lcd.print("White"); lcd.setCursor(12, 1); Serial.println("White"); whiteTime -= ((millis() - whiteLastCheck)); whiteLastCheck = millis(); if (whiteTime <= 0) { gameOver = true; lcd.print("LOSE"); return; } whiteMinutes = floor(whiteTime / 60000); whiteSeconds = floor(whiteTime / 1000) - whiteMinutes * 60; lcd.print(whiteMinutes); lcd.print(":"); if (whiteSeconds < 10) { lcd.print(0); } lcd.print(whiteSeconds); }// end printWait void UpdateBlackTime() { lcd.setCursor(1,0); lcd.print("Black"); lcd.setCursor(0, 1); Serial.println("Black"); blackTime -= ((millis() - blackLastCheck)); blackLastCheck = millis(); if (blackTime <= 0) { gameOver = true; lcd.print("LOSE"); return; } blackMinutes = floor(blackTime / 60000); blackSeconds = floor(blackTime / 1000) - blackMinutes * 60; lcd.print(blackMinutes); lcd.print(":"); if (blackSeconds < 10) { lcd.print(0); } lcd.print(blackSeconds); }// end printWait void StartWhiteTurn () { if (isWhiteTurn) { return; } isWhiteTurn = true; whiteLastCheck = millis(); } // end StartWhiteTurn void StartBlackTurn () { if (!isWhiteTurn) { return; } isWhiteTurn = false; blackLastCheck = millis(); } // end StartBlackTurn

Step 3: About This Project & How to Use.

About:

This clock makes a countdown from ten to zero.

How to Use This :

  1. Put the clock on the right side of the white pieces player.
  2. Reset the Arduino ,the countdown starts automatically.
  3. when a player ends his turn press on his button the LED of the another player is suppose to turn on.
  4. If the time of a player ends his side of the screen prints "LOSE".
I expect you enjoy!
Please comment and share this project :-D
Games Contest

Participated in the
Games Contest

Be the First to Share

    Recommendations

    • Edible Art Challenge

      Edible Art Challenge
    • Made with Math Contest

      Made with Math Contest
    • Paint Challenge

      Paint Challenge

    3 Comments

    0
    erastovmarius
    erastovmarius

    7 months ago

    Hello, why the time starts at 9:58, and not at 10:00?

    0
    adityaambare
    adityaambare

    Question 1 year ago

    how did you connect two buttons to same digital pin 2 and same for leds at pin 13? sorry i am new and unaware of this .

    0
    simaopintocorreia
    simaopintocorreia

    Answer 8 months ago


    @adityaambare Sorry for the late reply! I haven't saw the notification...
    The buttons: The original project just have one button so I placed two! The other player can basically change the clock just with his one button.
    The leds: How can I connect two leds in just one IO? Simple! one of the leds have the positive lead connected to de IO the other have the negative one! The negative lead of the first is connected on the GND the other led has its positive on 5V+ so... When IO is at HIGH position the led that have the positive on IO will lit when the IO is at LOW the one that have the negative on IO will lit up. resuming one led will lit at the time just by varying the value of one IO.