Transcript
Page 1: P5 LDR Line Following Robot

Project 5: LDR Line Following Robot

Design a Line Following Robot using a Light Dependant Resistor (LDR)

Learning Outcome

This project gives the user a hands-on experience on how to use ezCircuit Designer (ezCD), CoreChart and the eLab16m to design, build, document and program a “Line Following Robot”.

The aim is to encourage the user to design other PIC microcontroller electronic projects.

A typical example: a team of Secondary students used ezCircuit Designer (ezCD), CoreChart and eLab16m to design, build, document and program a touch pad device for autistic children to communicate through an i-pod.

Equipment for workshop

Computer

PC running Windows 2000 SP4 or higher with USB connections

Software

Microsoft .NET Framework V2 ( Required to run ezCircuit Designer ) ezCircuit Designer CoreChart Microsoft Word

Hardware

eLab16m Controller Board eLabtronics USBP Programmer with USB Cable

LDR Line Following Robot Parts and Tools

Small flat head screwdriver eRacer Mechanical Base with 4x AA Alkaline Batteries

( eRacer robot Base Assembly instructions are available in the ezCD CD) Pre-built: LDR light sensor circuit for the eLab16m board Soldering Iron and solder for construction if required

Project 5: LDR Line Following Robot1

Page 2: P5 LDR Line Following Robot

figure 2.1

Line Following RobotBuilding a robot is no longer rocket science. With only one LDR (Light Dependant Resistor) and two motors, a simple robot can be built to follow a line.

Step 1: Select eLab16m Template

The Line Following Robot is developed using the eLab16m board. The PIC16F819 chip on the board will be programmed by the user to form the brain of the robot.

a. Start up “ezCircuit Designer”. If a different project is displayed click on the following drop down menu to find eLab16m template: “File”, “Open”, “ezCircuit”, “Examples” and “eLab16m”. The “eLab16m” template should look like figure 1.1

Step 2: Create Documents

a. In the main menu, click on “Documentation”, “Create Document” and select “Specification”.

Project 5: LDR Line Following Robot2

figure 1.1

Page 3: P5 LDR Line Following Robot

b. Fill in “Introduction”, “Functional Requirement” and “Requirements Specification Rationale” as follows:

Introduction: The aim of this project is to build a line/light following robot.Functional Requirement: The Line Following Robot uses a light sensor to detect the colors of the line and two motors to move the robot along the line. The Robot needs to be powered from the Robot base and not an external battery pack.Requirements Specification Rationale: Learn to build and program a Line Following Robot with the eLab16m board, a light sensor and two DC motors.

NOTE: Please save the program regularly.

Step 3: Add Light Dependant Resistor (LDR)

a. Select the “Light Dependant Resistor (LDR)” icon in the “Circuit Groups”. b. Ensure “Active High” in “Circuit Typess” sub-menu is selected and then click on pin

17 (A0) of the chip diagram.c. Right click “LDR17” box and click Rename. Change “LDR17” to “LightSensor”.

Project 5: LDR Line Following Robot3

figure 3.1

Page 4: P5 LDR Line Following Robot

The LDR Circuit Diagram is available from ezCircuit Designer. To view the circuit diagram right click on the newly named “LightSensor” box. Then click on “View Circuit Diagram”.

NOTE: This is an Active High Circuit.

It is important to get familiar with the concept of Active High and Active Low circuits.

To return from the circuit diagram to the main screen, go to the top right corner and click the drop menu to find “Main” to return to the main page.

Alternatively click the “backward” arrow to return to the main page.

Project 5: LDR Line Following Robot4

figure 3.3

figure 3.2

Page 5: P5 LDR Line Following Robot

Step 4: Rename Motors

In the template the “Motor Drivers” are connected to pin 10, 11, 15 & 16.

a. Rename the Motor Drivers” as shown in Table 1 and figure 4.1. This will make programming easier to follow.

Pin to Change Renamed toDriver_B (B4) Motor1ForwardDriver_D (A6) Motor2Forward

The Line Following Robot design is now complete.

b. Go to the ezCircuit Designer “File” menu and click “Save as…”. Save the template name as “LineFollower”.

c. Generate CoreChart test program to test the hardware. Click on “Options” and then click “Send to CoreChart”.Alternatively click on the CoreChart icon in the ezCircuit Designer menu bar.

Project 5: LDR Line Following Robot5

Table 1: Rename Motor Driver Pins

figure 4.1

figure 4.2

Page 6: P5 LDR Line Following Robot

Step 5: Hardware Connection

Note: This project uses the battery power source from the robot base, not the battery pack that comes with the eLab16m.

a. Plug the white 3 pin power connector that comes from the robot base into the white socket labeled “BAT” on the eLab16m.

b. Plug in the two 2 pin motor connectors as shown in figure 5.1.c. Note that the first column of “header” pins next to the “labels” are connected to the

“negative rail”, the middle column of pins are connected to the “positive rail” and the inner most column of pins are the “signal” pins as shown in the “KEY”.

Connect the Light Dependant Resistor (LDR) sensor as shown below. Use heat-shrink to cover the edges of the LDR to vary the sensitivity of the LDR. The LDR Circuit Diagram is available from ezCircuit Designer. Right click on the LDR box connected to the PIC chip, then click on “View Circuit Diagram”. To return to the Main page, click on the “Backward” arrow on the top right corner.

Project 5: LDR Line Following Robot6

figure 5.1

KEY

Motor1 = Black A6 + Red B5Motor2 = Black B4 + Red A7

figure 5.2

Page 7: P5 LDR Line Following Robot

Step 6: Test Hardware with CoreChart test program

The CoreChart test program should look like figure 6.1.

a. Save the CoreChart test program as “LineFollower”.

b. Plug in the USB cable to the computer. Connect the USBP programmer to the eLab16m. Turn on the eLab16m power. Send the CoreChart test program to the chip.

The test program will test all the outputs on the project.

c. When the program is successfully downloaded to the chip, unplug the USBP programmer from the eLab16m.

d. Press and release the reset push button switch on the eLab16m to start the program.

e. One of the motors will spin clockwise for few seconds and the other will spin in a counter clockwise direction.

f. The Yellow LED will flash once.

Project 5: LDR Line Following Robot7

figure 6.1

Page 8: P5 LDR Line Following Robot

Step 7: Modify program to test the Light sensor

a. Delete icon 3 and icon 4 in the test program shown on figure 6.1.

b. Insert the “Again” LABEL icon 3.

c. The program does not allow icon 4, a “Decision” icon, to be inserted just before the “END MAIN” icon because this will create a logical error.

Reason: If the “Decision” is a “YES” before “END MAIN” icon then the program will stop. If the “Decision” is a “NO” then the program will point past “END MAIN” which causes a program error. Please refer to NOTE: Use of “Decision” icons below for further details.

d. The correct CoreChart programming procedure is to insert icon 5 first and then insert the “Decision” icon 4.

e. Save the program and send to chip.

f. Before running the program, ensure the LDR sensor is correctly connected to the eLab16m. (As shown in Step 5, figure 5.2)

g. Switch on the power on eLab16m and press the reset push button once to start the program.

h. Direct the sensor towards a light source and then cover the sensor. Check the response of the Yellow LED. It should turn on and off with the changes of light intensity.

Project 5: LDR Line Following Robot8

figure 7.1

Page 9: P5 LDR Line Following Robot

NOTE: Use of “Decision” icons

A “Decision” icon CANNOT be placed before a “LABEL” icon e.g. the “Again” icon. It must be placed BEFORE an “instruction” icon.

REASON:The reason is that if the “Decision” is a “YES” before a “LABEL” icon the program will skip the “LABEL” because it is NOT an instruction. If the “Decision” is a “NO” then the program will also skip to the icon after the “LABEL”. This is a logical error because the “Decision” cannot make a decision.

CoreChart also does not allow two “Decision” icons to be placed one after the other because this will create a logical error between YES or NO decisions in the two “Decision” icons.

Step 8: Add Subroutines

Add in subroutines “RIGHT” and “LEFT”.a. Click on the Edit drop menu and click on “Subroutines…”b. Type “LEFT” in the text entry box then click on “Add Subroutine”c. Repeat this for “RIGHT” subroutine.d. Click “Close” when finished

Project 5: LDR Line Following Robot9

figure 8.1

Page 10: P5 LDR Line Following Robot

Step 9: Build Line Following Program

Edit the Main Program to as follows.

a. Replace the “YellowLED” icons with the new subroutines as in figure 9.1 and save program.

The robot travels along a line or the edge of a piece of paper by the following process:The robot moves right when the LightSensor is OFF and moves left when the LightSensor is ON.

Project 5: LDR Line Following Robot10

figure 9.1

Page 11: P5 LDR Line Following Robot

STEP 10: Build the Subroutines

a. Double click on the subroutine “LEFT” and add icons as shown in figure 10.1.b. Repeat for subroutine “RIGHT” and add icons as shown in figure 10.1.

The “LEFT” subroutine makes the robot turn left and the “RIGHT” subroutine makes the robot turn right.

The “LDR Line Following Robot” program is now complete.

c. Save the program as “Linefollower_ROBOT” and then send to chip.

d. Press the reset push button switch on the eLab16m board to start the program.

e. Take a piece of white paper and place it on a dark surface. Then place the robot on the edge of the paper. Finally, position the light sensor to face the floor. The robot follows the “line” or the edge of the paper.

END OF Project 5: LDR Line Following Robot

Project 5: LDR Line Following Robot11

SUBROUTINE “LEFT” SUBROUTINE “RIGHT”

figure 10.1


Top Related