EHD Project Report(Arduino)

21
PROJECT REPORT ON TIC TAC TOE GAME USING ARDUINO PREPARED IN THE PARTIAL FULLFILMENT OF EL203 EMBEDDED HARDWARE DESIGN PROJECT Submitted by:- ARIJIT BASU (201101117) EKTA ARORA (201101116) KANIKA MEHTA (201101118) MANAS ROY (201101115) III rd Year, B.Tech. (ICT) Under the guidance of Prof. Rahul Dubey DHIRUBHAI AMBANI INSTITUTE OF INFORMATION AND COMMUNICATION TECHNOLOGY GANDHINAGAR, GUJARAT

description

EHD project

Transcript of EHD Project Report(Arduino)

Page 1: EHD Project Report(Arduino)

PROJECT REPORT

ON

TIC TAC TOE GAME USING ARDUINO PREPARED IN THE PARTIAL FULLFILMENT OF EL203 EMBEDDED

HARDWARE DESIGN PROJECT

Submitted by:-

ARIJIT BASU (201101117)

EKTA ARORA (201101116)

KANIKA MEHTA (201101118)

MANAS ROY (201101115)

III rd Year, B.Tech. (ICT)

Under the guidance of

Prof. Rahul Dubey

DHIRUBHAI AMBANI INSTITUTE OF INFORMATION AND

COMMUNICATION TECHNOLOGY

GANDHINAGAR, GUJARAT

Page 2: EHD Project Report(Arduino)

Arijit Basu (201101117) Ekta Arora (201101116) Kanika Mehta (201101118) Manas Roy (201101115)

ACKNOWLEDGEMENT

We would like to thank Prof. Rahul Dubey for giving us the opportunity to do this project

and helping us get started. We would also like to thank him for his continuous guidance and

support.

We would also like to thank our teaching Assistants.

Finally I would like to thank my family and friends for putting up with my constant

moaning about the project and supporting me through the difficult times!

Page 3: EHD Project Report(Arduino)

Arijit Basu (201101117) Ekta Arora (201101116) Kanika Mehta (201101118) Manas Roy (201101115)

Table of contents

1.0 Team members

2.0 Project Requirement

3.0 Project Specifications

4.0 Design Methodology

5.0 Software Algorithm and Flowchart

6.0 Hardware Schematic

7.0 Testing

8.0 Appendix

Page 4: EHD Project Report(Arduino)

Arijit Basu (201101117) Ekta Arora (201101116) Kanika Mehta (201101118) Manas Roy (201101115)

1.0 TEAM MEMBERS AND RESPONSIBILITY

1. Manas Roy 201101115

Contributed in building the circuit on the breadboard.

2. Ekta Arora 201101116

Contributed in the documentation and building of the algorithm.

3. Arijit Basu 201101117

Contributed in the documentation and software.

4. Kanika Mehta 201101118

Contributed in building the algorithm and software.

Page 5: EHD Project Report(Arduino)

Arijit Basu (201101117) Ekta Arora (201101116) Kanika Mehta (201101118) Manas Roy (201101115)

2.0 REQUIREMENTS

The purpose of the project was to build a two player Tic-Tac-Toe game. The Tic-Tac-Toe was

designed to meet specifications that were set to ensure a user friendly game.

The objective of the project was:-

1) To learn the basic design process of an Arduino

2) To learn the basic functionality of an IR Sensor (TSOP)

3) To design a 2 player Tic-Tac-Toe game and meet specifications.

4) To gain experience using Arduino along with processing IDE.

Tic Tac Toe is an entertainment game and a fun way to learn the basic design process of an

Arduino. The use of IR rays to interface with external hardware using sensors has many

important implications.

This document explains the layout process of the project. Finally recommendations for people

working on similar projects and possible future work are provided.

Page 6: EHD Project Report(Arduino)

Arijit Basu (201101117) Ekta Arora (201101116) Kanika Mehta (201101118) Manas Roy (201101115) Page 1

