Skip to main content

Introduction

You may have found that when testing your robot, it was sometimes difficult to know what was going wrong as there was no feedback about the sensors! Let's use the sparkles to add some feedback and make it easier to see what is going on.

  1. Let's add some more modules to allow our robot to give feedback about the line it is following.
    • Let's add some more modules to allow our robot to give feedback about the line it is following.

    • Add the Line sensor underneath as before then add Sparkle and buzzer modules to your robot like in the picture.

    • It can be quite hard to see the wiring with so many things plugged in! The motors and line sensor should be the same as before (M1, M2 and P0, P1)

    • Plug the buzzer into P2, and the Sparkles into P8.

  2. Load up your two sensor line follower program from the last lesson.
    • Load up your two sensor line follower program from the last lesson.

    • It should look something like our example in the picture.

  3. Let's use the outer front two Sparkles (0 and 2) to show the state of the two infrared sensors.
    • Let's use the outer front two Sparkles (0 and 2) to show the state of the two infrared sensors.

    • If the left sensor is on the line (0), turn the left Sparkle green.

    • If the left sensor is off the line (1), turn the left sparkle red.

    • Drag your main program to the side for now - don't delete it!

    • Write the simple code in the picture - test it on the track by moving the robot side to side across the line.

    • You will need to install the Neopixel package and setup the Sparkles - if you can't remember how, have a look at the Sparkles Guide.

  4. Let's use the right Sparkle (Sparkle 2) to do the same thing for the right hand sensor.
    • Let's use the right Sparkle (Sparkle 2) to do the same thing for the right hand sensor.

    • Add some blocks to set the right Sparkle in the same way as the left one, but using the right sensor.

    • There are some hint blocks if you need them!

    • Don't forget to test it properly.

  5. Let's add some more blocks so the middle Sparkle (Sparkle 1) is green when both sensors are on the line.
    • Let's add some more blocks so the middle Sparkle (Sparkle 1) is green when both sensors are on the line.

    • This is when both the left sensor and right sensor are 0!

    • Add a third IF/ELSE block that checks if both the left and right sensors are 0, and sets the middle Sparkle green if they are.

    • There are some hint blocks if you need them!

    • Don't forget, the AND block is in the logic menu.

  6. You may have thought the last program didn't look quite right - as the robot moved over the line, two Sparkles changed at once!
    • You may have thought the last program didn't look quite right - as the robot moved over the line, two Sparkles changed at once!

    • It would be more sensible for the program to set just the middle Sparkle green when both sensors are on the line, instead of all three.

    • We need to change the code to do this, to set the colours of all three Sparkles for each combination of sensor states.

    • In the picture is the structure you will need - 3 IF blocks for checking if the robot is to the left, right or on the centre of the line.

    • Add blocks to the bottom two IF blocks to set the Sparkles properly, like in the top IF block we have done already.

  7. You may have noticed that our Sparkle code and line following code have some very similar IF blocks.
    • You may have noticed that our Sparkle code and line following code have some very similar IF blocks.

    • Move the Sparkle blocks into the matching IF blocks in the main program, to merge your line follower and Sparkle programs together.

    • You should end up with something like the picture - a combination of the Sparkle and Line following code.

    • Test it properly on the track!

  8. What about when the robot comes off the line completely? Add some more Sparkle blocks to the first IF block to turn all the Sparkles red if the robot is off the line.
    • What about when the robot comes off the line completely?

    • Add some more Sparkle blocks to the first IF block to turn all the Sparkles red if the robot is off the line.

  9. Our robot should probably make more of a fuss if it gets lost completely and doesn't know where the line is.
    • Our robot should probably make more of a fuss if it gets lost completely and doesn't know where the line is.

    • Add some blocks to make the buzzer beep SOS if the robot goes off the line.

    • You can look back at the Morse Code lesson if you can't remember how to do this!

Finish Line

Tech Camp

Member since: 10/03/2012

119 Guides authored

Team

Tech Camp Staff Member of Tech Camp Staff

6 Members

140 Guides authored