## Introduction: Creating Bumpers for a Robot

In my grade 11 computer engineering course, we were given the task to make our robot go through a maze. In order to control if it goes straight, turns left or right we were asked to make bumpers. This way if the robot touched the wall and it hit the right bumper, the robot would turn left and if it hit the left bumper the robot would turn right. So essentially our task was to create a bumper that is able to be pushed in to allow to turn and I also need to come back out so it doesn't keep turning on a loop. However, setting up a bumper also requires you to set up a code and a circuit in order to get your bumper running. Follow the following steps to learn how to make your very own bumper for a robot.

## Step 1: The Circuit

In order to get the bumpers to work , you have to create a circuit on the breadboard on the top of your robot.

( follow the picture above to achieve 2 bumpers)

Materials Needed

• 2 small led lights (to ensure your bumpers are working)
• 8 wires
• 2 brown-black-yellow resistors
• 2 red-red-brown resistors

Some things to keep in mind

• The Vss is the "ground" there for it is equal to zero and the Vdd is equal to 1
• When the circuit is running the value is 0 when it is not running the value is 1
• The flat side of the led is negative and the other side is positive

Common Mistakes in Circuits

• LED is the wrong way
• The LED, resistor and wire are not lined up in the same column
• The led doesn't work anymore

## Step 2: The Code

The Code :

' {\$STAMP BS2}
' {\$PBASIC 2.5}

LBump PIN 11

RBump PIN 10

LMOTOR PIN 15

RMOTOR PIN 14

RFast CON 650

LFast CON 850

RSlow CON 700

LSLOW CON 800

MStop CON 750

RFastRev CON 850

LFastRev CON 650

RSlowRev CON 800

LSlowRev CON 700

MLoopC VAR Word 'For..Next Variable up to 65000ish

DO

GOSUB Forwardfast 'go forward

IF IN10 = 0 THEN ' if the two wires in input 10 are pressed then turn left

GOSUB TurnLeft90

ELSEIF IN11 = 0 THEN 'if the two wires in input 11 are pressed then turn right

GOSUB TurnRight90

ENDIF

LOOP

TurnRight90:

' Subprocedure to Turn 90deg Right

'**********************************************************

HIGH 1

LOW 0

FOR MLoopC = 1 TO 22

PULSOUT LMOTOR, LfastRev 'move forward one pulse

PULSOUT RMOTOR, Rfast ' using pins and constants

PAUSE 20

' 20mS allows robot to move ' before NEXT pulse

NEXT

RETURN

'*********************************************************

TurnLeft90:

' Subprocedure to Turn 90deg Right

'********************************************************

HIGH 0

LOW 1

FOR MLoopC = 1 TO 22

PULSOUT LMOTOR, Lfast 'move forward one pulse

PULSOUT RMOTOR, RfastRev ' using pins and constants

PAUSE 20 ' 20mS allows robot to move ' before NEXT pulse

NEXT

RETURN

'***********************************************************

ForwardFast:

' Subprocedure to move the robot forward one square fast

'**********************************************************

FOR MLoopC = 1 TO 70

PULSOUT LMOTOR,

LFast PULSOUT

RMOTOR, RFast

PAUSE 20

NEXT

RETURN

Brief Overview

The purpose of this code is to program the robot to turn left when the right wires ( bumper) is pressed and turn right when the left wires ( bumper) is pressed.

What does the code mean?

Well before I answer that question you should be familiar with what some of the codes used in this program mean.

GOSUB - so sub stands for go to subroutine ( the subroutine must be identified in your code)

ENDIF - used to end multiple lines IF command

_________________________________________________________________________________________

explaining the meaning behind the code.....

DO
GOSUB Forwardfast

- Is telling the robot to go forward right when it is turned on

IF IN10 = 0 THEN

GOSUB TurnLeft90

- is saying that if the two wires in input 10 ( the right bumper) touch then the robot will turn left at a 90 angle.

ELSEIF

IN11 = 0 THEN
GOSUB TurnRight90

- is saying that if the two wires in input 11 ( left bumper) touch then the robot will turn right at a 90 angle.

TurnRight90:
' Subprocedure to Turn 90deg Right

'**********************************************************

HIGH 1

LOW 0

FOR MLoopC = 1 TO 22

PULSOUT LMOTOR, LfastRev

PULSOUT RMOTOR, Rfast

PAUSE 20

NEXT RETURN '*********************************************************

- this is an example of a subroutine which is used so you dont have to repeat the same long code over and over again. this way your code looks neater and more put together.

- the high 1 / low zero means that when the robot turns right ( the left wires touch) the led turns on, this way you know everything is working.

## Step 3: The Bumpers ( Materials Required)

To make the bumper, you will need...

- 4 Popsicle sticks for the main structure and 2 Popsicle sticks to mount the bumper onto the robot

- 4 pieces of a sponge

- 4 paper clips

- so aluminum foil

- 4 wires ( to connect to the breadboard, explained in step 1 about the circuit)

- hot glue gun and glue sticks