3.0 SPECIFICATION

The Tic-Tac-Toe project is an interactive game between two players. The circuit was built

using Arduino as an open source electronic platform. Arduino can sense the environment by

receiving input from a variety of sensors and can affect its surroundings by controlling

lights, motors, and other actuators.

Following specification was decided for our project.

1. A tic-tac-toe game with a mesh of 3x3 LEDs.

2. Controlled via a TV Remote. (IR). 1-9 keys on remote denote the position of the LED.

3. A player alternates using the TV Remote.

4. The first player's LED is always bright (solids) and the second player's LED blinks. (a

novel idea considering we had only 1 color LED's.)

In most cases, the objectives of the project were met. The TSOP was used as an IR sensor to

receive input from the TV remote and the Arduino decoded the input using the predefined

library IRremote.h.

Page 7: EHD Project Report(Arduino)

Arijit Basu (201101117) Ekta Arora (201101116) Kanika Mehta (201101118) Manas Roy (201101115)

4.0 DESIGN METHOLOGY

In this section, the steps taken to design the circuit are explained. The topology of the

circuit is explained first followed by a brief description of IRremote.h. Finally the output for

each button 1-9 of the IR Remote is calculated experimentally.

4.1 TSOP 1738 IR SENSOR

Tsop is an IR receiver which will help you to interface your TV remote with arduino.

The TSOP outputs a constant HIGH signal when idle and as it receives data, it tends to invert the

data. i.e when an IR LED is transmitting data onto the TSOP, every time the IR led goes high,

the TSOP will go LOW and vice versa. Remote control signals are often bytes of data that is

encoded and transmitted by pulsing(switching ON & OFF the IR LED at a specific frequency)

Most TV remote controls work at 32-40 Khz frequency and most receivers can receive this

range.

The SIRC protocol uses a pulse width encoding of the bits. The pulse representing a logical "1"

is a 1.2ms long burst of the 40kHz carrier, while the burst width for a logical "0" is 0.6ms long.

All bursts are separated by a 0.6ms long space interval

4.1.1 TSOP PHYSICAL STRUCTURE

The photo module has a circuitry inside for amplifying the coded pulses from the IR transmitter.

The front end of the circuit has a PIN photodiode and the input signal is passed into an

Automatic Gain Control(AGC) stage from which the signal passes into a Band pass filter and

finally into a demodulator. The demodulated output drives an NPN transistor. The collector of

this transistor forms the output at pin3 of the module. Output remains high giving + 5 V in the

standby state and sinks current when the PIN photodiode receives the modulated IR signals

4.1.2 MODULATION IN TSOP

The black bars in the below image correspond to high signals (called marks) and the

white spaces in between correspond to low signals (called spaces). The duration of the 'marks'

Page 8: EHD Project Report(Arduino)

Arijit Basu (201101117) Ekta Arora (201101116) Kanika Mehta (201101118) Manas Roy (201101115)

varies according to the bit being transmitted. It is 2.4ms for the start bit, 1.2ms for HIGH bit and

0.6ms for LOW bit. The duration of the 'spaces' is a constant 0.6ms. Every mark is followed by a

space. Any data can be converted to binary format and transmitted in this manner. In fact this is

the basic form of all types of Serial Communication.

4.1.3 Specifications of TSOP 1738 IR Receiver is :-

1. Supply Voltage: –0.3...6.0 V.

2. Supply Current: 5 mA.

3. Output Voltage: –0.3...6.0 V.

4. Output Current: 5 mA.

5. Junction Temperature: 100 °C

6. Storage Temperature Range: –25...+85 °C

7. Operating Temperature Range: –25...+85°C

Page 9: EHD Project Report(Arduino)

Arijit Basu (201101117) Ekta Arora (201101116) Kanika Mehta (201101118) Manas Roy (201101115)

The input voltage Vs and GND for the TSOP is given directly from the 5V power pin and

the GND of the Arduino. The output of the TSOP is received in the digital pin 11 of the output.

4.2 IRremote.h

The library function IRremote was used to decode the bitstream value from the remote

and run the Tic Tac Toe code. IRremote acts like 2 libraries, one for sending and one for

receiving. Usually it's easiest to find the codes to transmit by first using the receiver.

Receiving

IRrecv irrecv(receivePin)

Create the receiver object, using a name of your choice.

irrecv.enableIRIn()

Begin the receiving process. This will enable the timer interrupt which consumes a small amount

of CPU every 50 µs.

irrecv.decode(&results)

Attempt to receive a IR code. Returns true if a code was received, or false if nothing received

yet. When a code is received, information is stored into "results".

results.decode_type: Will be one of the following: NEC, SONY, RC5, RC6, or UNKNOWN.

results.value: The actual IR code (0 if type is UNKNOWN)

results.bits: The number of bits used by this code

results.rawbuf: An array of IR pulse times

results.rawlen: The number of items stored in the array

irrecv.resume()

After receiving, this must be called to reset the receiver and prepare it to receive another code.

irrecv.blink13(true)

Enable blinking the LED when during reception. Because you can't see infrared light, blinking

the LED can be useful while troubleshooting, or just to give visual feedback.

IRremote requires a timer for both transmitting and receiving.

Page 10: EHD Project Report(Arduino)

Arijit Basu (201101117) Ekta Arora (201101116) Kanika Mehta (201101118) Manas Roy (201101115)

4.3 DECODING THE BUTTONS 1-9 FROM THE REMOTE

The following code was used to receive the decoded values in the Serial Monitor. The

values calculated in the flowchart are used in the main code for the Tic-Tac-Toe game.

#include <IRremote.h>

int RECV_PIN = 11;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()

{

Serial.begin(9600);

irrecv.enableIRIn(); // Start the receiver

}

void loop() {

if (irrecv.decode(&results)) {

Serial.println(results.value, HEX);

irrecv.resume(); // Receive the next value

}

}

BUTTON REMOTE_VALUE.DECODE

0 948321216

1 948321248

2 948321232

3 948321264

4 948321224

5 948321256

6 948321240

7 948321272

8 948321220

9 948321252

The decoded value is used by the micro controller of the Arduino to determine the input

value from the remote.

Page 11: EHD Project Report(Arduino)

Arijit Basu (201101117) Ekta Arora (201101116) Kanika Mehta (201101118) Manas Roy (201101115)

5.0 SOFTWARE ALGORITHM AND FLOWCHART

5.1.1 ALGORITHM FOR TIC TAC TOE

1) For i=1 to i=9

