element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
microbit
  • Learn
  • Learning Center
  • STEM Academy
  • microbit
  • More
  • Cancel
microbit
micro:bit Blog Save the Bees - A micro:bit project - The Flower
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join microbit to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: hifromkatie
  • Date Created: 2 Nov 2023 3:43 PM Date Created
  • Views 960 views
  • Likes 9 likes
  • Comments 2 comments
Related
Recommended

Save the Bees - A micro:bit project - The Flower

hifromkatie
hifromkatie
2 Nov 2023

The Flower

In each game there must be at least 1 Flower micro:bit/player.

This player will hide, and the Bee must find them (after collecting Pollen) to pollinate the Flower.

See game instructions

You will need:

1 Micro:bit
1 Battery box and batteries
1 USB programming cable

You will also need a computer connected to the Internet that has a USB input in order to program each micro:bit.

Instructions:

On the computer, point your browser to https://makecode.microbit.org/  and select  New Project.

image 

Name this project Flower.

image

on Start Block

We'll use the "on start" block,

image

to set up the game.

Under "Radio" then "... more" we can find the "radio set transmit power" block.

image

Click on that block and drag it into the "on start" block. Then change the value in the white box to 0.

The value to 0 means we will be limiting the radio transmission to the lowest possible setting, which means the micro:bits will need to be within around a meter of each other to be able to "talk" to each other.

image

Create a Variable

The next step is to create a variable called "game" using the "Make a Variable..." button inside the "Variables" menu.

To do this, go to 

image

Then 

image

Then name the variable and click OK. 

image

Your Variables should look like this:

image

Set the Values of the Variables

Now we are going to use the "set" block to set the variable to 0 to start the game.

In the Variables menu, click the "set" block and drag it on to the "on start" block beneath "radio set transmit power." The variable will default to "count".

Now drag another "set" block to "on start" and, using the drop down, change the variable name to "game."  

We are then going to use the "set" block to set both of these to 0 at the start of the game.
Note: the block is the same for all, once you drag it into the code, you select the down arrow in the block to change which variable it refers to.

Then we are going to use "show leds" block to display an "F", showing that this is running the Flower code.

image

Starting the Game

To start the game, we want to change the variable "game" to 1 to indicate the game has started and we want to display a Flower icon to show that this micro:bit is a Flower.  We will do this by pressing the A button on the micro:bit.

To do this, go to the "Input" menu, click on the "on button 'A' pressed" block and drag it to the workspace.

image

Inside this block we will place the "set" block from the Variables menu.

Go to Variables, click on the "set" block and drag it in to the "on button A pressed" block. Click on the white circle and change the value to 1.

To add the Flower icon to the micro:bit display, go to Basic and click and drag the "show icon" block into the "on button A pressed" block. In the drop down for the icons, select the Flower. 

image

Your "on button A pressed" block should look like this:

image

Receiving Radio Signals

When the A button is pressed on the micro:bit, the game is underway. Remember, we set the radio transmit area to 0 in the "on start" block. That means the radio works to a distance of about 1 meter so the Bee will have to find the other players and see what messages those micro:bits are sending.

To see if there are any micro:bits transmitting in the area, we will go to the Radio menu, click on the "on radio received receivedString", and drag it to the workspace.

image

Since the Flower's micro:bit will be receiving strings from the other players' micro:bits, we need to define what we're looking for ("Bee" and "Pollen") and then tell the micro:bit what to do based on the value received. To do this we'll be using "If" blocks. The first thing we'll check for is whether or not the game has started.  

If you'd like more information on how this block works, see the MakeCode help section on the "If" block.

Checking if the Game Has Started

In the Logic menu, click on the "if" block and drag it into the "on radio received receivedString" block. 

image

We want to replace the "true" drop down with a comparison - so that we can compare the value to what we want the value to be. In this case, we want the game to have started, so we're looking for the "game" variable to be set to "1" (we set this in the final step of the  "on button A pressed" block above).

Go to Logic and then select the comparison block that looks like this

image

