Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 31

ACKNOWLEDGEMENT

We would like to express our heartfelt gratitude to all those who


have contributed to the successful completion of this
Microprocessor & Microcontroller project. First and foremost,
we extend our deepest appreciation to Mr. Sidharth Das, for his
invaluable guidance, continuous support, and encouragement
throughout the duration of this project. Their insightful feedback
and expertise have been instrumental in shaping this work.
We are also indebted to Mrs. Devika Jena, for her unwavering
assistance and resources, which were crucial in the execution of
this project.
Furthermore, we extend our thanks to our fellow classmates for
their support and cooperation, without which the project would
not have been as enriching an experience.
Finally, we would like to thank our family and friends for their
understanding, patience, and unwavering encouragement during
this project.
We are deeply grateful for the collective efforts of all those
mentioned above, as their contributions have been pivotal in the
realization of this project.
OBJECTIVES
The objective of designing a Tic Tac Toe game using Arduino can serve several
purposes, including:

Educational Purposes: To provide a practical demonstration of programming logic


and concepts, introducing beginners to the world of embedded systems,
electronics, and programming.

Skill Enhancement: To improve programming skills by applying logic to a real-


life gaming application and understanding the integration of hardware and
software components.

Interactive Learning: To facilitate an interactive learning experience that


combines hardware and software aspects, encouraging enthusiasts to explore the
intersection of software and electronics.

Understanding Integration: To comprehend the integration of input/output devices


with an Arduino board and to gain hands-on experience in connecting various
components such as LEDs, buttons, and displays.

Fun and Entertainment: To create a simple, engaging project that can be enjoyed
by individuals of all ages, promoting the understanding and enjoyment of basic
game development and electronic circuits.

Thus, by designing Tic Tac Toe using Arduino, individuals can gain practical
experience in programming, hardware integration, and electronic circuits while
creating an enjoyable and interactive gaming experience.
INDEX
SERIAL NO. TITLE PAGE NO.
INTRODUCTION

Tic Tac Toe, often referred to as Xs and Os, is a classic and simple game
enjoyed by people of all ages. In this project, we aim to bring this
timeless game to life using the Arduino platform, combining the
principles of electronics and programming to create an interactive
gaming experience.

The project involves designing a physical interface that enables players


to interact with the game, making use of LEDs and buttons to represent
the grid and player moves. By implementing the logic of the game
through Arduino programming, we can create a responsive and
entertaining version of Tic Tac Toe that can be played with friends and
family.

It features a 3x3 LED grid that serves as the game board and two push
buttons for player input. The LED lights turn on to represent the moves
made by the two players, with each player's selected position using
different patterns of blinking.

The game has built-in logic to determine if a player has won, and the
LEDs display different patterns to indicate the winning combination.
Once a player wins, the game ends, and the board has to be reset for the
next round.
CIRCUIT DIAGRAM

CIRCUIT DIAGRAM OF TIC TAC TOE USING ARDUINO

WORKING CIRCUIT OF TIC TAC TOE USING ARDUINO


COMPONENTS
 Arduino Uno
 9 LEDs
 9 1K ohm resisters
 2 push buttons
 some jumper cables
 2 bread board
 USB cable
 Arduino IDE (software)
 Wires (as required)

Arduino Uno: The Arduino Uno is an open-source


microcontroller board based on the Microchip ATmega328P
microcontroller (MCU) and developed by Arduino.cc and initially
released in 2010. The microcontroller board is equipped with sets of
digital and analog input/output (I/O) pins that may be interfaced to
various expansion boards (shields) and other circuits. The board has 14
digital I/O pins (six capable of PWM output), 6 analog I/O pins, and is
programmable with the Arduino IDE (Integrated Development
Environment), via a type B USB cable. It can be powered by a USB
cable or a barrel connector that accepts voltages between 7 and 20 volts,
such as a rectangular 9-volt battery. It has the same microcontroller as
the Arduino Nano board, and the same headers as the Leonardo board.
The hardware reference design is distributed under a Creative Commons
Attribution Share-Alike 2.5 license and is available on the Arduino
website. Layout and production files for some versions of the hardware
are also available.
CONSTRUCTION & WORKING
Step 1: Setup the Hardware

Connect the components as per the schematic provided in the


image. The resistors are connected in series with the LEDs to
limit the current flow. The push buttons are connected to the
digital pins of the Arduino to detect player input.
Step 2: Set Up the Code in Arduino IDE