Begin:

Set pinMode i=OUTPUT

End

2)user=1

3) Initialize the reciever object

4)Wait for TSOP to receive value

5) if result=input from the remote

Begin

For i=1 to i=9

Begin:

If(button_value(i)=result)

If(user=1)

Begin:

Set LED(i)=HIGH

User=2

End

Else

Begin:

LED(i)=BLINK

User=1

End

Page 12: EHD Project Report(Arduino)

Arijit Basu (201101117) Ekta Arora (201101116) Kanika Mehta (201101118) Manas Roy (201101115)

6)If no. of turns=9 or if either of the player wins EXIT.

5.1.2 ALGORITHM FOR WINNING

1) If no. of turns<9

Begin:

For j=1 to j=2

Begin

For i=1 to i=3

Begin:

If(Row[i] is filled by user[j]) or Column[i] is filled by user[j])

Return WIN;

If(Diagonal elements are filled by user[j])

Return WIN

End

End

Else

Return DRAW

End

Page 13: EHD Project Report(Arduino)

Arijit Basu (201101117) Ekta Arora (201101116) Kanika Mehta (201101118) Manas Roy (201101115)

5.2 FLOWCHART

5.2.1 Tic-tac-toe Flow-Chart

No

Yes

Yes No

No Yes Yes

No

Start

