Phiro Arduino Board Game

Create a Game to make Phiro and its Arduino color sensor to move on a color path and reach the end to win. Make an automatic virtual dice program using Pocket Code to program Phiro moves. When Red is detected, take 1 step back, when Green is detected, take 1 step forward. You win when Phiro reaches Blue!

Objective

By the end of this lesson, learners will

  • Understand and program a virtual dice
  • Program Phiro movement in response to virtual dice
  • Understand and program Arduino color sensors
  • Extend Phiro's function with Arduino board
  • Connect the physical and mobile digital worlds
Subjects

Coding, Technology, Game, Maths, Engineering

Age

12 - 18 Years

Duration

60min

Robot & Accessories Needed

Phiro Pro robot, Phiro LEGO connector, Arduino UNO board + Arduino Adapter, HC-05 Bluetooth.

Download Material

Click here to Download

Other Accessories

Color Sensor, Connecting Wires, 9V Battery, Board Game Mat, Double sided tape.

Software

POCKETCODE4PHIRO

Review

Intro to Robotics & Coding,User Manual
Click here to learn about Pocket Code Blocks

  • step1
  • step2
  • step3
  • step4
  • step5
  • step6
STEP 1

Ask

How do dice in board games work?

How about a virtual dice?

How would you create a virtual dice to generate dice numbers, i.e. 1, 2, 3 etc.

What do you need to create a virtual dice that programs Phiro to move a "#" step forward?

How do color sensors detect different colors? What all can you do with color sensor information?

What values do color sensors have for Red, Green, Blue, White and other colors?

How can color sensors be programmed?

STEP 2

Imagine

What would you need in Phiro, Arduino and Pocket Code to solve this problem?

Imagine how your virtual dice programs Phiro movements, detects color and move accordingly?

1. Generate dice numbers & Move Phiro dice number of steps

2. Detect color & Move Phiro based on detected color

STEP 3

Plan

The challenge is to generate a virtual dice using Pocket Code and make Phiro move dice number of steps, and the following can happen:

If Phiro reaches the Green Square, take one step Forward as credit

If Phiro reaches the Red Square, take one step Backward as penalty

If Phiro reaches the Blue Square, Pocket Code says "Reached Destination"


Connecting Phiro, Arduino and Color Sensor

Make sure you have all the hardware components to connect up your Phiro Pro + Arduino + Color Sensor, and the board game color path mat. Find the free downloadable color mat file under "Download Material" in the lesson tags on top of page.

Board Game Code

Plan your game in 2 parts:

1.Generate dice numbers & Move Phiro dice number of steps

2.Detect color & Move Phiro based on detected color

STEP 4

Create

Time to get create your Phiro Arduino Board Game!

Connecting Phiro, Arduino and Color Sensor


To connect Phiro and Arduino with Pocket Code, you will need to have "Standard Firmata" on the Arduino Board. Here are the steps to upload Standard firmata.

In Arduino IDE,

1. Select the COM Port - Tools -> Serial Port -> Corresponding COM Port

2. Select your Arduino Board. Tools -> Board -> Your Arduino Board (We have used an Arduino UNO, but you can use any Arduino board)

3. Select the Standard Firmata. Click on Examples -> Firmata -> Standard firmata

4. Click on Upload


Code

Before you create your Main Board Game Code, let's figure how to detect color sensor values (which you will need in your main board game code) by creating easy code in Pocket Code, using the color path mat and Arduino connected Phiro. Place Phiro on each color square and detect sensor values.

Detect sensor values and note the value of a0 (Red), a1 (Blue) & a2 (Green). For example, we got values of a0 in between 180-200 for Red, a1 in between 170-180 for Green, a2 in between 181-190.

Note: Values will vary according to user environment. Use only the values you got with this code and use it in the main board game program.

Main Board Game Code

1.Generate dice numbers & Move Phiro dice number of steps

2.Detect color & Move Phiro based on detected color

1.Generate dice numbers & Move Phiro dice number of steps

Create a program to generate a virtual dice using Pocket Code and make Phiro move dice number of steps forward.

If Phiro reaches the Green Square, take one step Forward as credit

If Phiro reaches the Red Square, take one step Backward as penalty

If Phiro reaches the Blue Square, Pocket Code announces "Reached Destination"

Use above three looks in one sprite with look name 1, 2 & 3 respectively.

Initializing default value of variables a0, a1 & a2 to Arduino AnalogPin0, AnalogPin1 & AnalogPin2 respectively.

Initializing default LED Color

Initializing default Sprite Look to 1

Initializing Variable Random to 1

Generating Random value in between 30 to 50

Increasing variable random by 1 for each change of look

Using "Next Look" block animating dice

Checking generated random value and map its value to Dice value using "MOD" function.

Using Repeat block, move Phiro Random dice number of times

2. Detect color & Move Phiro based on detected color

Checking color of Final Square using a0 variable and if it's Red, Phiro LED glows Red and moves 1 step Backward.

Checking color of Final Square using a1 variable and if it's Green, Phiro LED glows Green and moves 1 step Forward.

Checking color of Final Square using a2 variable and if it's Blue, Phiro LED glows Blue and Pocket Code says "Reached Destination"

Test your board game

Once your main board game code is completed, place Phiro on color path mat. Switch on Phiro robot and select Bluetooth Mode. Connect battery to Arduino to turn it on. Press Play on your board game program and make sure to connect with both the Arduino Bluetooth and Phiro Bluetooth. Tap the program to generate Dice numbers and play.

STEP 5

Remix

Remix this program for Phiro to check any color and make Phiro LED to glow the same color.

STEP 6

Share

Share your Phiro Arduino Color Board Game with us using #MyPhiro and tag us @RobotixLS