1. Open the Arduino IDE.


2. Open the attached src.ino file by File > Open. If needed create a sketch
folder by pressing "OK" in the next dialogue.
3. Go to Tools > Board and select "Arduino Uno" as the board type.
4. Go to Tools > Port and select the port to which the Arduino Uno is
connected.
5. Click on the "Upload" button to upload the code to the Arduino Uno
board.
6. Wait for the code to compile and upload to the board.
7. Once the code is uploaded, the game of Tic Tac Toe can be played using
the push buttons and LEDs connected to the Arduino Uno board.
ADVANTAGES
1. Educational Value: It provides a practical application for
learning programming concepts, electronics, and hardware
integration, making it an effective educational tool for
students and enthusiasts.
2. Hands-on Experience: The project allows for hands-on
experience in working with electronic components and
programming, fostering a deeper understanding of how
software and hardware interact.
3. Simplicity: Tic Tac Toe is a simple game that can be easily
understood, making it an accessible starting point for
individuals new to both programming and electronics.
4. Customization: The project can be customized and expanded
upon, allowing for the incorporation of additional features or
modifications to the game logic, providing a platform for
creative exploration.
5. Interactive Learning: It promotes interactive learning by
enabling individuals to physically interact with the game
through the use of buttons, LEDs, and other components,
thereby enhancing the overall learning experience.
6. Low Cost and Accessibility: Arduino boards are relatively
inexpensive and widely accessible, making the project
affordable and attainable for a broad range of individuals,
including students, hobbyists, and educators.
7. Integration Potential: The skills and knowledge gained from
this project can be applied to more complex projects and
applications, providing a foundation for the development of
more sophisticated electronic systems and games.
APPLICATION
The project of creating a Tic Tac Toe game using Arduino can
have several practical applications, including:

1. Education: It can be used as an educational tool to teach


programming and electronics to students. The project can
help in explaining concepts such as logic, conditional
statements, and hardware integration in a fun and interactive
manner.
2. Entertainment: The Tic Tac Toe game can serve as an
entertaining pastime for people of all ages. It can be used in
recreational settings like cafes, waiting areas, or community
centers to engage people in a light-hearted and enjoyable
gaming experience.
3. Skill Development: Developing the project can help
enthusiasts and beginners in programming and electronics to
enhance their skills. It can provide hands-on experience in
implementing algorithms, handling input/output devices, and
integrating hardware components with software.
4. Demonstration of Concepts: The project can serve as a
demonstration of the practical application of
microcontrollers like Arduino in real-world scenarios. It can
showcase how simple games can be implemented with
minimal hardware and programming knowledge.
5. Prototyping: Creating a simple game like Tic Tac Toe using
Arduino can serve as a prototype for more complex gaming
systems. It can be a starting point for those interested in
developing more sophisticated electronic games and
interactive systems.
6. Promotion of STEM Education: By utilizing the project as
part of STEM (Science, Technology, Engineering, and
Mathematics) education initiatives, it can inspire and
encourage students to explore the fields of electronics,
programming, and game development.
7. Creative Exploration: The project can encourage creative
exploration and experimentation in the field of interactive
game development. It can serve as a foundation for
enthusiasts to build more complex and innovative gaming
projects using Arduino and other microcontrollers.
CODE
const int LED_pins[] = {2,3,4,5,6,7,8,9,10}; // LED pins
const int button1_pin = 12; // Player 1 button pin
const int button2_pin = 11; // Player 2 button pin
const int selection_button_pin = 13; // Selection button pin

int board[3][3] = {{0,0,0},{0,0,0},{0,0,0}}; // Tic Tac Toe board


int tempBoard[3][3] = {{0,0,0},{0,0,0},{0,0,0}};
int currentPlayer = 1;
int cursor = 0;
int didwin[] = {0, 0, 0, 0, 0, 0, 0, 0};
int isai = 1;

int sum, sumh;


