Skip to main content

1.1

by Tech Camp

Introduction

Using some switch sensors and clever coding, let's make your robot safely navigate the Martian rock fields!

  1. Hopefully your robot now makes it across the rock field fairly well - but only if the obstacle is directly in front.
    • Hopefully your robot now makes it across the rock field fairly well - but only if the obstacle is directly in front.

    • You might find it gets stuck with obstacles on the left and right - but we have two switch sensors, so we can upgrade the robot to fix that!

    • Put your other switch module onto your robot, and move the first one so it looks like the picture.

    • You should have 1 switch plugged into a1, and the other into b1.

  2. Let's test the left sensor.
    • Let's test the left sensor.

    • When the left switch is pressed, the robot should reverse and turn right to avoid the obstacle.

    • Try building the program in the picture and test your program!

    • Don't forget, you might need to adjust how far the robot turns and reverses for it to work well.

    • Make sure you understand this program - we have taken out some of the motorRun lines that aren't needed, as sometimes one of the motors is already going in the direction we want.

  3. You might have noticed something new in the last program - the text explaining what the code was doing was an example of comments.
    • You might have noticed something new in the last program - the text explaining what the code was doing was an example of comments.

    • Comments are very important - they remind you what your code is doing, but also help others read and understand your code.

    • You can add a comment using two forward slashes ( // ). You can then type anything you like afterwards, and it will be ignored by the robot.

    • Try adding some more comments to your code now!

  4. Now let's test the right switch.
    • Now let's test the right switch.

    • Change the program so it checks the right sensor, and then turns left to avoid the obstacle!

  5. Change your one switch code from the last challenge so both switches are being checked. Make sure that when the left switch is hit, the robot reverses and then turns to the right,  (away from the obstacle) and when the right switch is hit it reverses and then turns to the left.
    • Change your one switch code from the last challenge so both switches are being checked.

    • Make sure that when the left switch is hit, the robot reverses and then turns to the right, (away from the obstacle) and when the right switch is hit it reverses and then turns to the left.

    • Test your program properly in the rock field, and try to adjust the delay times so it works as well as possible!

    • There's some example code in the picture if you need a hint - but it is missing a lot of lines you will need to fill in!

  6. Let's add some more feedback to the robot so we know what its doing.
    • Let's add some more feedback to the robot so we know what its doing.

    • Add the LED and buzzer modules to your robot, and plug them into the last two pins.

    • Extend your program so that:

    • When driving forwards, the green LED is on.

    • When an obstacle is hit and the robot is reversing and turning, the red LED is on.

    • When the robot is reversing, the buzzer should beep to warn people to get out of the way!

    • If you can, try to make the buzzer beep several times as the robot is reversing instead of being on all the time.

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