Session 4: Smarter Bot: Advanced Decision Making
Session Architect: Muhammad Bilal
Duration: 50–60 minutes
Equipment Required:
- M3D Robotics Kit (robot with display attachment)
- Laptops with Scratch pre-installed
- Scratch Face Detection Extension enabled
- Whiteboard or chart to show facial features
- Paper and pencils for students to note observations
Learning Objectives:
By the end of this session, students will be able to:
- Understand how robots make multiple decisions using nested if–else blocks
- Identify how sensor readings (distance values) can trigger different robot behaviors
- Design a flowchart to represent layered logic and decision-making
- Debug conditional loops to ensure the robot reacts correctly to changing environments
- Relate robot decision-making to real-life examples of reacting to distance or obstacles
Resources:
Scratch Code for the Session:
AI Lab - Session 4.sb3 (15.5 KB)
1. Introduction (5 minutes) – Continuation of Previous Session
Start with the previous analogy:
“Last time, we learned how our little robot stops when it senses an obstacle, almost like it has a tiny brain that notices what’s in front of it.”
Transition to today:
“Today, our robot is going to act even smarter! We’ll teach it to make multiple decisions, just like we do. Imagine walking in a room: if a ball rolls slowly toward you, you step aside carefully. If someone suddenly jumps in front of you, you might jump back or make a surprised face. And if there’s nothing around, you feel free to smile and walk happily."
"Our robot is going to do the same—it will have different reactions depending on what it senses! So we can see, it will make different kind of decisions based on changing environment. Similar to what we did last time when we taught it to make a single decision.”
2. Linking to Previous Learning (5 minutes)
Recap the previous session:
- Single condition → robot stopped when obstacle was near
- Distance sensor → measured distance and triggered stop
You may show them the code that they made in the previous session.
Transition to today’s complexity:
“Today, instead of just stopping, the robot will decide what to do in many situations. We’ll use nested loops and multiple conditions to make it think like it’s alive!”
Teacher Prompts:
- “If the robot only stops when it’s close to something, what happens when it sees something far away?”
- “Can we make it react differently depending on how near or far an object is?”
3. Hands-On Coding: Nested Loops & Conditions (15 minutes)
“But what if the robot wants to decide how close that something is — far, near, or too close? That’s not one question anymore — it’s many! So today, our robot will learn to think in layers, just like we do.”
Step 1: Drawing the Flowchart (5 minutes)
Give each group a blank sheet and markers.
“Before we start coding, let’s plan what the robot should think like. Robots don’t guess — they follow logic.”
Guide them through simple discussion questions:
“If the robot sees something very far, what should it do?”
(Students may answer: keep moving forward.)
“If it sees something a little closer?”
(Maybe: slow down or turn a little.)
“And if something jumps right in front of it?”
(Stop! Maybe back up, or show an angry emoji.)
“Finally, what if it doesn’t see anything for a long time?”
(It could explore happily or get bored.)
Encourage them to turn these ideas into a decision flowchart:
- Is anything detected?
- No → Keep moving (happy face)
- Yes → Then check how close it is
- Very close → Show angry face → Back up
- Medium distance → Turn away 90°
- Far → Move forward carefully
“This is your robot’s brain — a map of how it decides things!”
Step 2: Moving from Flowchart to Code (10 minutes)
Now that we have our flowchart ready, let’s start building our code.
First, let’s start with what we have already made. A code block that checks a single condition and makes the robot react to it.
To make the bot react differently to some other condition, first we have to code that condition. Let’s look at our flow chart:
- The normal behaviour of the robot when nothing is front of it, it should smile and move forward. So let’s just start with that:
Encourage students to experiment with different values and decide which value indicates that the path is clear
- Now that the normal behaviour is coded, the next condition would be that there is something in the robot’s path, but it is far away. That means, the sensor value is lower than the one we used before which indicated a clear path, but it is still not that low. For example, if the value 800 indicates a clear path, then 600 could indicate an object far away.
At this point, you also have to the logic of how we are using these loops and how they work. The reason we have coded the next condition in the “else” part of the first loop is because the second condition should only be checked if the first isn’t true.
If the path is clear, it should only move forward and not execute any other condition.
We can also understand this by looking at our code. The first condition is true when the value is greater than 800 while the second will be true if the value is greater than 600.
Now, if both conditions are checked simultaneously for a value, say 900, then both conditions will be satisfied and two different movement instructions will be executed at the same time. This will create confusion for the robot. So, we have to design our code in a way that only one condition is checked at a time.
- Repeat the same process to code the next conditions.
Each condition will be coded in the else part of the previous condition block.
Encourage students to code as many behaviours as possible by adding more if-else blocks
Teacher Prompts During Coding
“Why do we need the forever loop?”
→ To keep checking continuously, so the robot can change its behavior instantly.
“What happens if we just use multiple if blocks instead of if-else?”
→ The robot might react wrongly — it could behave unexpectedly as multiple conditions can be true at the same time!
“Can you make the robot show its feelings using emojis?”
→ Helps students connect logic with expression — coding meets creativity.
“How does the robot know when to switch from angry to happy?”
→ This opens discussion on sensor thresholds — how numbers define emotions for a robot.
Step 3: Testing and Refining (5 minutes)
Let students test their code with real obstacles — hands, books, or boxes.
Encourage them to narrate what they see:
“When I move my hand slowly toward your robot, what does it do? Does it change behavior as I get closer?”
Ask them to experiment with distance limits (e.g., <200 mm, <400 mm, etc.) to tune responses.
Mini-Debrief Discussion
“Now your robot doesn’t just see an obstacle — it understands what kind of situation it’s in.
It’s not a one-question robot anymore. It’s starting to think like a cautious driver or a curious pet.”
Would you like me to now write Section 5: Student Extension (Emotion after N steps) in the same format? It’s a natural continuation from this part — where they add memory and timing into behavior.
5. Student Extension (10 minutes)
- Add a “bored / curious” emotion if the robot hasn’t seen anything after several steps
- Encourage experimentation with different angles, emojis, and thresholds
- Students test scenarios and debug: what works, what doesn’t
Teacher Prompts:
- “Can your robot patrol like a guard or act like a pet?”
- “Which emotion is funniest or most surprising when it happens?”
6. Wrap-Up / Reflection (5 minutes)
“Today, your robot learned to react like a little creature: happy, cautious, or startled. How did it feel watching it make its own choices? Who wants to share the most surprising thing their robot did?”
Teacher Prompt:
- “Next time, we’ll combine these decisions with more sensors, making the robot even smarter. Could it patrol, follow, or even play with us? Let’s push it to the limit.”



