Harmony Virtual Lab

Digital Technologies · Algorithms, programming and robotics

Programming a robot: sequence and loops

Write a program of moves and turns to steer a robot to its goal, then shorten it with a loop.

Start this experimentAll Digital Technologies experiments

Aim

To write, test and debug a simple program using sequence and iteration (loops).

Apparatus

  • Floor robot or programmable buggy (or this simulator)
  • Grid mat with obstacles

Theory

An algorithm is a step-by-step set of instructions. A program is an algorithm written so that a machine can follow it. The robot obeys three instructions: move forward one square, turn left, turn right.

Sequence means doing instructions in order. Iteration (a loop) repeats a set of instructions, so a pattern only has to be written once. Finding and fixing mistakes is called debugging.

Procedure

  1. Choose a level and study the grid: the robot must reach the flag without hitting a wall.
  2. Add instructions to the program. Pressing Forward again increases the count.
  3. Run the program. Every run is logged.
  4. If the robot crashes or stops short, debug the program and run it again.
  5. On levels 3 and 4, find the repeating pattern and use “repeat the whole program” to write a shorter solution.

What you do in the virtual lab

Set up the apparatus on screen, take readings and record them in a table (Level; Program; Repeats; Instructions written; Steps run; Result). Simulated instruments give slightly different readings each time, as real ones do. Finish with a short quiz; every answer is explained.

Teachers can set the experiment for a class, see each student’s results and use it as a WAEC- or NECO-style practical paper in exam practice.

Practice questions

  1. A step-by-step set of instructions for solving a problem is called

    1. an algorithm
    2. a loop
    3. a bug
    4. hardware
    Show the answer

    A. an algorithm An algorithm is the plan; a program is the algorithm written for a computer.

  2. Repeating a group of instructions several times is called

    1. sequence
    2. selection
    3. iteration
    4. debugging
    Show the answer

    C. iteration Iteration means looping. Selection means choosing between paths (if…else).

  3. A robot facing north obeys: Turn right, Turn right, Turn right. It now faces

    1. north
    2. east
    3. south
    4. west
    Show the answer

    D. west North → east → south → west.

Do the experiment and the full quiz

Related Digital Technologies experiments

  • Logic gates and truth tablesDigital Technologies · SSS 1 – SSS 2Switch the inputs of AND, OR, NOT, NAND, NOR and XOR gates and build each truth table.
  • Binary, octal and hexadecimalDigital Technologies · JSS 2 – SSS 1Flip eight bit-switches to see how computers store numbers, then hit target values in binary.
  • How strong is a password?Digital Technologies · JSS 1 – SSS 2Test made-up passwords, measure their strength in bits and see how long an attacker would need to guess them.
  • Spreadsheet formulas and functionsDigital Technologies · JSS 2 – SSS 2Use cell references, SUM, AVERAGE, MAX and IF to complete a shop sales record and a class result sheet.
  • Coding in PythonDigital Technologies · SSS 1 – SSS 3Write real Python – print, variables, loops and if statements – and have each program checked automatically.
  • Train a simple AIDigital Technologies · JSS 3 – SSS 3Teach a computer to tell ripe plantain from unripe by giving it labelled examples, then test how accurate it is.