int gameon = 1;
void setup() {

Serial.begin(9600);

for (int i = 0; i < 9; i++) {


pinMode(LED_pins[i], OUTPUT); // set LED pins as outputs
}
pinMode(button1_pin, INPUT_PULLUP); // set Player 1 button pin as input with pull-up resistor
pinMode(button2_pin, INPUT_PULLUP); // set Player 2 button pin as input with pull-up resistor
pinMode(selection_button_pin, INPUT_PULLUP); // set Selection button pin as input with pull-up resistor

}
void loop() {

drawBoard();
cursorcheck();

if(digitalRead(button1_pin) == LOW) {
Serial.println("button 1");
handleInput(button1_pin);
delay(50);
}
if(digitalRead(selection_button_pin) == LOW && board[cursor/3][cursor%3] == 0) {
Serial.println("Selection");
handleSelec();
delay(50);
}
if(gameon == 1){
cursorblink(cursor);
}
checkWin();
displayWin();

}void drawBoard() {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
Serial.print(board[i][j]);
if (board[i][j] == 1) {
digitalWrite(LED_pins[i*3+j], HIGH); // turn on LED for X 100%
}
else if (board[i][j] == 2) {
digitalWrite(LED_pins[i*3+j], HIGH);
delay(1);
digitalWrite(LED_pins[i*3+j], LOW);
delay(1); // turn on LED for O 50%
}
else {
digitalWrite(LED_pins[i*3+j], LOW); // turn off LED if no X or O
}
}
}
Serial.println(cursor);
delay(500);
}
void handleInput(int buttonPin) {

// Player 1 button
//Serial.println("Pressed!");
if (cursor == 8){
cursor = 0;
}
else {
cursor = cursor+1;
}
Serial.println(cursor);
delay(250);
}
void handleSelec() {
Serial.println("Selected!");
board[cursor/3][cursor%3] = currentPlayer;
if(currentPlayer == 1) {
currentPlayer = 2;
}else {
currentPlayer = 1;
}
cursor = 0;
}
void cursorcheck() {
for(int q = 0; q < 9-cursor; q++){
if(board[cursor/3][cursor%3] != 0) {
cursor += 1;
}
}
}
void cursorblink(int tempcursor){
digitalWrite(LED_pins[tempcursor], HIGH);
delay(50);
digitalWrite(LED_pins[tempcursor], LOW);
delay(50);
}
void checkWin() {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if(board[i][j]==0) {
tempBoard[i][j] = 9;
}else{tempBoard[i][j] = board[i][j];}

Serial.print(tempBoard[i][j]);
Serial.print("|");
}
}
Serial.println();
didwin[6] = 0;
didwin[7] = 0;
for (int i = 0; i < 3; i++) {
sum = 0;
sumh = 0;
didwin[6] += tempBoard[i][i];
didwin[7] += tempBoard[i][2-i];
for (int j = 0; j < 3; j++) {
sum += tempBoard[i][j];
sumh += tempBoard[j][i];
}
didwin[i] = sum;
didwin[3+i] = sumh;
}

for(int k = 0; k < 7; k++){


Serial.print(didwin[k]);
}
Serial.println();
}

void displayWin () {
for(int p = 0; p < 8; p++) {
if (didwin[p] == 3) {
gameon = 0;
int new_board[3][3] = {{1,1,0},{0,1,0},{1,1,1}};
memcpy(board, new_board, sizeof(new_board));
break;
}
if (didwin[p] == 6) {
gameon = 0;
int new_board[3][3] = {{1,1,1},{1,1,0},{1,1,1}};
memcpy(board, new_board, sizeof(new_board));
break;
}
delay(500);
}
}
RESULTS
CONCLUSION
In conclusion, the development of the Tic Tac Toe game using the
Arduino platform has proven to be an insightful and enriching
journey. Through this project, we have successfully demonstrated the
integration of hardware components with software logic, creating an
interactive gaming experience that combines the principles of
electronics and programming.

By delving into the implementation of the game logic, the utilization


of input and output devices, and the understanding of Arduino
programming, we have not only created a functional gaming system
but also gained valuable insights into the world of embedded systems
and microcontroller applications.

The project has not only provided an enjoyable and entertaining


experience for players but has also served as a practical educational
tool, fostering a deeper understanding of fundamental programming
concepts, circuit design, and hardware integration.

As we conclude this project, we recognize the potential for further


expansion and customization, encouraging the exploration of more
complex game development and interactive systems using the
Arduino platform. The skills acquired and the knowledge gained
throughout this project can serve as a solid foundation for future
endeavors in the realms of electronics, programming, and embedded
systems.

We hope that this project has not only inspired a deeper appreciation
for the application of Arduino in gaming but has also sparked a
curiosity and passion for further exploration and innovation in the
exciting field of electronics and programming.

You might also like