RedLightGreenLight Game System With Microbit Player Detection Features (non-violent)

by FrankYun123 in Teachers > 12

643 Views, 3 Favorites, 0 Comments

RedLightGreenLight Game System With Microbit Player Detection Features (non-violent)

Build Your Own Players Detection Red Light Green Light Game System Part1 #microbit #arduino
Red Light, Green Light

What is this Red Light Green Light Game System?

It comes from the most popular Netflix TV show Squid Game about a series of deadly games, but don't worry! The game I'm showing you has all the bad stuff taken out, so it's totally safe to play with children.

Rules of this game:

The players' goal is to reach the finish line before the countdown on the laptop stops. Players must freeze when the red light is on and move forward when the green light is on. 

The game without high tech is introduced in the second video.

Tech brief introduction:

1. Before the game starts, all players must wear a Microbit beacon on their arms. 

2. The Microbit beacon can detect if a player is moving with its onboard accelerometer. 

3. The beacon also constantly sends a radio signal to three receivers with antennas facing up and one receiver with the antenna facing all the players at the finish line. This setup can be used to detect if the player has reached this finish line. (I explained how the system works in the first 20 minutes long video.)


Upadates might be made to this tutorial.

Last upadate date: 11:00 AM Jan29, 2023 (GMT)

Supplies

Make you will need.jpg

1 a loptop

2. a usb speaker

3. a tv as extended display which is optional.

4.a tripod

5. a tripod cellphone mount.

https://www.amazon.com/Vastar-Universal-Smartphone-Horizontal-Adjustable/dp/B01L3B5PBI/ref=sr_1_4?crid=VDU8STMQB7PV&keywords=tripod+cellphone+mount&qid=1674974896&sprefix=tripod+cellphone+mount%2Caps%2C373&sr=8-4

6. a high quality shielded usb cable extension, or you can use one meter long Microbit compatible microusb cable.

https://www.amazon.com/UGREEN-Extension-Extender-Transfer-Playstation/dp/B00P0ES0VC/ref=sr_1_14?crid=KDKJSYXG1A1N&keywords=usb%2B3.0%2Bextension%2Bcable%2B3ft&qid=1674974646&sprefix=USB%2B3.0%2BExtension%2B%2Caps%2C343&sr=8-14&th=1

7.a tap measure

8. some cardboard.

9. six armband phone holders.

https://www.decathlon.co.uk/p/phone-running-armband/_/R-p-120495?mc=8352142&c=BLACK

7. eleven BBC Microbit version two single board computers. (Four for proximity sensing, Six used as beacons for players. One used as remote control)

https://www.sparkfun.com/products/17288

8. ten microbit triple A battery holders with switch.

https://www.sparkfun.com/products/15101

About the Codes on Microbits

Build Your Own Players Detection Red Light Green Light Game System Part2 #microbit #arduino
receiver1-screenshot.png

I have added the comments to the codes.

Code for receiver1:

The code for Receiver1 is composed of five parts: initialization, two ‘forever loops’, and two ‘on radio received’ loops.

Receiver1 will determine if a player has won the game. If player1 has won the game, Receiver1 will send the message ‘av’. When Beacon1 receives the message ‘av’, it will set the Victory_Flag to 1. When Victory equals 1, there will be code in another forever loop in this program that will cause the beacon to play a sound representing the player winning the game.

When the game starts, the first forever loop sends commands through the serial port to the Processing App on the laptop, controlling the color of the App to switch between red and green, and playing voice instructions.

The duration of the green light and the red light are configured in this loop. When the Processing APP on the laptop receives 'V', the APP background will turn green. When the Processing APP on the laptop receives 'H', the APP background will turn red. After the app background turns red, 1.8 seconds will be given to the players to stop running and stay still. Otherwise, no one can win the game.

If you want to change the duration of each green light red light session, you need to calculate the sum of the duration of all the green lights and red lights, and input this value into the Processing App to display the total time for the countdown.

When the red light comes on, the player cannot move and the value of Time_to_Move will be set to 1. Receiver1 will continuously send SA SB SC SD SE SF to scan beacon 1 to 6. When the green light comes on, the player can move and the value of Time_to_Move will be set to 0, Receiver1 will continuously send sa sb sc sd se sf to scan beacon 1 to 6.

When the beacon receives the scan signals sa or sb or sc or sd or se or sf from Receiver1, it will return a corresponding letter based on the current beacon's assigned number, allowing Receiver2, 3, 4 to detect the distance between the beacon and them by the received signal strength.

When Receiver1 receives message A, it means player1 moved when he or she was not supposed to, so Receiver1 will send a message ‘A’ through the serial port to the Processing app to indicate player1 has failed.

When Receiver1 receives message B, it means player2 moved when he or she was not supposed to, so Receiver1 will send a message ‘B’ through the serial port to the Processing app to indicate player1 has failed.

When Receiver1 receives message C, it means player3 moved when he or she was not supposed to, so Receiver1 will send a message ‘C’ through the serial port to the Processing app to indicate player1 has failed.

When Receiver1 receives message D, it means player4 moved when he or she was not supposed to, so Receiver1 will send a message ‘D’ through the serial port to the Processing app to indicate player1 has failed.

When Receiver1 receives message E, it means player5 moved when he or she was not supposed to, so Receiver1 will send a message ‘E’ through the serial port to the Processing app to indicate player1 has failed.

When Receiver1 receives message F, it means player6 moved when he or she was not supposed to, so Receiver1 will send a message ‘F’ through the serial port to the Processing app to indicate player1 has failed.

Code for the Beacon:

The beacon constantly reads acceleration data from the on board accelerometer. When the acceleration value of any of the x, y, or z axes changes by more than 40, it is considered that a part of this player's body has moved. You can change the value of 40 if you want to increase or decrease the sensitivity.

If this beacon detects that a player's body part has moved, it will play a 1500 Hz audio. If the player continues to move, the beacon will continue to play the 1500 Hz audio. If the player wins the game, the beacon will increase the volume to 255 and play eight notes representing the player winning the game, then decrease the volume back to 130.

When the beacon receives the scan signals sa or sb or sc or sd or se or sf from Receiver1, it will return a corresponding letter based on the current beacon's assigned number, allowing Receiver2, 3, 4 to detect the distance between the beacon and them by the received signal strength.

Code for Receiver2 Receiver3 Receiver4:

When Receiver2 receives letter a b c d e f or A B C D E F from any one of the beacons, it will delay for 5 milliseconds, then append the number 2 to the received letter and forward the received letter and its signal strength together to Receiver1.

When Receiver3 receives letter a b c d e f or A B C D E F from any one of the beacons, it will delay for 10 milliseconds, then append the number 3 to the received letter and forward the received letter and its signal strength together to Receiver1.

When Receiver4 receives letter a b c d e f or A B C D E F from any one of the beacons, it will delay for 15 milliseconds, then append the number 4 to the received letter and forward the received letter and its signal strength together to Receiver1.

Code for the remote control:

When you press the button A ,it will start sending the command GS to inform receiver1 to start the game. It will keep sending the GS command until the remote control gets feedback information indicating that receiver1 has received the command. The same applies to pressing button B to reset the game.

Download the Microbit Code

code for beacon.png

The Only Change You Need to Made When You Down the Codes:

When you download the program to the corresponding beacon, you need to change the value of beacon_No.

If it is for beacon 3, you need to change the value of beacon_No. to 3.

Install the Processing Programming Environment

Processing 1.png
Processing 2.png

Link for the Processing Programming Environment: https://processing.org/download

Link for the RedLightGreenLight Processing Code:

https://drive.google.com/file/d/1TcjH1qKhzj8OXCanjM244MbvOymsRYsj/view?usp=share_link

After installing the Processing Programming Environment, you need to add the official Sound library.

Set Up the Radio Proximity Sensing System

setup2.png
setup.png

Receiver 2, 3 and 4 are 1.5 meters apart. When setting up this configuration, it is important to ensure that nothing gets in the path of communication lines between Receiver1 and the other three receivers on the floor. Receiver1 is connected to a laptop computer. Receiver1 controls the Processing APP on the laptop switch between red light, green light and playing voice instructions via serial port. 

Make sure receiver 2, 3 and 4 are placed on the floor with the exact same direction as it is showed in the green background picture. Beacause my experiment are based on this configuration.


Next, turn on all the beacons,receivers, run the Processing code,and press the button A on the remote control to start the game. Have fun!

For Pros

pros.png

A Radio Signal Strength Measurement App has been developed by using the National Instruments LabWindows/CVI . You can use this APP to view how the radio signal strength received by receivers 1,2,3,4 changes when the beacon is moving around. A specific Microbit code should be download to receiver 1 to achieve this. (Attached to this step: ForPros-Receiver1-Data-Acquisition-Only-29012023.hex)

More details about this App will be added soon!

You can download the software and acquire a 45 days trial license.

https://www.ni.com/en-us/support/downloads/software-products/download.labwindows-cvi.html#353603

Code for the Radio Signal Strength Measurement App:

https://drive.google.com/file/d/1Er5Y4YibttOs-l6VGysH-iWNZsq8Lmbq/view?usp=share_link