AI Lab - Session 2 - Program Your Robot Brain

AI Lab Session 2: Program Your Robot Brain

Architect: Muhammad Bilal – Markhor3D
Duration: 50-60 minutes


Equipment Required:

  • M3D Robotics kit (M3D Go, attachments: pen, shovel, dumper).
  • Laptops with Scratch pre-installed.
  • Paper and pencils for students to document discoveries and ideas.
  • Markers and small obstacles for robot navigation.
  • Projector and screen (optional for demo).

Learning Objectives:

By the end of the session, students will:

  • Understand the concept of repetition and loops in programming.
  • Use repeat and forever blocks to automate tasks.
  • Program the robot to move and draw using pen attachment.
  • Introduce variables and understand how a robot can “remember” input.
  • Use the Scratch ask and answer blocks to make the robot respond dynamically.
  • Connect programming logic with math concepts (multiplication, geometry).

Resources:


1. Introduction & Discussion: Loops in Daily Life (10 minutes)

Start with a question to spark curiosity:

“How many of you brush your teeth every morning? And every night too?”

  • Let students share answers, then continue:

“Exactly! You do the same steps each time—pick up your brush, put toothpaste, scrub, rinse. That’s a routine you repeat! And you don’t need to be told how to brush your teeth every morning. You know each step.”

  • Invite more examples from their daily lives:

“Can you think of other things you do every day, week, or even every minute that repeat? Maybe songs on repeat, turning on a fan, playing a game level… what else?”

  • Connect to coding naturally:

“All these repeated actions are kind of like loops in programming. A loop tells the robot to do something again and again automatically. Just like you don’t have to think while brushing your teeth what the next step is, a loop helps robot work so you don’t have to keep pressing buttons each time. Today, we’ll teach our robot to follow loops just like your routines!”

  • Ask them to imagine:

“If your robot could follow your routines, what would you make it repeat first? Walking back and forth? Drawing a shape? Or something really silly, like spinning around?”

  • Let a few students share examples.

Teacher’s Role:

  • Encourage participation, let students share relatable examples.
  • Use examples they give to connect real-life repetition to loops.

2. Hands-On Practice: Repetition with Code Blocks (10 minutes)

Activity: Students will perform small tasks using simple code blocks to experience repetition.

  • First, ask students to drag a single movement block (e.g., “move forward”) and press green flag.
  • Then ask them to repeat it manually 3–5 times:

“Can you make the robot move forward, then stop, then move forward again… and again… how many times does it take to reach the marker?”

  • After a few attempts, introduce repeat blocks:

“Instead of dragging the same block multiple times, we can tell the robot: ‘Hey, do this 4 times!’ That’s what a loop does—it saves time and energy!”

  • Students practice wrapping a movement block inside a repeat 4 block.

Teacher’s Role:

  • Move around, check that students understand the concept of repetition.
  • Ask:

“What would happen if we increased the number inside the repeat block? Can you predict?”


3. Repeat and Forever Blocks (10 minutes)

Activity: Introduce forever loops and chaining multiple actions.

  • Demonstrate how to stack blocks: move forward → turn → move forward → turn.
  • Wrap them in a repeat block to patrol back and forth.

“Let’s say our robot is guarding a treasure. We want it to go forward, turn around, and go back. If we wrap this sequence in a repeat block, it will patrol automatically. Can anyone think of other places robots patrol?”

  • Introduce forever for continuous actions:

“If we want our robot to patrol all day without stopping, we can use a forever loop. But be careful—forever means forever until you tell it to stop!”

Teacher’s Role:

  • Ask students to predict movements before running the code.
  • Encourage experimentation with repeat counts and sequence order.

4. Drawing Shapes with Pen Attachment (10 minutes)

Activity: Students use loops to draw simple shapes.

  • Ask students to draw a square: 4 sides, 4 turns of 90°.
  • Show how to wrap the movement and turn blocks inside a repeat 4 block.

“See how one loop can replace 4 blocks? Can you predict how many steps it will take to draw a triangle or pentagon?”

  • Connect math concepts:

“If each side is 10 steps, how many total steps does the robot take to draw a square? How about a triangle?”

  • Encourage students to experiment with different shapes using loops and pen attachment.

Teacher’s Role:

  • Ask them to explain their calculations.
  • Encourage sharing of creative shapes beyond the examples.

5. Introducing Variables: Remembering and Asking (10 minutes)

Activity: Transition into variables naturally.

“So far, we’ve been telling the robot exactly what to do, and it does it. But what if we want it to remember something, or respond to us instead of just following fixed instructions?”

  • Introduce the concept of variables:

“A variable is like a little memory for your robot. It can store a number or text that it can use later. For example, it can remember how many steps it should take, or the answer to a question you ask it.”

  • Demonstrate ask [What is your favorite number?] and wait block.
  • Show that the robot stores the answer in the built-in variable answer.

“Now we can use this number in our loops. If I ask how many times the robot should spin, it will read your answer and do it exactly that many times!”

Teacher’s Role:

  • Guide students to try asking the robot a question and using ask block in a loop.

You may ask:

“What other questions could your robot ask to decide what to do next?”


6. Wait Until Block & Conditional Loops (10 minutes)

Activity: Introduce automation with conditionals.

  • Show wait until block and explain how it can pause actions until a condition is true.
  • Combine with answer variable:

“Let’s say the robot asks, ‘Are you ready to start?’ It will wait until your answer is yes, then begin the loop. This way, your robot can react based on what you say!”

  • Students try coding:

    1. Robot asks a question.
    2. Wait until answer meets a condition.
    3. Execute a movement or drawing sequence.

Teacher’s Role:

  • Encourage creativity:

“Can you make the robot dance only if your answer is ‘yes’? What else could it do?”

Their code should look something like this:

  • Discuss real-life analogies of conditional loops (e.g., traffic lights wait until cars are present, elevator stops only when someone presses a button).

7. Conclusion & Reflection (5 minutes)

Wrap-up Summary:

“Today, we learned how to make our robot repeat actions using loops, draw shapes using the pen, and even remember your input using variables. We also taught it to respond dynamically using wait until blocks. Now your robot is a little smarter—it can follow routines AND respond to you!”

Encourage students to share ideas:

“What else could your robot remember? What questions could it ask next time?”

Teacher Reminder for Students Feeling Confused:

“Some of you might be thinking, ‘Why are we learning this? How is this helpful?’ That’s okay! Remember, this is just the start. We are learning different tools one by one, and soon, you’ll start to see how these tools integrate with each other and help you make a smart robot that can do really cool things on its own.”

Learning Outcome:
By the end of the session, students will:

  • Be confident using loops (repeat, forever) for repetitive tasks.
  • Understand basic variables and the answer memory in Scratch.
  • Combine loops and variables with wait until for interactive behavior.
  • Connect programming with math concepts and geometry.