SquidGame 'Red Light, Green Light' Game System With Micro:bit V2 (the Most Complicated Micro:bit Project---Updated Tutorial)
by FrankYun123 in Teachers > University+
76 Views, 3 Favorites, 0 Comments
SquidGame 'Red Light, Green Light' Game System With Micro:bit V2 (the Most Complicated Micro:bit Project---Updated Tutorial)
Introduction to the Red Light-Green Light Game System
This project is a non-violent adaptation of the “Red Light-Green Light” game, inspired by the version seen in the TV series Squid Game. Unlike the series, which includes violent elements such as eliminating players with harmful actions, this system removes those aspects entirely, focusing instead on fun, fairness, and skill. The game is designed to be safe and educational, making it suitable for all ages.
The game system uses BBC Micro:bit Version 2 microcontrollers to create an interactive experience where players are monitored for movement and progress using wireless communication and signal processing. Each player wears a Micro:bit-powered beacon on their arm, which interacts with four receivers positioned near the finish line. The central receiver (Receiver1) manages the game, ensuring smooth communication and accurate player tracking.
Here’s how this game system works:
1.Movement Detection: Players' beacons on their arms transmit signals to the receivers. These signals indicate whether a player is moving or standing still during the red light phase.
2.Proximity Monitoring: The receivers measure the signal strength to determine when a player has crossed the finish line, ensuring precise detection.
3.Interference Prevention: All devices operate on the same radio channel but use slight time delays to avoid communication conflicts and maintain accuracy.
4.Real-Time Feedback: Receiver1 communicates with a laptop running a processing program that displays game status, countdown timers, and player progress. The system also provides voice instructions and visual cues for red and green light phases.
This project demonstrates how technology can transform a well-known game into an engaging, interactive activity while eliminating harmful elements. Exclusively compatible with BBC Micro:bit Version 2, this system is perfect for educators, students,
5.For detailed system workflow, please check step 14.
If you want to create this game system, you need to fully understand how it works to successfully implement its functions.
If you want to create this game system, you need to fully understand how it works!
If you want to create this game system, you need to fully understand how it works!
The following steps provide an in-depth explanation of its working principles.
If you have any question about how to make this game system, please do not hesitate to leave a comment!
Supplies
List of Items for Building the Game System:
- Laptop (1 unit)
- Used for running the Processing application that displays game status, countdowns, and provides audio instructions, which communicates with Receiver 1.
- USB Speakers (1 pair)
- Used for playing audio instructions and game sounds.
- Optional TV (1 unit)
- Can be used for a larger visual display when connecting the laptop to the TV.
- Tripod (1 unit)
- Used to hold Receiver 1 in place.
- Microbit Campatible USB Cable
- Used for connecting Receiver 1 to the laptop.
- Measuring Tape (1 unit)
- Used for measuring and marking distances on the field for setting up the game.
- Cardboard (Multiple)
- Used for crafting holders for Micro:bits and their battery packs.
- Armbands Phone Holder (6 units)
- Used to secure the beacons (Micro:bits) on the players' arms during the game.
- BBC Micro:bit V2 (11 units)
- Core component for implementing:
- Beacons (6 units)
- Receivers (4 units)
- Remote Control (1 unit)
- Battery Holders for Micro:bit (10 units)
- Provides portable power to the Micro:bit devices.
Player Movement Detection
Motion Detection in the Red Light-Green Light Game System: A Functional Explanation
Overview
In the Red Light-Green Light game system, motion detection plays a critical role in determining whether a player moves during the “Red Light” phase. This video demonstrates how a BBC Micro:bit, utilizing its built-in accelerometer, detects and communicates player movements. The system ensures fairness and adds a layer of interactivity by monitoring even subtle body movements.
How Motion Detection Integrates into the Game System
1.Key Components:
- Motion-Detecting Beacon:
- Each player wears a Micro:bit device (beacon) mounted on an armband or phone holder.
- This Micro:bit monitors body movement using its built-in accelerometer.
2.Body Balance Sensitivity:
- The Micro:bit’s accelerometer is highly sensitive, capturing even minor movements, such as:
- Shaking the head.
- Leaning forward or backward.
- Moving an arm slightly or shifting weight.
- These motions cause subtle changes in body balance, which the accelerometer detects and communicates to the game system.
Understanding Bluetooth Proximity Sensing Basics
https://microbit.org/projects/make-it-code-it/proximity-beacon/
First, you need to watch the Micro:bit Foundation’s official tutorial on Radio Signal Strength. This will help you build a basic understanding of the radio system and Bluetooth proximity sensing before moving to the next steps. Please visit the official tutorial website, watch the video, and complete the tasks provided.
Understanding the Small-Scale Finish Line Detection System
This tutorial video demonstrates a scaled-down version of a finish line detection system, built with four Micro:bit devices. Unlike the final 1.5-meter version, this model uses a smaller scale to explain the system's functionality. It provides a practical way to understand how the detection system works .
The system is designed to track players reaching the finish line by measuring radio signal strength from wearable beacons. Using real-time communication between the Micro:bits, it accurately detects when a player enters the designated finish line zone.
Understanding Antenna Performance of Micro:bit V2
The Micro:bit Version 2 is equipped with a trace antenna that exhibits specific characteristics related to the directionality of its radio signal transmission and reception. These features are critical for optimizing the player dectection system using four Micro:bit at the finish line.
Strongest Signal Emission
- Initially, it was hypothesized that Direction Two and Direction Three (specific orientations of the Micro:bit) would emit the strongest radio signals.
- However, experimental results revealed that Direction Five, which is perpendicular to the Micro:bit circuit board plane, is the orientation that emits the strongest radio signals.
Optimal Signal Reception
- The same perpendicular orientation of the circuit board (Direction Five) was also found to be the most effective for receiving radio signals.
How to Set Up the Finish Line Radio Proximity Sensing System
This video explains how to set up a finish line detection system using BBC Micro:bit devices. The system uses multiple receivers and beacons to determine if a player has reached the finish line based on radio signal strength.
System Overview
The system consists of:
- Receivers:
- Receiver1: Acts as the central controller. It communicates with the players’ beacons and the receivers at the finish line.
- Receivers 2, 3, and 4: Positioned at the finish line, they detect the signal strength from the players' beacons.
- Beacons:
- Worn on players’ arms to transmit radio signals to the receivers.
- laptop: The laptop is connected to Receiver1 and communicates with a Processing app. This app plays a crucial role in the game system by:
- Displaying the remaining game time on the screen.
- Monitoring and updating the statuses of players in real time.
- Providing voice instructions to guide players throughout the game.
What You Need
- 4 BBC Micro:bit Version 2 devices (for receivers)
- 1 BBC Micro:bit Version 2 device per player (as beacons)
- Battery packs for each Micro:bit
- Tripod for Receiver1
- Laptop with a Micro-USB cable
- Measuring tools (e.g., tape measure) to position devices accurately
Step 1: Receiver Configuration
- Position Receivers at the Finish Line:
- Place Receivers 2, 3, and 4 on the floor at the finish line with their antennas facing upward.
- Maintain a distance of 1.5 meters between each receiver. This setup ensures that the finish line spans a width of approximately 4.5 meters.
- Setup Receiver1:
- Mount Receiver1 on a tripod with its antenna facing forward.
- Ensure there is a clear communication line between Receiver1 and the other receivers (2, 3, and 4) at the finish line.
Step 2: Beacon Configuration
- Prepare Beacons for Players:
- Each player wears a Micro:bit beacon on their arm. Secure the beacon using an armband or phone holder.
- The beacons continuously transmit radio signals, allowing the receivers to detect their proximity.
Step 3: Signal Detection Logic
- Proximity Detection:
- The antennas of Receivers 2, 3, and 4 face upward. When players are far away, the signal strength from the beacons is weak.
- As a player approaches the finish line, the signal strength received by these receivers increases rapidly.
- Threshold Setting:
- Set a threshold value for signal strength detection.
- When any one of the finish line receivers detects a beacon signal strength exceeding the threshold, it is considered that the player has reached the finish line.
- Accuracy:
- The system provides a detection accuracy of approximately 1 meter.
Step 4: Gameplay Rules
- Avoid Obstructions:
- Ensure players do not block the communication line between Receiver1 and the finish line receivers (2, 3, and 4).
- Players should leave the finish line area immediately after crossing to avoid signal interference for others.
- Finish Line as an Area:
- The finish line is not a single line but an area. If a player’s beacon enters this area and the signal strength exceeds the threshold, the player is marked as having crossed the finish line.
How the Finish Line Radio Proximity Sensing System Works?
How the Finish Line Radio Proximity System Works
The finish line proximity sensing system is designed to detect whether a player has reached the finish line and whether they are moving when they shouldn't be. This process relies on real-time communication between beacons worn by players and receivers placed at the finish line.
Player Status Detection: Example with Player 1
- Signal Initialization:
- Receiver1 sends a signal with the identifier "SA" to query Player 1’s status.
- Beacon 1, worn on Player 1’s arm, responds based on the player's motion:
- Lowercase "a": Sent when Player 1 is stationary.
- Capital "A": Sent when Player 1 is moving.
- Player Movement Example:
- If Player 1 starts running, Beacon 1 transmits a capital "A."
- Assuming no other players block the signal, all receivers (Receiver1, 2, 3, and 4) detect the letter "A" simultaneously.
Communication and Jamming Prevention
- Avoiding Signal Jamming:
- Receivers 2, 3, and 4 operate on the same communication channel as Receiver1. To prevent jamming, each receiver introduces a delay before forwarding the signal to Receiver1:
- Receiver2: Waits for 5 milliseconds before relaying the signal strength of the received "A" to Receiver1.
- Receiver3: Waits for 10 milliseconds before relaying the signal strength.
- Receiver4: Waits for 15 milliseconds before relaying the signal strength.
Multi-Player Scanning
- Sequential Scanning:
- After scanning Player 1 with "SA", the system queries the other players in sequence:
- Sends "SB" to scan Player 2.
- Sends "SC" to scan Player 3.
- Sends "SD" to scan Player 4.
- This process continues for up to six players.
- Scan Duration:
- Scanning one player takes 20 milliseconds.
- With a maximum of six players, the total scan cycle duration is 120 milliseconds.
Creating a Cardboard Holder for the Micro:bit and Battery Pack
This tutorial explains how to create a simple and functional cardboard holder to secure a BBC Micro:bit and its battery pack. The holder is designed to fit neatly into an armband phone holder.
What You Need
- A piece of cardboard
- Scissors or a craft knife
- Tape or glue
- Micro:bit Silicone cover (optional)
- Armband phone holder
- Micro:bit and its AAA battery pack
Step 1: Cut and Shape the Cardboard
Measure and Trace:
- Place the Micro:bit and battery pack on the cardboard.
- Trace an outline large enough to hold both items securely.
Step 2: Secure the Micro:bit and Battery Pack
- Attach the Micro:bit:
- Position the Micro:bit on the cardboard.
- Ensure the buttons remain accessible by leaving openings for them.
- Tape or glue the Micro:bit securely in place.
- Attach the Battery Pack:
Step 3: Prepare for the Armband Phone Holder
- Silicone Cover (Optional):
- If you prefer to protect the Micro:bit with a silicone cover, ensure the cover doesn’t block the antenna.
- Use scissors to carefully cut a small opening in the silicone cover near the antenna area. This ensures strong signal transmission and reception.
- Modify the Armband Phone Holder:
- If the armband phone holder has a thick plastic cover, cut a hole in the area near the antenna.
- This additional opening prevents signal interference from the plastic material.
Step 4: Insert the Holder into the Armband
Place the Cardboard Holder:
- Slide the cardboard holder, with the Micro:bit and battery pack attached, into the armband phone holder.
- Ensure the openings align correctly for the buttons and antenna.
Install the Processing Programming Environment
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.
A Brief Introduction to the Processing App Runs on the Laptop.
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.
Introduction to the Processing App in the Red Light-Green Light Game System
The Processing app is the central interface of the Red Light-Green Light game system. It connects to Receiver One through a serial port and serves three primary purposes: visual feedback, auditory feedback, and player status display. The app switches between red and green light phases, announces the game progress through audio cues, and visually displays each player’s status. By integrating with other components such as the remote control, Receivers One to Four, and the beacons, it ensures smooth operation of the game.
Setting Up Serial Communication
The Processing app begins by establishing a serial connection with Receiver One. This connection allows the app to receive real-time data about player actions and game status. The app dynamically selects the first available serial port on the laptop to ensure compatibility with different systems. Serial communication is essential for transmitting critical messages, such as player success or failure, and game state changes.
Sound Integration
To enhance the gaming experience, the app incorporates a sound library. This feature enables it to play audio files for various game events, such as starting the game, announcing red or green light phases, and declaring player results. For example, when the game begins, an introductory sound file plays to set the stage for participants.
Visual Feedback and Player Status
The app uses the laptop display to show the current game state. During the green light phase, the screen background turns green, indicating that players can move. During the red light phase, the screen turns red, signaling players to stop. The Processing app also displays the status of each player, using color-coded indicators. A yellow status means the player is active, white indicates the player has won, and black shows the player has failed.
Handling Serial Messages from Receiver One
Receiver One communicates with the Processing app by sending specific messages through the serial connection. For instance, when Receiver One detects that a player has moved during the red light phase, it sends a letter corresponding to the player’s ID, such as A for Player One or B for Player Two. The Processing app processes these messages to update the player’s status visually and audibly. Additionally, messages like S indicate the start of the game, while W triggers a game reset.
Countdown Timer and Game Phases
The Processing app features a countdown timer displayed on the screen. This timer provides a visual reference for players, showing how much time remains in the current game. The app alternates between green and red light phases based on commands received from Receiver One. For example, when the app receives the letter V from Receiver One, it changes the screen background to green, signaling the green light phase. Conversely, when it receives the letter H, the screen background turns red, indicating the red light phase.
Reset and Result Announcement
When the app receives the message W, it resets the game state, including the timer and player statuses. At the end of the game, the app announces the results for each player. For instance, if Player One wins, the app plays an audio file declaring their success. Similarly, if Player Two fails, the app announces their failure. The result announcement provides a satisfying conclusion to the game for all participants.
Integration with System Components
The Processing app is deeply integrated with the remote control, Receivers One to Four, and the beacons. The remote control is used to start and reset the game by sending GS and RE commands to Receiver One. Receiver One processes these commands and forwards the necessary instructions to the Processing app. Receivers Two to Four relay beacon signal data to Receiver One to determine player positions and movement. The beacons, attached to the players, respond to scan signals from Receiver One by indicating whether a player is moving or stationary.
Brief Introduction of the Code of the Beacon.
Introduction to Initialization and Configuration
- Beacon Number Assignment: Each beacon is assigned a unique number, such as 1 for player 1, 2 for player 2, and so on. This number is displayed on the Micro:bit’s LED screen for confirmation. For example, beacon 1 will show the number 1 on its display.
- Radio Communication Setup: All beacons operate on the same communication channel. This is configured using the command radio.setGroup(7). To ensure strong signals, the transmission power is set to the maximum using radio.setTransmitPower(7).
- Placement of the Beacon: The beacon is securely placed inside an armband phone holder, which the player wears on their arm. A small hole may be cut near the beacon's antenna in the armband to ensure uninterrupted communication.
Movement Detection Algorithm
The beacon uses its built-in accelerometer to monitor movement. The algorithm works as follows:
- Data Collection:
- The accelerometer measures acceleration along three axes: x, y, and z.
- Five readings are taken for each axis in quick succession and stored as the first set of measurements.
- After a 50-millisecond pause, another five readings are taken, forming the second set of measurements.
- Calculating Averages:
- The program calculates the average value of each axis for both sets of measurements. For example:
- The x-axis averages are stored as X_ACC_Data_1_AVG and X_ACC_Data_2_AVG.
- Detecting Changes:
- The program calculates the absolute difference between the average values of the two sets for each axis.
- For example:
- X_ACC_Data_CHG represents the change in the x-axis between the two sets.
- Determining Movement:
- If the change in acceleration for any axis exceeds a predefined threshold (default is 40), the beacon detects movement. Otherwise, it determines the player is stationary.
- The sensitivity of this detection can be adjusted by modifying the threshold value.
Communication with Receivers
- Responding to Scan Signals:
- When Receiver1 sends scan signals, such as "SA" or "SB," the beacon responds based on its number and the player's movement status.
- If the player is stationary, the beacon sends a lowercase letter, such as "a" for beacon 1.
- If the player is moving, the beacon sends an uppercase letter, like "A" for beacon 1.
- Victory Detection:
- When Receiver1 determines a player has won, it sends a victory signal, such as "av," to the respective beacon.
- The beacon then sets its Victory_Flag to 1, signaling success.
Audio Feedback System
- Movement Alerts:
- If the beacon detects movement, it plays a tone at 1500 hertz to alert the player.
- The tone continues as long as the player moves and stops when the player remains still.
- Victory Celebration:
- When the player wins, the beacon increases its volume and plays a celebratory melody. This provides both an auditory cue and positive reinforcement for the winner.
Downloads
The Code of Receiver One.
To explain the Receiver 1 code comprehensively, I will break down its structure and functionality while focusing on its interaction with the beacon system, the Processing app, and other receivers. Here is a detailed explanation:
Initialization and Configuration
Receiver 1 initializes several variables and sets up communication channels:
- The radio communication group is set to 7. This ensures all connected devices, beacons, Processing app, and other receivers, operate on the same channel.
- Signal threshold is initialized to 115. This value determines the signal strength required to consider that a beacon has reached the finish line. It can be adjusted based on the average height of players to optimize accuracy.
- The serial port is configured for communication with the Processing app, allowing Receiver 1 to send player status updates, for example, movement or finish line detection.
The code displays an LED pattern during initialization to indicate that the program is running and ready.
Game Start and Reset Logic
Receiver 1 listens for specific commands, GS and RE, from the remote control:
- Game Start, GS:
- Upon receiving GS, Receiver 1 resets all player tags and flags and sets the Game_Start_flag to 1.
- It sends a confirmation, GSAC, to the remote control to indicate the game has started.
- Game Reset, RE:
- When RE is received, all variables are reset to their initial state.
- Receiver 1 sends a confirmation, REAC, to the remote control and a reset signal, w, to the Processing app to restart its timer.
Detecting Player Movement
Receiver 1 listens for movement data from the beacons and evaluates it using the radio.onReceivedString function:
- When a beacon sends an uppercase letter, for example, A, B, etc, it indicates a player moved when they were not supposed to during the red light phase.
- Receiver 1 sends the respective player's failure signal, for example, A for Player 1, to the Processing app via the serial port. This updates the player's status in the app and triggers a corresponding audio response.
The radio.onReceivedValue function handles messages relayed by Receivers 2, 3, and 4:
- These messages, for example, A2, B3, etc, indicate a player's movement detected by other receivers.
- Receiver 1 processes these messages similarly by marking the player as failed and sending the appropriate signal to the Processing app.
Finish Line Detection
Receiver 1 determines when a player reaches the finish line based on average signal strength data:
- It receives lowercase letters, a, b, etc, from the beacons during the green light phase.
- The signal strength received by Receivers 2, 3, and 4 is averaged over the last three readings.
- If the average exceeds the signal threshold, Receiver 1 considers the player has reached the finish line.
- Receiver 1 sends a signal, for example, av for Player 1, to the beacon and updates the Processing app about the player's status.
Interaction with the Processing App
Receiver 1 sends various signals to the Processing app:
- S: Starts the countdown timer and switches the app's background to green.
- H: Changes the app's background to red and gives players time to stop moving.
- z: Signals the end of the game, prompting the app to announce results and update player statuses.
The Processing app responds by updating its graphical display, playing audio cues, and providing real-time feedback to players.
Collaboration with Other Receivers
Receivers 2, 3, and 4:
- These receivers are placed at the finish line and measure signal strength from the beacons.
- They forward data, for example, A2, B3, to Receiver 1, which aggregates the information to evaluate player movement and proximity to the finish line.
- This distributed system enhances the accuracy of movement detection and finish line validation.
Detecting Movement Using Beacons
Beacons continuously monitor player movement using their built-in accelerometers:
- Accelerometer data is averaged over five measurements.
- The change in average values over time is calculated for the x, y, and z axes.
- If any change exceeds a threshold, the beacon marks the player as moving and sends an uppercase letter, for example, A, to Receiver 1.
Continuous Scanning Logic
Receiver 1 alternates between scanning during green and red light phases:
- During the green light phase, Time_to_Move equals 1, Receiver 1 sends lowercase scan signals, sa, sb, etc, to identify players approaching the finish line.
- During the red light phase, Time_to_Move equals 0, it sends uppercase scan signals, SA, SB, etc, to monitor if players are moving.
Conclusion
The Receiver 1 code orchestrates communication between all components of the system:
- It manages game state transitions, monitors player movement, and evaluates finish line detection.
- It interacts seamlessly with the Processing app to provide real-time visual and audio feedback.
- Collaboration with Receivers 2, 3, and 4 ensures accurate detection of player movement and finish line proximity, making the system robust and reliable.
Downloads
Code of Receiver 2, 3 and 4
Explanation of Receiver 2, Receiver 3, and Receiver 4 and Their Relationship with Receiver 1 and the Overall System
This explanation covers the functionality, logic, and role of Receiver 2, Receiver 3, and Receiver 4 in the context of the red light-green light game system. Their primary role is to forward information from the beacons worn by players to Receiver 1, enabling Receiver 1 to make decisions about player movements, fail conditions, and winning conditions.
Initialization and Configuration
- Shared Setup Across Receivers:
- Each receiver initializes communication parameters by setting:
- Radio transmission power to 7: Ensures consistent signal strength across all devices.
- Radio group to 7: All receivers and beacons must be on the same group to communicate effectively.
- Serial communication setup: Redirects data to the USB port for debugging or monitoring.
- Each receiver has a specific time delay before forwarding the received signal to Receiver 1:
- Receiver 2: Delays for 5 milliseconds.
- Receiver 3: Delays for 10 milliseconds.
- Receiver 4: Delays for 15 milliseconds.
- The distinct LED patterns provide visual feedback for identifying the receiver during initialization.
Core Functionality
- Signal Reception and Processing:
- Each receiver listens for specific messages (a, b, c, etc.) transmitted by the beacons.
- Upon receiving a message:
- The signal strength is measured in dB, ranging from -100 dB (weakest) to -28 dB (strongest).
- The signal strength is mapped to a value between 0 and 255 for further processing.
- The value is truncated to an integer for easier handling.
- Signal Forwarding Logic:
- The received message is appended with the receiver's identifier (e.g., 2, 3, or 4) and forwarded to Receiver 1.
- For example:
- If Receiver 2 receives a, it sends a2 along with the signal strength to Receiver 1.
- If Receiver 4 receives B, it sends B4 to Receiver 1.
- This forwarding ensures Receiver 1 can associate the signal strength with the correct receiver and player beacon.
Player Movement Detection
- Delay Mechanism:
- The delays (5 ms for Receiver 2, 10 ms for Receiver 3, and 15 ms for Receiver 4) prevent simultaneous forwarding of the same signal by multiple receivers, avoiding communication interference.
- This delay-based system ensures sequential processing of player data at Receiver 1.
- Role in Movement and Signal Strength Analysis:
- Each receiver calculates the signal strength of the player’s beacon and forwards it to Receiver 1.
- Receiver 1 uses this data from multiple receivers to:
- Determine player movements by analyzing variations in signal strength.
- Decide if a player has reached the finish line (if the signal strength exceeds a predefined threshold).
Integration with Receiver 1
- Receiver 1's Decision-Making:
- Receiver 1 consolidates data from all receivers (2, 3, and 4) to:
- Detect if a player has moved during a red light.
- Determine if a player has reached the finish line.
- Receiver 1 communicates directly with the Processing app to:
- Notify failures (e.g., A for Player 1 moving during red light).
- Announce winners when a player reaches the finish line.
Debugging and Serial Communication
- Serial Data Output:
- The serial communication (e.g., serial.writeValue) was initially included for debugging purposes.
- It allows developers to monitor signal strength and forwarded messages during system testing.
- These serial outputs are not utilized during the actual game process.
System Workflow
- Beacon Sends Signal:
- Beacons worn by players transmit identifiers (a, b, etc.) with their movement state (uppercase for movement, lowercase for stationary).
- Receiver Functions:
- Receivers 2, 3, and 4 receive these signals and calculate signal strength.
- Each receiver appends its identifier (2, 3, 4) to the message and forwards it to Receiver 1.
- Receiver 1 Integration:
- Receiver 1 uses the combined data to:
- Detect failures during the red light.
- Announce winners when players reach the finish line.
- Processing App and Game Monitoring:
- Receiver 1 communicates critical updates (e.g., game start, player failures, winners) to the Processing app for real-time display and announcements.
Key Considerations for Practical Use
- The time delay values (5 ms, 10 ms, 15 ms) are critical for ensuring non-interfering signal forwarding.
- Signal strength thresholds must be calibrated for the environment and average player height for optimal performance.
- Debugging outputs can be removed for a streamlined game operation.
Code of the Remote Control
The remote control device provides a simple yet effective interface for controlling the game states. Below is a detailed explanation of the code and its integration with the overall system.
Initialization and Configuration
- Radio Configuration:
- The remote control is configured to use the same radio group (Group 7) and transmit power (7) as other devices in the system. This ensures seamless communication across all components.
- Serial Communication:
- The serial.redirect function initializes serial communication for debugging or monitoring purposes. Data will be sent through the USB interface, though this feature is not actively used during gameplay.
- Startup Display:
- Upon power-on, the device displays a diamond icon on the LED grid to indicate it is ready for use.
Key Functions
1. Starting the Game (Button A Pressed)
- When Button A is pressed:
- Sound Effect:
- A rising sine wave sound effect is played, indicating the game start signal is being sent.
- Set Start Signal Tag:
- The variable Start_Signal_TAG is set to 1, signaling the intent to start the game.
- Display Feedback:
- The text "S" is shown on the LED grid, followed by a sad face icon to visually confirm the start signal has been triggered.
- Transmission:
- In the basic.forever loop, if Start_Signal_TAG is set to 1, the remote control sends the signal "GS" (Game Start) with a value of 0 via radio to other devices.
2. Resetting the Game (Button B Pressed)
- When Button B is pressed:
- Sound Effect:
- A descending sine wave sound effect is played, signaling the reset intent.
- Set Reset Signal Tag:
- The variable Reset_Signal_TAG is set to 1, indicating a reset action.
- Display Feedback:
- The text "R" is shown on the LED grid, followed by a sad face icon to confirm the reset signal has been triggered.
- Transmission:
- In the basic.forever loop, if Reset_Signal_TAG is set to 1, the remote control sends the signal "RE" (Reset) with a value of 0 via radio to other devices.
3. Receiving Acknowledgment from Other Devices
- The remote control listens for acknowledgments ("GSAC" for start and "REAC" for reset) from other devices:
- Game Start Acknowledgment:
- When "GSAC" is received:
- The Start_Signal_TAG is reset to 0, stopping the repeated transmission of the start signal.
- A happy face icon is displayed on the LED grid to confirm the start signal has been acknowledged by Receiver 1.
- Reset Acknowledgment:
- When "REAC" is received:
- The Reset_Signal_TAG is reset to 0, stopping the repeated transmission of the reset signal.
- A happy face icon is displayed on the LED grid to confirm the reset signal has been acknowledged by Receiver 1.
Integration with the System
- Interaction with Receiver 1:
- The remote control sends "GS" to start the game and "RE" to reset the game. These signals are received and processed by Receiver 1, which controls the system's state.
- Upon receiving "GS", Receiver 1:
- Initiates the countdown timer on the Processing app.
- Signals the beacons and other receivers to start the game.
- Upon receiving "RE", Receiver 1:
- Resets the game state, including the countdown timer and all player statuses.
- Acknowledgments:
- Receiver 1 sends "GSAC" or "REAC" back to the remote control to confirm receipt of the respective signals. This ensures the remote control knows the commands have been executed.
Visual and Audio Feedback
- The remote control provides intuitive feedback through:
- Sound Effects: Different sound effects for start and reset actions.
- LED Display:
- The letter "S" or "R" and an emotional icon (sad or happy) confirm the current action and acknowledgment status.
System Workflow Example
- Game Start:
- The instructor presses Button A on the remote control.
- The remote control sends "GS" to Receiver 1.
- Receiver 1 starts the countdown timer, notifies other components (beacons, Processing app), and sends "GSAC" back to the remote control.
- The remote control displays a happy face upon receiving "GSAC".
- Game Reset:
- The instructor presses Button B on the remote control.
- The remote control sends "RE" to Receiver 1.
- Receiver 1 resets the game state and sends "REAC" back to the remote control.
- The remote control displays a happy face upon receiving "REAC".
Key Considerations
- Time Interval Between Commands:
- The basic.pause(10) in the basic.forever loop ensures commands are not sent too frequently, reducing unnecessary radio traffic.
- Robustness:
- Acknowledgment signals ensure that commands are reliably received and processed by Receiver 1.
Downloads
Overview of the System Workflow
The red light and green light game system involves multiple interconnected components, including the Processing app, Receiver1, Receivers 2, 3, and 4, and the beacons worn by players. Receiver1 communicates with the Processing app via the USB-to-serial interface provided by the Micro:bit, acting as a lower-level serial device. Here's a detailed explanation of the system's workflow:
Initialization Phase
- Processing App Setup:
- The Processing app initializes the game environment, sets up serial communication with Receiver1, and prepares visual and audio feedback for players.
- Receiver1 Setup:
- Receiver1 initializes its communication channel and serial connection to the Processing app. It also sets up its internal variables and prepares to handle inputs from Receivers 2, 3, and 4, as well as the beacons.
- Receivers 2, 3, and 4 Setup:
- Each of these receivers initializes their communication group and sets a specific delay time to avoid signal collisions when forwarding beacon signal strength to Receiver1.
- Beacon Initialization:
- Each beacon is set with a unique ID (beacon_No) and configured to detect movement using its accelerometer. The communication group is synchronized with the receivers.
- Remote Control Setup:
- The remote control initializes and waits for button inputs to either start (Button A) or reset (Button B) the game.
Game Start Phase
- Remote Control Signal:
- When the player presses Button A on the remote control, it sends a "GS" (Game Start) signal to Receiver1.
- Receiver1 forwards this signal to the Processing app via the USB-to-serial interface. The Processing app acknowledges this signal and starts the countdown timer, displaying a "green light" to indicate the game has started.
- Beacon Scanning:
- When the game starts, Receiver1 begins sending scanning signals (SA, SB, etc.) to each beacon in sequence. These signals are used to track player movement and position.
- The beacons respond based on whether the player is stationary (lowercase letters) or moving (uppercase letters), relaying this information back to Receiver1 through Receivers 2, 3, and 4.
Player Movement Detection
- Movement Detection by Beacons:
- Each beacon uses its accelerometer to detect movement. If the movement exceeds a predefined threshold, the beacon marks the player as moving and sends an uppercase response to the receivers. Otherwise, it sends a lowercase response.
- Signal Strength Forwarding:
- Receivers 2, 3, and 4 receive beacon signals, calculate the signal strength, and forward the information to Receiver1 with an appended identifier (e.g., a2 for Player 1 detected by Receiver 2).
- These receivers introduce specific delays (5ms for Receiver2, 10ms for Receiver3, 15ms for Receiver4) to prevent signal collisions.
- Data Processing by Receiver1:
- Receiver1 collects data from all receivers, evaluates the signal strength, and determines if a player has moved or reached the finish line.
- If a player moves during a red light, Receiver1 sends a failure signal (A, B, etc.) to the Processing app, which updates the game status and announces the result.
Finish Line Detection
- Signal Strength Averaging:
- Receiver1 calculates the average signal strength of the last three readings for each player from Receivers 2, 3, and 4. If the average exceeds a threshold, it determines that the player has reached the finish line.
- Victory Announcement:
- Upon detecting a player reaching the finish line, Receiver1 sends a victory signal (av, bv, etc.) to the beacon. The beacon plays a celebratory melody and sends feedback to the Processing app for display and announcement.
Processing App Feedback
- Visual and Audio Output:
- The Processing app updates the game environment based on data received from Receiver1. For instance:
- A red or green background is displayed depending on the game phase.
- Players' statuses are shown (e.g., failed, won, or still playing).
- Audio cues, such as "Player 1 wins" or "Player 2 fails," are played.
- Game Status Updates:
- The Processing app manages the countdown timer and stops the game automatically when the timer reaches zero or all players have completed the game.
Reset Phase
- Reset Signal from Remote Control:
- When the player presses Button B on the remote control, it sends a "RE" (Reset) signal to Receiver1.
- Receiver1 forwards the reset signal to the Processing app, which resets the game environment, clears the timer, and prepares for a new game session.
- System Reset:
- All components, including receivers and beacons, reinitialize their variables and prepare to start the game again.
Summary of Component Interactions
- Receiver1 and Processing App:
- Communication is managed via the USB-to-serial connection, with Receiver1 acting as the lower-level serial device.
- Receivers 2, 3, and 4:
- Act as signal relays, forwarding beacon data with unique identifiers to Receiver1.
- Beacons:
- Detect player movement using accelerometers and respond to scanning signals from Receiver1.
- Processing App:
- Acts as the central game controller, providing visual and audio feedback, managing the countdown timer, and determining the game outcome.
- Remote Control:
- Starts and resets the game, ensuring smooth operation.
All the code:
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
Put Bluetooth Devices Away
This system uses Bluetooth signal strength to determine whether a player is approaching the finish line. Therefore, during the game, all players must refrain from carrying their phones, as phones may be in Bluetooth scanning mode, which could interfere with the system. Similarly, players are not allowed to wear Bluetooth earphones. All mobile phones must be placed aside, at least five meters away from the finish line area.
For optimal performance, it is recommended to play the game in an indoor environment, where external interference from other Bluetooth devices can be minimized. This ensures the accuracy and fairness of the game.
For Pros
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