and drag it on top of the if block: 

image

What we are looking for is the "game" variable to be set to 1. To look for this comparison, we'll drag the "game" variable from the Variables menu 

image

and drag it on top of the left value of the "If" block to the left of the equal sign:

image

and then change the value from 0 to 1. This tells the micro:bit that if the "game" variable is set to 1, run the rest of the if blocks nested within. But if the "game" variable is not 1, then it will do nothing. 

Waiting for a Bee

Once the game is live (the variable is set to 1), the next signal we're waiting for is one from the Bee. Once we receive the Bee signal, we will:

  • take the Flower out of the current game,
  • play a happy tone,
  • tell the Bee "thank you" for the pollen, 
  • and display a heart icon.

To do this we will first check for a text string received that equals "Bee."

To do this, go to Logic and click on an "If" block and drag it in to the existing "on radio received" block, inside the existing "If" block for game.

image

In this "If" block we are looking for the the received string to be "Bee."  

We will change the "true" statement to a comparison - this time we're looking for a text string (words/letters), not a number, so drag this comparison on to the "If" block

image

The block should look like this:

image

We want to compare the value received by radio signal from another micro:bit to the value "Bee."  

Click on the "receivedString" variable name in the "on radio received" block and drag it on the "If" block to the left of the equal sign.

image

Then click in the box to the right of the equal sign and type in "Bee". If the value is "Bee" then the rest of the actions in this "If" block will run.

Take the Flower out of the Current Game

A Flower can only be pollinated once, so we remove the Flower from the game by setting the "game" variable back to 0.

To do this, go to Variables and click on a "set" block and drag it in to to "If" block, then change the variable to "game" using the drop-down.

image

Play a Happy Tone

Next, we will play a melody from the micro:bit library to indicate our Flower is happily pollinated. 

In Music, find the "play melody" block

image

and drag it into the "If" block under the game variable block. Use the drop down to select a melody (I chose entertainer).

image

Tell the Bee Thank You

We're going to send a radio message to the Bee's micro:bit. We do this not just because it's polite to say "thank you", but also to ensure the Bee gets credit for finding and pollinating this Flower. Every time a Bee gets a "thank you" from a Flower, its score increases by 1.

To do this, go to Radio and click on the "radio send string" block

image

and drag it in in to the "If" block beneath the melody player block.

Click in the white text box and enter "thanks"

Display a Heart

This happy Flower is now out of the current game. To indicate that I have put in a "show icon" block displaying a heart.

Go to Basic, click the "show icon" block and drag it in to the "If" block under the "radio send string"

The final "on radio receive" block should look like this

image

This is the code for the Flower Micro:bit complete, you also need a pollinator and a bee, and then you can go and play!

image

Be sure to save your work!  At the bottom of the screen you'll see the save interface, click the save icon to save your work.

image

The final step is adding the code to a micro:bit. See the micro:bit guide for programming here: https://microbit.org/get-started/user-guide/transfer-code-to-the-microbit/ if you require assistance with this step.

Now on to Pollen and Bee. 

Pollen program instructions

Bee program instructions

  • Sign in to reply
  • hifromkatie
    hifromkatie over 1 year ago in reply to kmikemoo

    Perfect, hope you enjoy it if you give it ago!
    Let me know if you have any issues.
    I've been using/teaching kids to program micro:bits since 2016, so it'll be interesting how someone new to the device finds the instructions.

    The BBC helped develop the micro:bit, and provided every UK secondary school (11-16) student one when they first came out, and code clubs in Primary schools got a set back in 2016 or 2017. So they were quite popular in the UK. There has just been a new donation of a 30 pack to every UK primary school of the V2 that applied for a pack (5 to 11 year olds), so hopefully that'll give them a new push

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • kmikemoo
    kmikemoo over 1 year ago

    hifromkatie What a cute game!  I have three Micro:bits headed my way (Thank you Project14) so I can try it out when they arrive.  Our schools don't use Micro:bits (that I know), but this would be a great demonstration to spark that interest.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube