Line Following, Obstacle Avoiding , and Victim Finding , Oh My!

The robot's objectives are the following:

1. Follow a line with sharp turns

2. Maneuver through breaks in the line

3. Detect obstacles and manuever around them

4. Identify colors to be able to locate green and aluminum victims.

 

 

VIDEOS OF THE ROBOT IN ACTION

 

 

 

GOAL: This robot will be built to compete in the 2008 Robocup Junior Rescue competition. In this competition the robot must " follow a black line which twists and turns , avoid obstacles present on the line , and identify green and aluminum tape victims with a flashing lamp". The robot itself will have three main functions making it a 3 in 1 robot .

 

 

 

Lets begin the long process of researching , designing , building, and programming the robot.

Note: Quite a few people have told me that they would probably do only part of this tutorial , and not the entire project. Therefore , I have divided each "part" of the tutorial with its own parts needed list. A I hope you learn something from this tutorial!

 

The Bill of Materials and Hours Spent can be found here :

Research:

After many , many hours of research I decided upon making a prototype version , which would allow me to test out the different concepts which I will need to master before finishing this robot.

I broke down the robot into 5 subsytems: Locomotion , Power , Sensors , Control, and Display.

  1. Locomotion - I will use two HS-42BB servos for locomotion and one ball caster
  2. Power - four AA batteries will provide the power for all the systems
  3. Sensors - five QRB1113 reflective object sensors will track the line , one scanning PING ultrasonic sensor will provide ranging, and one photoresistor /LED will search for victims.
  4. Control - One PIC 16F616 microcontroller will act as the brains for the robot . It will be programmed in PICBASIC and assembly
  5. Display - one LCD display will show what routine is being done , one LED will show power , and one LED will flash when a victim is detected.

 

Summary of Robot Procedure

I made a quick CAD of what my final product should resemble.

 

 

 

After ordering all these parts from various online stores, i put together the first version of my line following robot. The assembling of this version is unimportant , as it was just a testing platform.

 

 now the good version

 

 

Here's a quick video of it. As you can see , it is unable to handle sharp turns and is relatively slow. Also note the crude design and the hotglue everywhere. The completed , plexiglass version of this robot will be faster and more sophisticated.

 

 

 

 

Designing:

Here is the list of things which I learned from the prototype version of the robot.

After this I drew up the design of the bottom of the robot.

 

CAD As you can see the IR sensor array is in front. Servos are on the side and the caster is on the back.

 

 

Before we begin assembling the mount for the line sensors , lets just review how they work. In your QRB1113 sensor there are actually two components, an IR emitter and a phototransistor. The IR emitter LED , as its name implies , emits infrared light which is "invisible" to the human eye. But, a cool trick with IR light is to use a camera, such as a cell phone camera, to see the IR light.

The IR will appear to the camera bluish/ purpleish , while looking ( or not looking) invisible to you. this is very useful when debugging IR circuits   Anyway, lets get back on track. The IR LED emits infrared light and the phototransistor will detect the amount of IR light being reflected from the object. Since black objects reflect less light than white objects, the difference can be detected and fed to the microcontroller.

Building:

Before we begin building you should have the following tools on hand:

1. Soldering Iron with solder

2. Ratchets

3. Hammer

 

4. Drill with various bits

5. Phillips screwdriver ( electric or nonelectric)