Result=Input

from remote

If Button[i].encodedValue==result.value

If user==player1

LED[i] High, count++ LED[i] Blink, count++

User=player2 User=player1

User=player1, count=0

C

If player1 wins or

count==9

EXIT EXIT

If player2 wins or

count==9

Page 14: EHD Project Report(Arduino)

Arijit Basu (201101117) Ekta Arora (201101116) Kanika Mehta (201101118) Manas Roy (201101115)

5.2.2 Wining Flowchart

a) For player1

b) For player2

Similar to the player1 case if the led BLINKS rather than being HIGH.

Start

If

Atleast one row out of the three rows or atleast one column out of the three

columns or atleast one diagonal out of the two diagonals is HIGH

player1 WINS

Page 15: EHD Project Report(Arduino)

Arijit Basu (201101117) Ekta Arora (201101116) Kanika Mehta (201101118) Manas Roy (201101115)

6.0 HARDWARE SCHEMATIC

1) Pin 2-10 are connected to corresponding LED’s.

2) The pin 1 of TSOP is connected to the GND pin of the Arduino. Pin 2 of the TSOP is

connected to the 5V power pin and Pin 3 is connected to the digital pin 11 of the Arduino.

3) The LED’s can be grounded using the GND pin of the Arduino.

Page 16: EHD Project Report(Arduino)

Arijit Basu (201101117) Ekta Arora (201101116) Kanika Mehta (201101118) Manas Roy (201101115)

7.0 OBSERVATION AND TEST RESULT

TEST NUMBER TEST DONE RESULT

1

Pressing numbers 1 to 9 of the

remote and printing the

corresponding bit code of each

number on the serial monitor.

Every output corresponding to

each button input had different

bit code and were printed

accordingly.

2 Check if the led corresponding

to each button is responding.

Every led was responding on

its corresponding button click.

3

Check if the led is HIGH and

BLINKING for player1 and

player2 respectively.

The alternate chosen LEDs by

the button click were HIGH

and BLINKING.

4 Check if the winning

condition is detected correctly.

Winning condition is satisfied

correctly.

Page 17: EHD Project Report(Arduino)

Arijit Basu (201101117) Ekta Arora (201101116) Kanika Mehta (201101118) Manas Roy (201101115)

8.0 APPENDIX – CODE

#include <IRremote.h> int RECV_PIN = 11; IRrecv irrecv(RECV_PIN); decode_results results; int i = 0; int blinkarray[11]; int user=0; int flag=0; void setup() { for(i=2;i<11;i++) { pinMode(i,OUTPUT); } irrecv.enableIRIn(); // Start the Remote receiver Serial.begin(9600); } void loop() {

over: if(flag==9)

{ flag++;

Serial.println("Draw"); for(int j=2;j<11;j++) {

if(blinkarray[j]==2) digitalWrite(j,LOW); } } if(flag<9)

