Session 10: Treasure Hunt Challenge – Bringing it All Together
Session Architect: Muhammad Bilal
Duration: 50-60 minutes
Objective:
Students will program their bot to autonomously explore the classroom, locate and track “treasure” checkpoints, avoid collisions with other bots, and keep score of treasures found. This session reinforces their understanding of movement, sensors, conditions, variables, loops, and remote notifications while fostering problem-solving and collaborative skills.
Equipment Required:
- M3D Robotics kits with line sensor and rangefinder sensor
- Laptops with Arduino IDE pre-installed
- Remote client setup
- Black tape to mark checkpoints on the floor as treasures
- Paper and pencils for planning and tracking
Learning Goals
- Combine multiple programming elements to complete a multi-step task autonomously.
- Use conditions and variables to track progress and make decisions based on sensor input.
- Strengthen understanding of loops and decision-making in real-time bot navigation.
- Utilize remote notifications for real-time feedback and user interaction.
1. Introduction to the Treasure Hunt Challenge (5 minutes)
Activity
You can begin with a discussion to introduce the objective of the Treasure Hunt Challenge and explain how the bots will detect treasures, track scores, and avoid obstacles.
- Checkpoints as Treasures:
You can say:
"Today, we’re going on a treasure hunt! Each black mark on the floor is a checkpoint, or as we’ll call it, a ‘treasure.’ When your bot detects a treasure, it should keep track of it and let us know!”
You may ask students for ideas about what they want to include in this competition:
“What do you think the bot should do when it finds a treasure? How can it let us know?”
- Avoiding Obstacles:
You may say:
“But here’s the tricky part – there are other bots exploring too! How can our bot avoid bumping into others?”
- Score Tracking:
“As your bot finds treasures, it’ll need to keep a count of them. What’s a good way to keep track of something that keeps changing?”
Discuss using a variable lead them to the answer of how they can use them to hold the score.
Teacher’s Role:
- Connect the discussion to prior learning by referring to the use of sensors, variables, and notifications.
- Lead students to the idea of using conditions to detect checkpoints and obstacles and to keep a running score.
2. Planning and Setting Up the Code (5 minutes)
Activity
Guide students in structuring their code, starting with variable setup and connecting the sensors. You may break down the whole code into small activities:
- Declare Variables:
“We’ll start by setting up a variable to hold our score, or treasure count. Every time we detect a checkpoint, we’ll add to this count.”
- Code Example:
int totalTreasures = 0; // Initialize the treasure count
- Sensor and Remote Setup:
“We’ll connect the sensors and remote client so our bot can ‘see’ treasures and notify us. Let’s make sure each piece is working before we get moving!”
The code will look like this:
Assist students if they are facing issues connecting to remote or connecting any of the sensors.
Teacher’s Role:
- Help students organize their setup, ensuring each sensor is connected.
- Confirm students understand each part of the setup, explaining any questions that arise about variable initialization or sensor setup.
3. Coding the Treasure Detection Logic (10 minutes)
Activity
Guide students in creating code to detect treasures and send a remote notification.
- Treasure Detection with Line Sensor:
You can explain what the bot will be doing as follows:
“Our bot will be looking for treasure by checking if it’s over a black line. When it finds one, it’ll add 1 to its total treasure count and notify us by displaying a message on the remote.”
- Code Example:
go.forward(50); // Make the robot move
if (line.onTheLine()) {
totalTreasures++; // Increase the treasure count
remote.notify("Treasure detected!"); // Send notification
delay(1000); // Brief pause to register checkpoint
go.stop(); // Pause movement
}
- Encourage them to test the their code and see if the robot is counting the variables correctly.
Teacher’s Role:
- Encourage students to think critically about the logic, such as why a pause is needed to prevent repeated counting.
- Assist with syntax or debugging if students encounter issues with incrementing the variable or displaying notifications.
4. Implementing Obstacle Avoidance (10 minutes)
Activity
Students will use the rangefinder sensor to detect other bots and avoid collisions.
- Coding Obstacle Detection:
“We’ll program the bot to stop if it senses another bot within 5 cm. This prevents collisions and helps keep track of the treasures without interference.”
- Code Example:
if (range.get_cm() < 5) { // Check if another bot is nearby
remote.notify("Obstacle ahead!"); // Notify remote
go.stop(); // Stop to avoid collision
delay(3000); // Short pause before resuming
}
- Assist them in checking their code that the robots can evade each other successfully without getting stuck or keep moving against each other.
Teacher’s Role:
- Explain the logic behind each part of the code, especially how the rangefinder prevents collisions.
- Encourage students to think about the behavior they want to see and test accordingly.
5. Combining Movement and Logic for Continuous Exploration (10 minutes)
Activity
Guide students to combine treasure detection, obstacle avoidance, and continuous movement.
-
Final Code Example:
void setup() { go.begin(); // Initialize the robot remote.begin(); // Begin remote for notifications } void loop() { if (line.onTheLine()) { totalTreasures++; // Increment treasure count remote.notify("Treasure detected!"); // Send notification delay(1000); go.stop(); go.turnLeft(); // Turn after detecting treasure delay(1000); // Pause after turning } if (range.get_cm() < 10) { remote.notify("Obstacle Ahead!"); // Notify remote go.stop(); // Stop to avoid collision delay(3000); // Short delay } else { go.forward(50); // Move forward at moderate speed } }
Teacher’s Role:
- Ensure students understand the overall logic and that they are comfortable integrating all parts.
- Address any troubleshooting needs and encourage collaboration for problem-solving.
6. Treasure Hunt Run and Scorekeeping (10 minutes)
Activity
In this final challenge, all students will activate their robots simultaneously, allowing them to explore the classroom for treasures in real-time. The bots will search for checkpoints, avoiding obstacles and collecting points as they navigate.
- Starting the Hunt:
“Alright, let’s begin our treasure hunt! When I say go, everyone will turn on their robots and watch them explore the room, looking for treasure points. Remember, if your bot collided with another, you’ll lose a point for each collision. Avoiding obstacles was part of today’s challenge!”
The bots will move continuously for 3-5 minutes (timing up to the teacher’s preference), automatically logging each checkpoint detected and avoiding other bots to prevent collisions.
- Counting Points:
Once time is up, students will turn off their robots and check the “Total Treasures” variable to see how many treasures each bot found.
- Score Verification:
- The teacher will verify each bot’s treasure count, ensuring all scores are accurate.
- For any robots that collided during the hunt, the teacher will deduct one point per collision, reinforcing the importance of avoiding obstacles during navigation.
Teacher’s Role:
- Guide students through turning on their robots and starting the hunt.
- Track time and announce when to start and stop.
- Verify scores and ensure fair point deduction for any collisions.
- Encourage students to observe each bot’s behavior and think about strategies for future improvements.
7. Reflection and Wrap-Up (5 minutes)
Activity
Wrap up the session with a reflection on the challenge and their coding journey.
Discussion Questions:
- Teacher: “What was the most challenging part of today’s treasure hunt?”
- Teacher: “How did using the remote notifications help track progress? Would you use this feature again in future projects?”
Teacher’s Role:
- Encourage students to share insights and challenges from their work.
- Celebrate their progress and teamwork throughout the course, emphasizing the skills they’ve developed.