6. Vise ( optional, but it'll make your life easier)

7. Pliers

8. Glue Gun

9. Tablesaw is the best but Jigsaw or Hacksaw is acceptable

 

You can get a jig saw for cheap here : American Science and Surplus

 

 

 

 

 

 

 BREAK TIME

Go ahead and take an hour or two break. You'll need the energy . Take a walk, watch some TV, or just get some fresh air.

 

I hope you enjoyed your break. Lets get back to business.

So far I've explained to you how everything will work , but we now have to assemble everything .

Also, in the following instructions there are pictures posted. To enlarge any picture simply right click the picture and then click View Image.

 

DISCLAIMER: ANYTHING THAT YOU BUILD , WHETHER SEEN ON THIS SITE OR ELSEWHERE, SHOULD BE DONE WITH CAUTION AND WITH THE SAFETY IN MIND. DO NOT USE ANY TOOLS IF YOU ARE NOT FAMILIAR WITH THEIR USE. BY CONTINUING TO READ THIS TUTORIAL AND BY CLICKING THE LINK TO SEE THE ACTUAL INSTRUCTIONS , YOU ARE ACCEPTING RESPONSIBILITY FOR ANY DAMAGE OR INJURY WHICH MAY OCCUR BY FOLLOWING THE INSTRUCTIONS PRESENTED IN THIS TUTORIAL.

 

 

 

 

 

*** Bill of Materials and Hours Spent ***

Here is the bill of materials for this robot. Now before all of you are baffled by the realtively high price let me let you in on a little secret. Some of the parts here were reused from previous projects I made .

I got plexiglas donated to me, I got some parts as free samples,  I got the PICBASIC PRO compiler for free from a friend, and I bought a ton of parts on eBay for up to 75% off what it usually goes for. So the actual total cost for me personally was less than $50 , most of the savings are from already owning the parts.

PART

QUANTITY

TOTAL

TOTAL W/OUT EXTRAS:

        $107.90

w/ options = $477.90


QRB1113 IR reflective sensors

5

5 @(FREE SAMPLES) = $0

3" x 3/4" aluminum mending plates

2

2 @($.6225 ea.) = $1.25

1 1/2" #8-32 machine screw

3

3 @($.07 ea.) = $0.21

1/2" # 8-32 machine screws

11

11 @($.07 ea.) = $0.77

#8 washers

16

16 @($.06 ea.)= $0.96

#8 nuts

14

14 @($0.12 ea.)= $1.68

"L" brackets

4

4 @($0.66 ea.) = $2.64

1 foot of 1/8" diameter heat shrink

1

1 @($1.30 ea.)=$1.30

400 K ohm Photoresistor

1

1 @($2.00 ea.)=$2.00

HS-425BB servos

2

2 @($14.99 ea.)=$29.98

Universal Servo Mounts

4

4 @($0.975 ea.) = $3.90

3/8" #4 Screws

8

8 @($0.12 ea.) = $0.96

1/2" #4 Screws

4

4 @($0.12 ea.)= $0.48

2.5" Airplane Wheels

2

2 @($0.2645 ea.) = $5.29

Ball Caster Kit

1

1 @($3.00 ea.)= $6.00

Plexiglas Base

1

1 @(DONATED)= $0

4AA Battery Holder

1

1 @($1.10 ea.) = $1.10


 

Universal Sensor Mount

1

1 @($4.95 ea.)= $4.95

Parallax PING Ultrasonic Sensor

1

1 @($29.95 ea.)=$29.95

HS-311 Servo

1

1 @($8.99 ea.) = $8.99

400 Point Breadboard

1

1 @($4.00 ea.) = $4.00

10K ohm resistor

5

5 @($0.10 ea.) = $0.50

220 ohm resistor

6

6 @($0.10 ea.)=$0.60

.1uF ceramic capacitor

2

2 @($0.07 ea.)=$0.14

T 1 ¾ LED

1

1 @($0.15 ea.)= $0.15

100K resistor

2

2 @($.05 ea.)= $0.10

PIC16F616

1

1 @(FREE SAMPLE)

PICBASIC PRO Compiler (Optional)

1

1 @($250) = $250

U2 Programmer(Optional)

1

1 @($120)= $120


 

 

 

 

 

 

TIME SPENT

 

Researching : 50 hours

Designing:     100 hours

Assembling :  10 hours

Documenting: 35 hours

 

For a total of : 195 hours

 

 

Whats the reason for all that time researching and designing? This was my first project with a microcontroller, with IR photoreflective sensors, with PING ultrasonic sensors , and with PICBASIC. If I were to do a similar project now, after gaining all this knowledge, I would probably finish eveything in under 20 hours.

 

 

1. Making the Line Following Sensor Mount

I. MAKING THE LINE FOLLOWING SENSOR MOUNT:

 

To make the mount for the IR sensors you need the following

  1. Five QRB1113 Sensors ( available from Fairchild Semiconductor) QRB1113
  2. Four pieces of 3" x 3/4" aluminum mending plates Aluminum mount (BUY NOW)
  3. One 1 1/2" #8-32 machine screw  (BUY NOW)
  4. Nine 1/2" # 8-32 screws Screw and Nut (BUY NOW)
  5. Sixteen #8 washers  (BUY NOW )
  6. Ten #8 nuts  (BUY NOW)
  7. Four "L" brackets ( BUY NOW )
  8. Some Wires ( preferably more than 24 gauge)
  9. A foot of 1/8" diameter heat shrink (BUY NOW)
  10. Hotglue Stick (BUY NOW)

11. 16K to 1M Photoresistor (BUY NOW)

STEPS

1. First bend over the two middle legs of the QRB1134 , so that they touch each other .

 

 

2. Then solder the two middle legs of EVERY sensor together

 


 

( STEPS 3 -5 SHOULD ONLY BE DONE TO TWO SENSORS. AFTER STEP 5 IS FOR THE THREE OTHER SENSORS )

3. Put a washer on the 1/2" machine screw.

4. Using a screwdriver , screw in the 1/2" screw with the washer into the sensor. Make sure the washer does not fall off.

5. Repeat this so you have two screws which have 1/2" screws going through them. This is the outside sensors .

 

 http://i273.photobucket.com/albums/jj202/erobot/Picture11-1.jpg

 

 

6. Now mount one of the remaining sensors through its screw on the long side of an L bracket. Put a nut on the end. The order is:

Sensor with screw in it ----L bracket ---- nut

 


7. Repeat Step 15 for the other sensor.

8. Now mount an L bracket with sensor to one side of the mending plate .

9. Repeat Step 17 for the other sensor and screw.

 

 

 

10. Now take the 1 1/2" machine screw and put a washer on it. We are now mounting the three middle sensors.

11. Using a screwdriver, screw in the screw through one of the sensors.


 


12. Now push the end of the screw through a hole on only one mending plate .

 

 

 

13. Now add four #8 washers through the screw so that on the screw there is the following c

omponents in the following order.
Washer --- Sensor --- Mending plate --- 4 washers

 

14. Use the screwdriver again and screw in the 1 1/2" long screw through another sensor. The order on the screw should be like this:

Washer --- Sensor --- Mending plate --- 4 washers ---Sensor

15. Add four more washers to the end of the screw. The arrangment on the screw looks like this:

Washer --- Sensor --- Mending plate --- 4 washers ---- Sensor --- 4 washers

 


 

 

16. Push the second mending plate onto the end of the screw. The order now looks like this:

Washer --- Sensor --- Mending plate --- 4 washers ---- Sensor --- 4 washers --- Mending Plate

 

17. Screw in another sensor at the end and put a washer and a #8 nut on the end . Almost done!

Washer --- Sensor --- Mending plate --- 4 washers ---- Sensor --- 4 washers --- Mending Plate --- Sensor --

Washer -- Nut

 


 

18. Tighten the nut with pliers or a ratchet and make sure all the sensors are aligned and facing the same way.

Alright we mounted the middle sensors!

 

19. Now align all the sensors and tighten all the nuts. 95% Done !

 

20. Next just solder red wires to all the legs except the middle pins.

 

 

 

21. Mark the wire that is attached to the S side with white wire.

22. Solder a black wire to all of the middle pins of all the sensors. Solder all these wires together. Look in the picture carefully to notice the black wires.

 


 

23. Solder a black wire to the any another black wire connected to a sensor. This will be the wire which is negative or ground for the entire sensor array.

24. Now apply the heat shrink to the pins of the sensors. Place your soldering near the heat shrink to shrink it. Then you can add hotglue on top of the heatshrink or instead of the heatshrink.

 


 

 

25. NOW THAT WASN'T THAT HARD! :#)

 

 

 

 

 

One more step and the entire mount is done. Take a photoresistor , cover it in heatshrink and hotglue it in between the two mending plates. Instructions are here , follow them exactly!

So you should have something that looks like this:

 

 


 

Also right now you should mark the sensor wires with a specific label or with a specific color electrical tape. I just wrapped a different color electrical tape for each sensors wires .

 

Now remember those wires marked with white tape? Do the following to them.

The outermost left sensor's signal wire should be wrapped with yellow tape .

The outermost right sensor's signal wire should be wrapped with green tape.

The left sensor's signal wire should be wrapped with blue tape.

The center sensor's signal wire should be wrapped with red tape .

The right sensor's signal wire should be wrapped with white tape .

 

MAKE SURE YOU KNOW WHICH WIRE GOES WHERE. LABEL IT WITH A REGULAR LABEL OR WITH TAPE. KNOW WHICH IS THE SIGNAL WIRE AND POWER WIRE FOR EACH SENSOR.

 

 

An optional choice here would be to add wire connectors to each of the sensor wires . Instructions can be found in this tutorial created by Admin http://www.societyofrobots.com/electronics_wire_connector.shtml

 

 

 

2. Making the Plexiglass Base

II . MAKING THE PLEXIGLASS BASE

Its come time to make the plexiglass base. Truthfully it can be any material - but I recommend plexiglass or HDPE plastic.Download this file into Google SketchUp , and print it out to scale. Follow these instructions on printing out to scale using SketchUp. Now print out the picture below . The picture below shows what each hole will be used for , as well as showing what diameter drill bit you should be using. The drill bit size is located in the respective boxes. Be careful when cutting the template though.

 

 

 

 

 

 

Some info on using a jigsaw ( thanks GariWilson for finding it )

 

III. ADDING ON LOCOMOTIVE POWER

You will need the following components :

Two HS-425BB servos  (BUY NOW)

Four Universal Servo Mounts  (BUY NOW )

Eight 3/8" #4 Screws  (BUY NOW)

Four 1/2" #4 Screws (BUY NOW)

Two 2.5" Wheels  (BUY NOW)


Ball Casters Kit  (BUY NOW)


 

 

1. First modify both of the servos as shown in this tutorial .In the tutorial where it says to center the servo the code in PICBASIC is .

PULSOUT (location ), 150 . For example

Start: ' Start Label

PULSOUT PORTB.4 , 150 ' Send a pulse to the servo

PAUSE 18 ' Pause 18 milliseconds

Goto Start 'Make a loop of it

. Please note this is at 4 mhz , for 8 mhz the resolution would be doubled to 300.

2. Now mount a universal mount to each side of both servos using the 3/8" #4 screws.

3. Print out this drilling template and drill holes where it shows . Use a 1/4" bit on the drill.

Notice how the servos fit perfectly on the template I made , yes thats the magic of CAD( Computer Aided Design) .

 Now with the servos:

4. Attach the 90 degree servo mount to the servo using the 3/8" #4 screws . Now mount the servos using the 1/2" #4 screws. The screw should go through the plexiglass hole and into the hole of the servo mount.

5. Congrats the servos are mounted

6. Now mount the red servo horn that comes with each servo to a wheel. This can be done two ways. One way is to use hotglue to mount the servo horn to the wheel. Another method which is much cleaner is to use screws to fasten the horn to the wheel. Both methods are pictured below.

7. Now mount the wheel to the servo using the screw that came with the servo.

 

8. Once you've mounted both wheels on both servos you should have something that looks like this ,

 

 

 

6. Now its time to mount the casters . Assemble your casters using the instructions in the kit. Keep the screws left over , you should have something like this remaining when you are done.

 

 

7. Mount one of the casters using two of the screws that came with them into the plexiglass.

 

 

 

8. Repeat step seven for the other caster . There should be 2 screws and 2 nuts left over .Keep them since we will be using them later . You should now have a plexiglass base that looks like this :

 

 

 

3. Mounting the Batteries and Scanning Sonar Sensor

You will need the following parts:
1. 4 AA Battery Holder (BUY NOW)
2. Screws and nuts left over from the caster kit
3. Two 1/2" #8-32 screws and nuts (BUY NOW)
4. Two 1 1/2: #8-32 screws and nuts (BUY NOW)
4. One Servo Sensor Mount (BUY NOW)
5. Parallax PING Ultrasonic Sensor (BUY NOW)
6. HS-311 Servo (BUY NOW)
1. Take your battery holder and widen the mounting hole with a 1/8" bit.
2. Your battery holder should look like this :
3. Now mount the battery holder using the two screws and nuts left over from the casters.
4. Put nuts on the screws to fasten the battery holder to the plexiglass. Tighten the nuts with needlenose pliers.
5. Mount the Paralax PING ultrasonic sensor to the servo sensor mount and then mount the sensor mount to the servo.
6. Now take two 1 1/2" #8 -32 screws and put them in the corner of the servo as pictured.
7. Now mount the servo to the plexiglass with the screws. Tighten the screws with #8 nuts also.
8. Now your robot actually looks like a robot!!!
9. Just one more step to go . Mount the sensor mount using two 1/2" #8-32 screws and two #8 nuts.Tighten the nuts with pliers.

4. Making the Circuit

FOLLOW THESE INSTRUCTIONS AFTER FOLLOWING ALL THE OTHER INSTRUCTIONS FOR MAKING THE ROBOT ITTSELF. THIS IS THE STEP RIGHT BEFORE PROGRAMMING , and the third to last step in all.

Download the Schematic Here

 

 

 

To make the circuit you will need the following:

  1. One 400 Point Breadboard (BUY NOW)
  2. Five 10K ohm resistors ( Color Code: Brown- Black - Orange ) (BUY NOW)
  3. Six 220 ohm resistors ( Color Code: Red - Red - Brown) (BUY NOW)
  4. Two .1uF Ceramic Capacitors ( Code : 104) (BUY NOW)

5. One regular LED / any color you want (BUY NOW)

6. Two 100 K resistors (Brown - black - yellow) (BUY NOW)

 

 

STEP 1: Place the the PIC16F616 microcontroller in pins 1-7 as shown in the picture.

 


 

STEP 2: Connect a wire from a point on row 1 of the breadboard( left side) to a point on the positive voltage column. Connect a wire from row 1 of the breadboard ( right side) to a point on the negative voltage column.

 

 

STEP 3: Connect one leg of a 10K resistor to row 2(right side). Then take the other leg and connect it to a point on the positive voltage column.

STEP 4: Repeat step 3 for rows 3,4,5, and 6( on the right side of the breadboard). One leg of the resistor into its respective row and one leg into a point on the positive voltage column.

 


 

STEP 5: Now on the left side of the breadboard, connect a wire from a point on row 8(left side) to a point on the positive voltage column. Take another wire and connect it from a point on row 9(left side) to a point on the negative voltage column.

 


 

STEP 6: Take a wire and connect it from a point on row 10(left side) and connect the other end of the wire to a point on row 6(left side)

 


 

STEP 7: Grab a wire and connect it from a point on row 11(left side) to a point on the positive voltage column. Now on row 12(left side) take another wire and connect it from a point on row 12(left side) to a point on the negative voltage column.

 


 

STEP 8: On row 13(left side) connect a wire to a point on that row and connect the other end to a point on row 2(left side).

 

STEP 9: Connect a wire from a point on row 14(left side) to a point on the positive voltage column. Take another wire and connect it from a point on row 15(left side) to a point on the negative voltage column.

 

 

 

STEP 10: On row 18(left side) connect a to a point on the row and connect the other end of your wire to one leg of your switch. Now take the positive wire( the red one) from the battery holder( we installed before) and connect the end of that wire to a different point on row 18(left side). Connect another wire from a point on the positive voltage column to the other leg of the switch.

 


 

STEP 11: Take the negative wire ( the black one) of the battery holder and connect the end of it into a point on row 19(left side). Now take another wire and connect it from a point on row 19(left side) into a point on the negative voltage column.

 

 

STEP 12: Take a wire from the photoresistor and connect it point on row 24(left side).Now take another wire and connect it to a point on row 24(left side) to another point on the negative voltage column. Take the second wire of the photoresistor and connect it to a point on row 22(left side).

 

 

STEP 13: Connect a wire from row 22(left side) to a point on row 3(left side). Take a 200 K ohm resistor. Connect one leg of the resistor into row 3(left side) and connect the other leg into a point on the positive voltage column.

 

 


STEP 14: Connect one leg of a 220 ohm resistor( red-black-red) to a point on row 25(left side). Connect the other end to a point on the positive voltage column. Take the Left( blue tape) sensor's signnal wire and connect it to a point on row 25(left side). Connect the other wire from the Left sensor( the power wire) to a point on row 27(left side). Take a 220 ohm resistor and connect one leg to row 27(left side) and one leg to a point on the negative voltage column

 


 

STEP 15: Connect a wire to a point on row 25(left side) and connect the other end to a point on row 3(right side).

 


 

STEP 16: Connect the signal wire from the outermost right sensor(aka RRight , its covered with green tape) to a point on row 30(left side). Connect the power wire of RRight to a point on row 29(left side). Connect one leg of a 220 ohm resistor to row 29(left side) and the other leg to a point on the positive voltage column.

STEP 17: Connect a wire from row 30(left side) to a point on row 4(right side)

 


 

STEP 18: Connect the signal wire from the outermost left sensor(aka LLeft , its covered in yellow tape) to a point on the row 30 ( right side). Then connect the power wire from the LLeft sensor to a point on the row 29.(right side)

 


 

STEP 19: Take a 220 ohm resistor and connect one leg of the resistor into a point on row 29 ( right side) , connect the other leg of the resistor into a point on the positive voltage column.

 


 

STEP 20: Connect a wire from a point on row 30(right side) to a point on row 5(right side)

STEP 21: Find the black wire coming from the line following sensor mount. Connect that to a point on row 23(right side). Now take the signal wire from Center sensor( red tape) and connect it to a point on row 24(right side). Connect the the power wire for the Center sensor to a point on row 26(right side)

STEP 22: Take a 220 ohm resistor and connect one leg into a point on row 26(right side). Connect the other end of the resistor to a point on the positive voltage column. Now connect a wire from a point on row 24(right side) and connect the other end of that wire to a point on row 6(right side). Connect another wire from row 23(right side) and connect the other end of the wire to a point on the negative voltage column.

 

STEP 23: Connect the signal wire from the Right sensor(white tape) to a point on row 20(right side). Connect the power wire to a point on row 21(right side).

 


 

STEP 24: Take a 220 ohm resistor and connect one leg to a point on row 21(right side) and the other leg to a point on the positive voltage column. Connect a wire from a point on row 20(right side) to a point on row 2(right side).

 


 

STEP 25: Find the two wires that are connected to the LED that is mounted next to the resistor. Connect one wire of the LED to a point on the negative voltage column and one wire to row 15(right side). Take a 220 ohm resistor and connect one leg to row 15(right side) and connect the other leg to a point on the positive voltage column.

 


 

STEP 26: Connect the servos and the sonar sensor as shown in the drawing. On the left side row 7(left side) should get one of the drive motor's signal wire( the yellow one) row 8 and 9 get that servo's positive and negative wires. Row 10(left side) gets the other drive motor's signal wire, and row 11,12 are for that servo's positive and negative wires. Row 13(left side) recieves the scannign servo's signal wire and row 14,15 get that servo's positive and negative wires. Row 7(right side) gets the sonar's signal wire and row 8,9 get the sonars positive and negative wires

 


 

STEP 27: Take the positive lead of a status LED and connect it to a point on row 5(left side) . Connect the negative lead of that same LED to a point on the negative voltage column.

 


 

STEP 28: Connect a wire from the left negative voltage column to the right negative voltage column. Connect another wire from the right positive voltage column to the left positive voltage column.

 

 

ALL DONE!

 

 

 

 

5.Installing and Setting Up the Programming Software and Hardware

After finishing the chassis and circuit, we now have to give the darn thing its "brain".

 

I used PICBASIC PRO to make the program , but PICBASIC generates an assembly file as well.I will post that assembly code up also. If you know assembly language and do not need PICBASIC, all you need is the programmer. If you don't know assembly then just use PICBASIC PRO.

Now the first thing we need is a microcontroller . We will use the PIC16F616 PDIP microcontroller. PIC is the brand( which is manufactured by Microchip), 16F616 is the part number , and PDIP is the package type. PDIP means it will look like this .

 

The microcontroller holds the program , which is a list of instructions for the robot . The language that I will use in this tutorial is a language known as PICBASIC PRO. Here is some sample code to blink an LED.

loop:   High 0          ' Turn on LED connected to PORTB.0
Pause 500 ' Delay for .5 seconds

Low 0 ' Turn off LED connected to PORTB.0
Pause 500 ' Delay for .5 seconds

Goto loop ' Go back to loop and blink LED forever
End

 

The compiler software transfers the basic code into assembly code and then into robot code( called hexadecimal code) . Assembly code of that same program would be over a page long of almost incomprehensible MOVLW , MOVWF , EQU , $128 , and other various commands. From the assembly code , hexadecimal code(the robot code) is created, which is TOTALLY incomprehensible. Here it is , in case you are curious:

0000- 2828 01a3 00a2 30ff 07a2 1c03 07a3 1c03
0008- 2823 3003 00a1 30df 200f 2803 01a1 3ee8
0010- 00a0 09a1 30fc 1c03 2818 07a0 1803 2815
0018- 07a0 0064 0fa1 2815 1820 281e 1ca0 2822
0020- 0000 2822 0008 1383 1303 1283 0064 0008
0028- 1405 1683 1005 1283 3001 00a3 30f4 2002
0030- 1005 1683 1005 1283 3001 00a3 30f4 2002
0038- 2828 0063 2839

 

 

 

 

The compiler costs $250 dollars retail, but there sometimes are cheaper versions online -- however, those versions are pirated copies , and any free torrent downloads of PICBASIC PRO are also illegal copies . Buy the retail version from here

 

The following instructions are for installing and setting up MicroCode Studio with PICBASIC PRO and the U2 Programmer. I was surprised not to find any instructions to do this online, so I went ahead and wrote my own. Enjoy!

 

Now once you have the compiler , you need hardware that can download the robot code onto the microcontroller from the computer. There are many options available for this piece of hardware.

I recommend this U2 Programmer since it can program almost any PIC micro out there

There are other USB programmers out there , as well as Serial Port Programmers for cheaper.

 

OR you can buy the code preprogrammed on your chip from Microchip Direct . However, if you go with this option , you will not be able to edit or debug the code . If you do this then skip all of the steps below.

 

For the next steps you should have a microcontroller, the PICBASIC PRO compiler ,and a programmer hardware.

Lets begin:

Install the software that came with the programmer

Follow the instructions provided with PICBASIC PRO to put PICBASIC PRO software on your computer

Download and Install MicroCode Studio - a free program to edit BASIC code

Download and Install MPASM Assembly Compiler

 

Now open up MicroCode Studio. Click View in the toolbar and then select Compiler and Editor Options.

A pop up box should appear . Make sure the "Compiler" tab is selected and then click the button titled "Find Automatically". It should start searching your computer for the PIC BASIC PRO compiler.

 

 

After it has found it , select the tab titled "Assembler ". Click the "Find Automatically" button and wait till it has found the MPASM assembler software.

Now select the Programmer tab .

Click the "Edit" button. A box should pop up. Type in the program name of your programmer software. For the U2 USB programmer it is "meprog.exe" .

Click Next. Now click "Find Automatically" and wait until it finds the software for the programmer.

After it has finished finding the programmer software , click "Next". Then click "Finished".

 

All done with the options for MicroCode Studio !

 

Now open up the programmer software in C:/Program Files/meLabs Programmer. Click meprog.exe

Now click the Options tag and make sure only the options in the photo are checked. Uncheck the other options

Click the View tab and then click Configuration from the drop down list.

Change the configuration setting to match the settings in the picture.

Exit out of the programmer . You have finished setting up all the software and hardware!!!

 

 

 

 

 

 

 

 

 

 

6. Uploading the Program to the Microcontroller

 

There are four variations to the program I have made.

Program #1: The first one is for the robot to follow smooth turns , sharp turns, and breaks in the line.

Program #2: The second one can handle victim finding, smooth turns, sharp turns, and breaks in the line.

Program #3:The third one can handle all the ones program #2 can handle with the addition of obstacle avoidance

Program #4:The fourth one is only obstacle avoiding.

 

The other final code does everything together - victims, line following, and obstacle avoiding.

 

 

NOTE: All the programs output display data to an LCD , but it is not necessary to connect an LCD, the program will run perfectly without it.

 

I have attached the BASIC code , the Assembly Language Code , and the hex file code for each program.

 

The only thing you would need to change in any of the programs is the following code.


Forward1 con 200
Forward2 con 100
Backward2 con 200
Backward1 con 100


If you modified the servos perfectly then leave the above code alone. If the servos are not turning right , play around with the above numbers until you get the desired motor movement. The numbers should be more than 99 but less than 201. Do not give it more than that

 

Also, if you can set the threshold value for the sensors. Once a sensor has a value more than LineColor it is considered to be seeing black. So also play around with that value until its the best it can be.
LineColor con 47000 ' the threshold value for a line being detected is 150

 

 

Now to upload the code to the microcontroller you do the following.

 

1. Put the PIC16F616 into the U2 programmer socket. Plug in the programmer. The green LED should be on.

2. Go to the folder where meprog.exe is located and double click it or instead of this open up the .pbp file in MicroCode Studio and Press F10, this should open up meprog.exe as well as compile the program.

3. Meprog.exe should now be opened up. Make sure that the device selected is the PIC16F616

4. Now click File and then click Open.

5. Find the hex file of the program and open it. For example, in the photo below I was uploading Program #2.

6. Now press Ctrl and P at the same time. This will begin uploading the code. A small window should pop up and now just let it run .

 

7. Once it says Finished , you are done and you can put the microcontroller in the robot and take it out of the programmer.

 

 

 

 

7. Troubleshooting

This is the troubleshooting page , where I basically think of everything that can go wrong and post solutions for it. If you have a problem which cannot be solved by this page , go ahead and post it in the forum.

 

Servos not turning the right way - your servos are not connected or they are not getting the right pulses, so play around with the pulses.

Sensor not working- Take a digital camera and look through it. Make sure that each of the IR sensors is giving off blue light( visible to the camera, not to humans)Or its a bad connection, or its the pull up resistor . Make sure its all connected and the resistor is the right value

LED not turning on- try flipping the wires of the LED , or maybe its just burned out and then just replace it.

Sensors giving bad readings- If you are in sunlight the sensors will give bad readings, so maybe cover the robot with duct tape. Or check your circuit for mistakes.

Batteries heating up - The positive and negative voltage wires somewhere in the circuit are touching

I see smoke- Batteries' wires are touching . I really don't think smoke will happen , but you never know.

Nothing is working or turning on- The batteries are not connected, or they are too weak.

 

 

ERROR MESSAGES

 

1. No programmer found ---- Your programmer is not connected , plug it in!

2. No device found ----- Either your microcontroller isn't in the programmer socket properly or you selected the wrong device. Select PIC16F616.

8. Videos

Some videos of the 3 in 1 robot

 

Shake Test

 

 

Basic Line Following

 

 

Following Sharp Lines

 

 

Meaneuvering a Break in the Line

 

Identifying Tape Victims

 

Basic Object Avoidance