{ if(win()) { Serial.print("Player "); Serial.print(user+1); Serial.println(" win"); flag=10; for(int j=2;j<11;j++)

{ digitalWrite(j,LOW);

Page 18: EHD Project Report(Arduino)

Arijit Basu (201101117) Ekta Arora (201101116) Kanika Mehta (201101118) Manas Roy (201101115)

} goto over; } blinkOrNot(); Serial.println("Player"); Serial.print(" "); Serial.println(user+1); for(i=0;i<=90000;i++) { if(irrecv.decode(&results)) goto cont; } cont: switch(results.value) // if the '+' button is pressed { case 948321248: i=1; setArray(); break;// 948321248 is the value for '1' case 948321232: i=2; setArray(); break;// 948321232 is the value for '2' case 948321264: i=3; setArray(); break;// 948321264 is the value for '3' case 948321224:

i=4; setArray(); break;// 948321224 is the value for '4' case 948321256: i=5; setArray(); break;// 948321256 is the value for '5' case 948321240: i=6; setArray(); break;// 948321240 is the value for '6' case 948321272: i=7; setArray(); break;// 948321272 is the value for '7' case 948321220: i=8;

Page 19: EHD Project Report(Arduino)

Arijit Basu (201101117) Ekta Arora (201101116) Kanika Mehta (201101118) Manas Roy (201101115)

setArray(); break;// 948321220 is the value for '8' case 948321252: i=9; setArray(); break;// 948321252 is the value for '9' case 948321216: i=0; break;// 948321216 is the value for '0' } delay(300); // small delay to avoid debounce irrecv.resume(); // Receive the next value } }

void blinkOrNot() {

for(int j=2;j<11;j++) {

if(blinkarray[j]==1) { digitalWrite(j,HIGH); }

} for(int j=2;j<11;j++)

{ if(blinkarray[j]==2) { digitalWrite(j,HIGH); }

} for(int j=2;j<11;j++)

{ if(blinkarray[j]==2) { delay(50); }

} for(int j=2;j<11;j++)

{ if(blinkarray[j]==2) { digitalWrite(j,LOW); } } for(int j=2;j<11;j++)

{

Page 20: EHD Project Report(Arduino)

Arijit Basu (201101117) Ekta Arora (201101116) Kanika Mehta (201101118) Manas Roy (201101115)

if(blinkarray[j]==2) { delay(50); }

} }

void setArray() {

if(user==0) {

blinkarray[i+1]=1; user=1; flag++; } else

{ blinkarray[i+1]=2; user=0; flag++; } } boolean win() { if(user==0) { if(blinkarray[2]==blinkarray[3]&&blinkarray[3]==blinkarray[4]&&blinkarray[4]==1) return true; else if(blinkarray[5]==blinkarray[6]&&blinkarray[6]==blinkarray[7]&&blinkarray[7]==1) return true; else if(blinkarray[8]==blinkarray[9]&&blinkarray[9]==blinkarray[10]&&blinkarray[10]==1) return true; else if(blinkarray[2]==blinkarray[5]&&blinkarray[5]==blinkarray[8]&&blinkarray[8]==1) return true; else if(blinkarray[3]==blinkarray[6]&&blinkarray[6]==blinkarray[9]&&blinkarray[9]==1) return true; else if(blinkarray[4]==blinkarray[7]&&blinkarray[7]==blinkarray[10]&&blinkarray[10]==1) return true; else if(blinkarray[2]==blinkarray[6]&&blinkarray[6]==blinkarray[10]&&blinkarray[10]==1) return true; else if(blinkarray[4]==blinkarray[6]&&blinkarray[6]==blinkarray[8]&&blinkarray[8]==1) return true; else return false;

} else{

if(blinkarray[2]==blinkarray[3]&&blinkarray[3]==blinkarray[4]&&blinkarray[4]==2) return true;

Page 21: EHD Project Report(Arduino)

Arijit Basu (201101117) Ekta Arora (201101116) Kanika Mehta (201101118) Manas Roy (201101115)

else if(blinkarray[5]==blinkarray[6]&&blinkarray[6]==blinkarray[7]&&blinkarray[7]==2) return true; else if(blinkarray[8]==blinkarray[9]&&blinkarray[9]==blinkarray[10]&&blinkarray[10]==2) return true; else if(blinkarray[2]==blinkarray[5]&&blinkarray[5]==blinkarray[8]&&blinkarray[8]==2) return true; else if(blinkarray[3]==blinkarray[6]&&blinkarray[6]==blinkarray[9]&&blinkarray[9]==2) return true; else if(blinkarray[4]==blinkarray[7]&&blinkarray[7]==blinkarray[10]&&blinkarray[10]==2) return true; else if(blinkarray[2]==blinkarray[6]&&blinkarray[6]==blinkarray[10]&&blinkarray[10]==2) return true; else if(blinkarray[4]==blinkarray[6]&&blinkarray[6]==blinkarray[8]&&blinkarray[8]==2) return true; else return false; } }