Your SlideShare is downloading. ×
Report - Light Sensing Robot
Report - Light Sensing Robot
Report - Light Sensing Robot
Report - Light Sensing Robot
Report - Light Sensing Robot
Report - Light Sensing Robot
Report - Light Sensing Robot
Report - Light Sensing Robot
Report - Light Sensing Robot
Report - Light Sensing Robot
Report - Light Sensing Robot
Report - Light Sensing Robot
Report - Light Sensing Robot
Report - Light Sensing Robot
Report - Light Sensing Robot
Report - Light Sensing Robot
Report - Light Sensing Robot
Report - Light Sensing Robot
Report - Light Sensing Robot
Report - Light Sensing Robot
Report - Light Sensing Robot
Report - Light Sensing Robot
Report - Light Sensing Robot
Report - Light Sensing Robot
Report - Light Sensing Robot
Report - Light Sensing Robot
Report - Light Sensing Robot
Report - Light Sensing Robot
Report - Light Sensing Robot
Report - Light Sensing Robot
Report - Light Sensing Robot
Report - Light Sensing Robot
Report - Light Sensing Robot
Report - Light Sensing Robot
Report - Light Sensing Robot
Report - Light Sensing Robot
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Report - Light Sensing Robot

7,989

Published on

Report for light sensing robot

Report for light sensing robot

0 Comments
8 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
7,989
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
0
Comments
0
Likes
8
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. 4/2/2012 Assignment - 2202CDE EMBD. MICROPROCESSORS GROUP PROJECT Group NTP Divay Khatri – 4073084 Aleksandr Fedunov – 3238989 Cagdas Degirmenci – 3052983 Salem Bazeedan – 3522590To design a robotic vehicle using a PIC18F4520 microcontroller board, stepper motors, DarlingtonDriver, photo reflective optical sensor, light dependent resistor and switches. The task is to design aLight Sensing Robot using all the above stuff and to make it search for light within an enclosed areawith the boundary as the black tape and stop at a distance of 15cm from the light source and twoswitches which help to re-negotiates the path once collided with the obstacle.
  • 2. INDEX Contents Page No. Who did what? 2 Introduction 3–5 Design Process - Hardware Design 6–8 - Software Design 9 – 15 Implementation 16 – 19 - Code 20 – 25 - PCB 26 – 30 Components used 31 Test Methodology 32 – 34 Conclusion 35 References 36 Who did what?Divay KhatriThe whole software thing + helped with the hardware part + helped with PCBdesign + report from design process till the endAleksandr FedunovHelped with the hardware part + Introduction and conclusion for the reportCagdas DegirmenciHelped with the hardware part + helped with PCB designSalem BazeedanHelped with the hardware part And in the start of the assignment we discussed the logic about how to do this together. 2|P a ge
  • 3. Introduction:What is a robotic vehicle?The field of robotics encompasses a broad spectrum of technologies in which computationalintelligence is embedded in physical machines, creating systems with capabilities farexceeding the core components alone. Such robotic systems are then able to carry out tasksthat are unachievable by conventional machines, or even by humans working withconventional tools. The ability of a machine to move by itself, that is, “autonomously,” isone such capability that opens up an enormous range of applications that are uniquelysuited to robotic systems.To be useful in real world, robots need to move safely in unstructured environments and achievetheir given goals despite unexpected changes in their surroundings. The environments of real robotsare rarely predictable or perfectly unknown so it does not make sense to make precise plans beforemoving. This report will describe how we designed and built a light sensing robot.The task is to build a light sensing robot using two LDR’s to sense the light and accordinglymove the wheels, one opto sensor to remain within the boundary, two switches to changethe direction of the robot when gets collided with an obstacle, all this on a PIC18F4520microcontroller board, and a Darlington driver to control the locomotion aspect of thevehicle.Our first step was to understand how the robot should work and what things it needs toperform. If the sensors (LDR) sense bright light, i.e. approximately a distance of 15cm away from the robot, then the robot must stop. If the sensors sense extra light than the normal light, then the sensor which is having some extra light, the vehicle should move in that direction. If both the sensors sense the same amount of extra light then the vehicle should move in the forward direction. If the opto reflective sensors value is 0 then do all of the above steps else if it is 1 that means the robot is over the boundary, the black line. So it should move backwards and then turn to a direction and then again should start searching for extra light. If the switches gets pressed, that means the robot has collided with something (an obstacle) and it needs to change its way. When a switch gets pressed, the interrupt comes in.Let’s get into the detail of these steps,The robot should move within an enclosed black taped area which robot must sense viaphoto reflective optical sensor. The main task is that robot should search for a light sourceby using LDR’s (Light Dependant Resistors) and when it collides with an obstacle with the 3|P a ge
  • 4. lever switchers(bumpers) it should re-negotiate its path towards the light source. Afterrobot reaches the light source it should stop at a small distance from it.We were given four weeks to complete this project for from both hardware and softwareaspects. This was not that tough task as we have successfully completed our firstassignment – Line following robot few months ago. Some things were similar, some piece ofthe code was similar and we had to attach the sensors to the same vehicle platform.But there was a difference this time, logically if a vehicle has to move then one wheel shouldrotate in the clockwise direction and the other in the anti-clockwise direction to make thevehicle move but in actual both the wheel should move in the same direction (the forwarddirection to move forward and vice-versa).The thing which was changed for us was the polarity of the stepper motors we were usingwhere we had to set the locomotion aspect of the wheels with both motors moving in theclockwise direction.Below we will discuss about the general idea as on the set-up with the stepper motors.Our objective for the first week was to find a voltage values for LDR’s (how it reflects thelight) and resistor values for the LDR’s, Optical sensor and Lever switchers. To calculatevalues of the resistors we used data sheets of each component (sensor). Calculations aregiven in the main body, after the calculations we started attaching the sensors and theswitches one by one to the breadboard and with the development board, the LDR’s usinganalogue to digital channel 0 and channel 1 to PORTA bit 0 and 1 assigned the decimalvalues to the code where it should follow the light source and stop at some distance from it(using 8 bits) and then tested it along with a stepper motors. The confirmation was that theLDR’s reacted well to the light and the stepper motors moved accordingly. The first weekwas over.On the second week our objective was to achieve the task with the interrupts by using leverswitchers. The resistor values for this were found in the schematic given. We already knewfrom the lectures that we must use 2 interrupts, one low priority and the other high priority.The high interrupt have a privilege mode. For example if a low interrupt is currently doingthe instruction, a high interrupt can easily interrupt the low interrupt but the vice-versa isnot true. We completed this objective for the week and made the interrupts work. Whenone of the bumpers is pressed then the stepper motors do some steps, it moves in thebackward direction, turn to either left or right and then move forward searching the light.Attaching the opto sensor was the last step so for the third week we arranged everythingtogether including the opto sensor and compiled the code. Everything worked fine but wecouldn’t stop the wheels at 15cm distance from the light source.After we saw it working, we recorded the video of the set-up which can be found below. 4|P a ge
  • 5. Then the fourth week we started connecting components on the robotic vehicle and make it move, the objective for the last week of the project. The video below can demonstrate how it works on the vehicle and can prove that the entire task was done successfully. What we were done so far is:  Stepper motors works with the LDR’s  Optical reflective sensor can avoid the black line  The lever switchers works perfectly fine as the interrupts and can perform the tasks to re-negotiate the obstacle  The LDR’s make the stepper motors move to follow the light and stops them at a given range The idea is to make the robotic vehicle within an enclosed black taped area and follow the light source. When it reaches the obstacle it must perform steps to re-negotiate it/avoid it and then again should follow the light source. If it reaches the black tape or the boundary it should change the direction.We made two videos showing the working of the light sensing robot: Set-up of the hardware (an in working with the individual parts) http://www.youtube.com/watch?v=6825V6opX7Q The moving robotic vehicle http://www.youtube.com/watch?v=qKiPZ4BL_vA 5|P a ge
  • 6. Design Process:Below is the diagram that shows the set-up of the hardware, with all the sensors, theirrespective resistors, the switches, PIC development board and the stepper motors. Or wecan say the circuit diagram. 6|P a ge
  • 7. To understand more about this let us have a look at the UML diagram for the hardwaredesign. UML activity diagram for Hardware Design 7|P a ge
  • 8. This is the general idea from hardware point of view about what is happening. Now let ushave a look at how to make the robot move in forward and backward direction. Fromprevious classes we figured out that for a full step sequence in a clockwise direction, thevalues for the steps should be: STEP 1 0x09 STEP 2 0x05 STEP 3 0x06 STEP 4 0x0AAnd thus for the full step sequence in an anticlockwise direction, the values for the stepsshould be reversed: STEP 1 0x0A STEP 2 0x06 STEP 3 0x05 STEP 4 0x09This sequence applies only for one stepper motor but if we have to make two steppermotors move simultaneously then the stepping sequence will be: 1. Make both the motors move in clockwise direction: STEP 1 0x99 STEP 2 0x55 STEP 3 0x66 STEP 4 0xAA 2. Make both the motors move in anti-clockwise direction: STEP 1 0xAA STEP 2 0x66 STEP 3 0x55 STEP 4 0x99 3. Make one motor in anti-clockwise direction and the other in clockwise direction STEP 1 0xA9 STEP 2 0x65 STEP 3 0x56 STEP 4 0x9A 8|P a ge
  • 9. This was the general idea of how to make the motors move. In our Project we have connected 4-7 bits of PORTD with Motor 2 and 0-3 bits of PORTD with Motor 1. Now let us have a look at the software design. Software design: After making the connections according to the circuit as shown above, MPLAB was launched and a new project was created so as to program the PIC18f4520 through the ICD 3. We started programming the PIC in C language. 1. a. First we configured the operational parameters of the PIC by setting OSC mode to HS high speed clock. b. Then the watchdog timer was set to OFF. c. Low Voltage Programming was also set to OFF. d. And a state to compile without extra Debug compile code was set. 2. Header files (Include files) were included in the program a. #include <p18f4520.h> - device used is the PICF4520 b. #include <delays.h> - to include the delay routines c. #include <adc.h> - to include the files used in the analogue to digital conversion d. #include <stdio.h> - this describes the interface to the library which contains basic I/O functions e. #include <portb.h> - to set port b for interrupts and use the default registers defined in it 3. The stepping sequence was figured out in the previous classes and according to that stepping sequence where the stepper motors did a clockwise and anti-clockwise turn; the steps were assigned hexadecimal values. We know that 0x00 For the 0-3 bits of the PORTUsed to represent hexadecimalvalues For the 4-7 bits of the PORT 9|P a ge
  • 10. Thus to make a robotic vehicle move in the forward direction, we need to make one motormove in anti-clockwise direction (i.e. Motor 1) and the other motor in clockwise direction(i.e. Motor 2) and we have to make changes in the directions of both the motors accordingto the response from the photo reflective optical sensors, light dependent resistors and theswitches.But the robotic vehicle we were working on was having a different setting in the motor andthus we had to set both the wheel in clockwise direction in order to make the robot run.Practically, both the motors should move in the forward direction but logically both in theopposite directions but with our robotic vehicle the case was different and thus the steppingsequence in the end was changed.We have assigned appropriate hexadecimal values to the steps and they are: (you will see incomparison)When done on stepper motors (left side) and when done on the robotic vehicle (right side) STEP 1 0xA9 STEP 1 0x99 STEP 2 0x65 STEP 2 0x55 STEP 3 0x56 STEP 3 0x66 STEP 4 0x9A STEP 4 0xAA STEP 5 0xA0 STEP 5 0x90 STEP 6 0x60 STEP 6 0x50 STEP 7 0x50 STEP 7 0x60 STEP 8 0x90 STEP 8 0xA0 STEP 9 0x09 STEP 9 0x09 STEP 10 0x05 STEP 10 0x05 STEP 11 0x06 STEP 11 0x06 STEP 12 0x0A STEP 12 0x0A STEP 13 0x9A STEP 13 0xAA STEP 14 0x56 STEP 14 0x66 STEP 15 0x65 STEP 15 0x55 STEP 16 0xA9 STEP 16 0x994. Then we declared the interrupts according to the low and high priority and used the GOTO command to go to their respective definitions.5. Then we initialized all the bits (0-7) of PORTD for outputs and all 7th bit of Port C for the input from opto sensor, 0 and 1st port bit of Port B for interrupts and 0 and 1st bit of Port 10 | P a g e
  • 11. A for inputs from both LDR’s. Also included a while loop (with while = 1) such that the code can run forever.6. Then we included the code for the Analogue to Digital conversion twice, once for channel 0 and next for channel 1 and transferred that converted digital value to the respective LDR.7. Now we compared the value of LED1, if 0 then proceed normally, else if 1 then go to the else part.8. If LED1 =0, starts the basic logic to control the locomotion aspect of the vehicle which uses the ADC converted value to steer the robot. There are 5 conditions which can be included a. If LDR1 > LDR2 Then stop left stepper motor and move the right stepper motor in forward direction in order to move the robot to the left. b. If LDR2 > LDR1 Then stop right stepper motor and move the left stepper motor in forward direction in order to move the robot to the left. c. If LDR1 == LDR2 This situation occurs rarely; in this both the wheels move in the forward direction. d. If LDR1 and LDR2 are less than 245 (the voltage value of LDR at a distance of approx 15cm) then the robot should stop e. Another case can be if LDR1 and LDR2 both values are falling below a certain range which means there is no extra light and in that case the robot can rotate left or right by remaining at the same position. But we have not included this in the code as it was simply to follow the light source and stop9. If LED1 = 1, starts the else part which is just a condition to move the robot backwards and turn to a direction. This case happens when the robot is over the black line and thus according to the code it can’t cross the black tape which acts as the boundary.10. Then there are two switches in the hardware design which are bumpers, when the robot collides the switch gets pressed and acts as an interrupt and accordingly the interrupt function works. If switch 1 gets activated then the robot moves backwards, turn to right and move forward for some steps and then again starts following the light as it gets back into the main program. Similar happens when switch 2 gets activated. 11 | P a g e
  • 12. For the opto sensors and the light dependent resistors we need to find their resistor valuesusing the data sheets from the manufacture of those sensors thus the calculations are givenbelow:For opto sensor: RD = RL = RD = RL =For LDR’s: RD = 82.5 Ω RL = 25 GΩ 12 | P a g e
  • 13. Voltage Out – 320 V (maximum) Current – 75 mA (maximum) 1000 LUX - 400Ω 10 LUX - 9 kΩ VOUT = = = Rx =This was a general calculation.But the output never goes to complete 5V or to complete 0V; therefore using Vout as 4.3volts and 0.7 volts the values of Rx comes out to be 2.457 KΩ and 1.465 KΩ.But as advised we had to use the values that we used during the normal exercises.The above software design and interrupt routine steps are presented throughthe UML activity diagrams, please see below. 13 | P a g e
  • 14. UML activity diagram for Software Design 14 | P a g e
  • 15. UML activity diagram for the Interrupt sequence 15 | P a g e
  • 16. Implementation of the designImplementation of the design wasn’t challenging as we have already completed assignment1 and the exercises we have carried out since the start of the module. As we knew about theprevious components, the opto sensors, the LDRs there was just the interrupts which wasnew to us. But that was also done easily.Setting up the connection and understanding how the circuit worked was quiet easy. Whenwe came across a problem; such as unresponsive equipment, it did not take us long to figureout what the problem was because we were familiar with the equipment. Having theseadvantages we quickly set-up the circuit. We have explained below the circuit step by stepand explained further the reason of these connections.The schematic was given to us and we had to arrange the circuit in the same manner. 16 | P a g e
  • 17. This is the set-up of the hardware with individual components.About the hardware set up: a) Firstly we connected the PIC I/O board and the PIC development board with a 10-pin ribbon cable. This connection was made from the PIC I/O board to Port D on the development board. Using this connection we were able to cross-over 8-bit of information. b) Then with an 8-way connected wire, we have connected I/O board with the microcontroller’s input. c) The output of the microcontroller is then connected to the stepper motors. 0-3 bits to one of the stepper motor and 4-7 bits into the other stepper motor. d) After completing the main connections, we moved on to power supply connections where 5V were connected to most of the boards and 12V was only connected to the stepper motors. e) We then connected the optical sensor, the LDR, and the switches with their respective resistors to the bread board which was already powered by 5V. 17 | P a g e
  • 18. f) We then connected the output of these sensors to the respective ports in the PIC microcontroller board. g) Finally with an RJ11 cable, we connected the PIC board to MBLAB ICD3 (programmer and debugger) device. h) Then connected the 4 white LED light source with +5v and GND and started checking whether the hardware responds accordingly or not.While connecting the circuit we did encounter simple problems. They are seen simplebecause we easily found solutions to them. For example when we were planning on how tostop the robotic vehicle when closer to the light source, we come across logical difficulties.We were first trying to use a 10 bit adc channel and the values with that were coming in therange of greater than 800 for the voltage output of LDR but we resolved this by using a 8 bitwhich returned a voltage output of 245 (at a distance we needed).The table below shows different voltage output values at different sensitivities of the light. Light Sensitivity LDR1 LDR2 Normal Light 224 volts 221 volts Bright Light 246 volts 245 volts Medium bright Light 244 volts 244 voltsThe ‘brain` of the circuit is the PIC18F4520 and it has been programmed with a C languagecode which we have written and it works according to our preferences.Firstly we have connected the Darlington board with the Port D on the PIC. The port D onthe PIC is an output interface and we use this output to control the stepper motors. The pins0-3 are programmed to use the LDR1 corresponding to motor 1 and the pins 4-7 areprogrammed to use the LDR2 corresponding to motor2. The pins 9 and 10 are for groundconnections. A 5V power supply was connected to the PIC Board. The other end of theDarlington driver is used to connect the Stepping motors on the robotic vehicle. The wirescoming out windings of the stepping motors had to be individually connected on theDarlington board. The wires have to be connected in the pattern of White, White, Blue,Blue, then White, White and Blue, Blue. The Darlington driver was powered with 12Volts.The stepping motors surely needed power to run so we also connected the two with 12Voltsthrough +Vmotor connection. The next connection we made was connecting the two LDR’s,the two switches and one optical reflective sensor to the PIC board. We configured ourprogram in such way that each sensor was assigned to a stepping motor. In simplicity eachsensor acted as an eye for the motor it was assigned to. The connection of the hardwarecomponents is still the same as defined in the design section. 18 | P a g e
  • 19. LDR Opto sensorThe Opto Sensor output goes to Port C bit 7 acts as the input where it detects a black line;LDR1 and LDR2 through an ADC bit 0 and 1 of Port A and the Lever Switches to Port B 0 and1. These inputs are configured in the program so the motors act on these values.Then we programmed the PIC microcontroller through ICD3. Thecode is given below: 19 | P a g e
  • 20. The program code in ‘C’ for the Light Sensing Robot/* Group Ntp - Light Sensing RobotDivay Khatri - 4073084Aleksandr Fedunov - 3238989Cagdas Degirmenci - 3052983Salem Bazeedan - 3522590*/// configure operational parameters of the PIC#pragma config OSC = HS#pragma config WDT = OFF#pragma config MCLRE = ON#pragma config DEBUG = OFF#pragma config LVP = OFF// header files#include<p18f4520.h>#include<delays.h>#include<portb.h>#include<stdio.h>#include<adc.h>#define LED1 PORTCbits.RC7// define PORTC bit 7 for output from opto sensor// Stepping Sequence - according to the robotic vehicle// move forwardunsigned char STEP1 = 0x99;unsigned char STEP2 = 0x55;unsigned char STEP3 = 0x66;unsigned char STEP4 = 0xAA;// stop left and move rightunsigned char STEP5 = 0x90;unsigned char STEP6 = 0x50;unsigned char STEP7 = 0x60;unsigned char STEP8 = 0xA0;// stop right and move leftunsigned char STEP9 = 0x09;unsigned char STEP10 = 0x05;unsigned char STEP11 = 0x06;unsigned char STEP12 = 0x0A;// stop the motorsunsigned char STEP13 = 0x00;// LDR1 = left and LDR2 = rightvoid high_isr (void);void low_isr (void);void INT0_ISR(void); //Prototype for the goto that followsvoid INT1_ISR(void); 20 | P a g e
  • 21. #pragma code high_interrupt = 0x08 //High Interrupt vector @ 0x08void high_interrupt (void) // At loc 0x08 we place the assembler instructionGOTO{ _asm // This is the assembly code at vector location GOTO high_isr _endasm}#pragma code#pragma interrupt high_isrvoid high_isr (void){ if (INTCONbits.INT0IF == 1)// Was interrupt caused by INT0 ? INT0_ISR (); // Yes , execute INT0 program}#pragma code low_interrupt = 0x18void low_interrupt (void) // At loc 0x08 we place the assembler instructionGOTO{ _asm // This is the assembly code at vector location GOTO low_isr _endasm}#pragma code // used to allow linker to locate remaining code#pragma interruptlow low_isrvoid low_isr (void){ if (INTCON3bits.INT1IF == 1) INT1_ISR ();}int LDR1 = 0;int LDR2 = 0;int i;void main (void){ ADCON1 = 0xFF; TRISD = 0x00; LATD = 0x00; TRISA = 0xFF; TRISC = 0xFF; // setting the interrupts INTCONbits.INT0IE = 1; //Enable INT0 interrupts INTCONbits.INT0IF = 0; // Clear INT0 Interrupt flag INTCON3bits.INT1IE = 1; //Enable INT0 interrupts INTCON3bits.INT1IF = 0; // Clear INT0 Interrupt flag INTCON3bits.INT1IP = 0; RCONbits.IPEN = 1; INTCONbits.GIE = 1; // Enable global interrupts INTCONbits.GIEL = 1; INTCONbits.GIEH = 1; 21 | P a g e
  • 22. while(1) { OpenADC(ADC_FOSC_32 & ADC_LEFT_JUST & ADC_0_TAD,ADC_CH0 & ADC_INT_OFF &ADC_VREFPLUS_VDD & ADC_VREFMINUS_VSS, 0b1011); SetChanADC(ADC_CH0); /* Selects the pin used as i/p to the */ Delay10TCYx(20); /* delay for 200 instruction cycles */ ConvertADC( ); /* start A/D conversion */ while(BusyADC( )); /* wait for completion */ LDR1 = ADRESH; OpenADC(ADC_FOSC_32 & ADC_LEFT_JUST & ADC_0_TAD,ADC_CH1 & ADC_INT_OFF &ADC_VREFPLUS_VDD & ADC_VREFMINUS_VSS, 0b1011); SetChanADC(ADC_CH1); /* Selects the pin used as i/p to the */ Delay10TCYx(20); /* delay for 200 instruction cycles */ ConvertADC( ); /* start A/D conversion */ while(BusyADC( )); /* wait for completion */ LDR2 = ADRESH; if(LED1 == 0) {//LDRs controlling stepper motors// to check if ldr greater than ambient light and less than 15cm light if(LDR1 <= 245 && LDR2 <=245) { if(LDR1 > LDR2) { LATD = STEP5; Delay10KTCYx(12); LATD = STEP6; Delay10KTCYx(12); LATD = STEP7; Delay10KTCYx(12); LATD = STEP8; Delay10KTCYx(12); } else if(LDR2 > LDR1) { LATD = STEP9; Delay10KTCYx(12); LATD = STEP10; Delay10KTCYx(12); LATD = STEP11; Delay10KTCYx(12); LATD = STEP12; Delay10KTCYx(12); } 22 | P a g e
  • 23. else if(LDR2 == LDR1) { LATD = STEP1; Delay10KTCYx(12); LATD = STEP2; Delay10KTCYx(12); LATD = STEP3; Delay10KTCYx(12); LATD = STEP4; Delay10KTCYx(12); } } else { LATD = STEP13; Delay10KTCYx(12); } } else if(LED1 == 1) { for(i=0;i<14;i++) { LATD = STEP4; Delay10KTCYx(12); LATD = STEP3; Delay10KTCYx(12); LATD = STEP2; Delay10KTCYx(12); LATD = STEP1; Delay10KTCYx(12); } for(i=0;i<14;i++) { LATD = STEP5; Delay10KTCYx(12); LATD = STEP6; Delay10KTCYx(12); LATD = STEP7; Delay10KTCYx(12); LATD = STEP8; Delay10KTCYx(12); } } }} 23 | P a g e
  • 24. // Interrupt routine INT0_ISRvoid INT0_ISR (void) // This is the interrupt service routine{ for(i=0;i<7;i++) { // reverse; (for 3 times) LATD = STEP4; Delay10KTCYx(12); LATD = STEP3; Delay10KTCYx(12); LATD = STEP2; Delay10KTCYx(12); LATD = STEP1; Delay10KTCYx(12); } for(i=0;i<5;i++) { // stop right wheel and move left wheel (2 times) LATD = STEP9; Delay10KTCYx(12); LATD = STEP10; Delay10KTCYx(12); LATD = STEP11; Delay10KTCYx(12); LATD = STEP12; Delay10KTCYx(12); } for(i=0;i<4;i++) { // go forward; (1 time) LATD = STEP1; Delay10KTCYx(12); LATD = STEP2; Delay10KTCYx(12); LATD = STEP3; Delay10KTCYx(12); LATD = STEP4; Delay10KTCYx(12); }INTCONbits.INT0IF = 0; // Clear INT0 flag before returning to main programINTCON3bits.INT1IF = 0; // Clear INT0 flag before returning to main program} 24 | P a g e
  • 25. void INT1_ISR (void) // This is the interrupt service routine{ for(i=0;i<7;i++) { // reverse; (for 3 times) LATD = STEP4; Delay10KTCYx(12); LATD = STEP3; Delay10KTCYx(12); LATD = STEP2; Delay10KTCYx(12); LATD = STEP1; Delay10KTCYx(12); } for(i=0;i<5;i++) { // stop left wheel and move right wheel (2 times) LATD = STEP5; Delay10KTCYx(12); LATD = STEP6; Delay10KTCYx(12); LATD = STEP7; Delay10KTCYx(12); LATD = STEP8; Delay10KTCYx(12); } for(i=0;i<4;i++) { // go forward; (1 time) LATD = STEP1; Delay10KTCYx(12); LATD = STEP2; Delay10KTCYx(12); LATD = STEP3; Delay10KTCYx(12); LATD = STEP4; Delay10KTCYx(12); }INTCONbits.INT0IF = 0; // Clear INT0 flag before returning to main programINTCON3bits.INT1IF = 0; // Clear INT0 flag before returning to main program} 25 | P a g e
  • 26. Now let’s have a look at the PCB design of the circuit (2-D and 3-D images). 26 | P a g e
  • 27. 27 | P a g e
  • 28. 28 | P a g e
  • 29. 29 | P a g e
  • 30. 30 | P a g e
  • 31. Project Components The components we used are given below and from where to buy.Component Name Cost Link 2 LDR’s 2 x £2.01 = £4.02 http://uk.farnell.com/silonex/norps-12/light- dependent-resistor/dp/327700 1 PIC18F4520 £4.72 http://www.rapidonline.com/Electronic- microcontroller Components/PIC18Fwxyz-Enhanced-Flash- microcontroller-64435/?sid=2fbad005-5de5- 4e06-b030-abb943273caf 1 Photo reflective £4.30 http://uk.mouser.com/search/ProductDetail.as optical sensor px?qs=iblIa22dKKR%2F8%2FPojtStag%3D%3D& cm_mmc=findchips-_-na-_-na-_- na&extra=index=4%7Cquery=OPB743%7Cqty= 0 2 Stepper Motors 2x£8.35 = £16.70 http://www.rapidonline.com/Electrical- Power/2-Phase-Bipolar-Stepper-Motor-12v-37- 0507/?sid=09feedbc-9699-47dc-9868- df23ccdca7f3 Copper wire £2.83 http://www.rapidonline.com/Education/Gilt- copper-wire-83192/?sid=369bfaaf-db6a-464f- a38f-04f214c6ae63 Darlington Driver £5.09 http://uk.farnell.com/allegro- microsystems/a6841sa-t/darlington-driver- serial-8bit-5841/dp/1202821 Microchip ICD3 £124.88 http://uk.farnell.com/microchip/dv164035/kit- evaluation-icd3/dp/1664878 In total by spending £161.66 + miscellaneous charges (power supply and breadboard) we can build this light sensing robotic vehicle and program it as well. 31 | P a g e
  • 32. Test Methodology This design was not built at once. We did it in parts and noticed how the thing works and then reversed it and saw how it works and noted down the changes. First we set up the hardware with just one stepper motor and saw the movement.And programmed PORTD 0-3 bits according to this pattern STEP 1 0x09 STEP 2 0x05 STEP 3 0x06 STEP 4 0x0AThis made the stepper motor move in a full step sequence in a clockwise direction. Andrevering these values made the stepper motor move in a full step sequence in an anti-clockwise direction. STEP 1 0x0A STEP 2 0x06 STEP 3 0x05 STEP 4 0x09We understood that on reversing the code the movement of the stepper motor changed.Now we attached another stepper motor to PORTD 4-7 bits and tried making both themotors move at the same time. Since we knew the concept thus changed the values of stepsto: 32 | P a g e
  • 33. STEP 1 0xA9 STEP 2 0x65 STEP 3 0x56 STEP 4 0x9AWe kept one value to be ‘9’ and other to be ‘A’ because when a car moves we know that thetires of the car moves in the same direction but the motor which makes them move actuallyrotate in opposite directions. This concept we applied here and while making changes to thehexadecimal values of the steps we kept in mind to make one motor rotate in clockwisedirection and the other in anti-clockwise direction.This is the general case but with the robotic vehicle we worked on, with that we had tomove both the wheels in the same clockwise direction logically as well.When we completed the investigation of the stepper motors then we started dealing withthe photo reflective optical sensors and started testing them on the black line and on othersurface as well and found that when they were faced down on some other surface then getthe light in the receiver and thus completes the connection and returns a value of ZERO, butwhen placed faced down on a black surface, the receiver receives no light and theconnection doesn’t get complete and returns a value ONE. So we were sure that whenplaced on a black surface the sensors return a value 1 and when on other surface it returns avalue 0. We then connected the opto sensor to PORTC bits 7.Then we connected the multi meter with the LDR and threw light over them and recordedthe change in the voltage with respect to bright and low light conditions and the outputvalue of the voltage from the LDR’s according to different light sensitivities are: Light Sensitivity LDR1 LDR2 Normal Light 224 volts 221 volts Bright Light 246 volts 245 volts Medium bright Light 244 volts 244 voltsWe then compared both the values of LDR1 and LDR2 and assigned a pattern of steppingsequence to them. This was just a bit of the whole code to give an idea how the conditionswere made.Example:if(LDR1 <= 245 && LDR2 <=245) then to the light searching operation and move towards thelight and if not then stop the wheels.And the values were read into the PIC through an Analogue to Digital channel where theanalogue signal gets converted to digital signal. 33 | P a g e
  • 34. This was done by Analogue to Digital conversion code.OpenADC(ADC_FOSC_32 & ADC_LEFT_JUST & ADC_0_TAD,ADC_CH0 & ADC_INT_OFF &ADC_VREFPLUS_VDD & ADC_VREFMINUS_VSS, 0b1011); SetChanADC(ADC_CH0); /* Selects the pin used as i/p to the */ Delay10TCYx(20); /* delay for 200 instruction cycles */ ConvertADC( ); /* start A/D conversion */ while(BusyADC( )); /* wait for completion */ output = ADRESH; And similarly for the channel 1, now LDR1 and LDR2 contains the converted digital signal which we need to compare with our decimal values of 15 cm, far away or closer which is We know that 5v = 256 if we deal with 8 bit ADC channel Using a programmer calculator, we found out Analogue voltage Decimal Value 8-bit binary value 5 volts 256 1 0000 0000 2.5 volts 128 0 1000 0000 4.40 volts 224 0 1110 0000 4.83 volts 246 0 1111 0110 4.78 volts 244 0 1111 0100 By clubbing the stepping sequence, the photo reflective optical sensors and the light dependent sensors code the main function of the .c file was written and by clubbing the interrupt code for the lever switches the interrupt routine was written. This was the design process and the testing methodology including the UML activity diagrams for Hardware and Software design for the robotic vehicle. 34 | P a g e
  • 35. Conclusion:The group assignment we carried out helped us having a wider view on electronics and itsintegration with software. We already got an idea of ‘The World of Logic and Circuits’ fromassignment 1 but this time it was an amazing experience to know that we can do so muchwith circuits and esp. learning to design a PCB. We understood how this integration works.Now we feel one more step closer to be an engineer and once again proved to ourselvesthat this was the right choice for our professional life. This project also made us feel moreconfident on practical basis, where we felt as if we were working with this equipment for along time.Working as a group in this project contributed in our success, because we all were notfamiliar with every aspect of the requirements. One of us was good with programming, onewith the hardware part as in the circuit part and one with both. Logical thinking is a veryimportant aspect to build any circuit that has no idea of what environment it is going to dealwith, and this aspect was in all three of us. We always thought a problem logically first,worked that logic out on paper and one of us decided how we will work this in coding, theother decided how this will work with the hardware and we started setting up the hardwareand writing the code so as not to waste any time. By doing this project together we endedup getting knowledge and information on the areas we were weak in through sharing ourideas and thoughts with each other.During the last three weeks where we carried out several tasks, we came across someproblems. For example at one point the sensor we were using was not working so wecouldn’t stop the car. It took us a bit of time to find out it was the sensor which wasn’tworking, as we had to individually test every component and wire connections. Then theLDR’s didn’t work well and we tried to search for a problem but logically everything wasfine. It took time to find that LDR’s didn’t worked fine with the opto-sensor. Also now weunderstand that if in the circuit shows a different path for the power supply then theyshould connect to the different power supplies.Other than that we didn’t encounter any major problems, and carried out the required taskseasily. By doing this project as a group we all getting knowledge and information on theareas that we didn’t know at all such as interrupts. Also, it gave us a great time spendingwhere we can share our ideas and thoughts with each other.After we built the circuit and programmed the PIC we decided to test the robotic vehicle. Itwould’ve been amazing if everything went perfect at first stage, but unfortunately thisdidn’t happen. We had to modify a lot of little things like, the distance between the sensorsand the surface, change the coding (as the vehicle we were working on had differentpolarity stuff); as the vehicle was moving faster than it should and sometimes it got out ofits track (black tape). As mentioned before with a bit of modifying and adjustments theseproblems were overcome.Finally when we finished the robotic vehicle and were satisfied with the design and thecoding. So we placed the robot in an enclosed area with black tape around, placed someobstacles in between and a light source. Then we made the robot run and this time we werereally satisfied as it smoothly moved in the area searching for light and stopped at just somedistance from it. This made us feel good as all the hard work we put in, resulted in oursuccess. Now we wish to work on more projects like this, I wish there was some homeworkto design a robot to do this in your holidays. But we carried out this successfully. 35 | P a g e
  • 36. References:The ADC conversion code:http://web1.eng.coventry.ac.uk/panos/info/Experiments/Micros/202CDE/ADC%20Lab%20PIC18.pdfFor the configuration settings of the PIChttp://web1.eng.coventry.ac.uk/panos/info/Experiments/Micros/202CDE/Config%20settings%20PIC18.pdfFor the delay functions used in the codehttp://web1.eng.coventry.ac.uk/panos/info/Experiments/Micros/202CDE/Delay%20Library%20MCC18.pdfFor the MCC18 C compilerhttp://web1.eng.coventry.ac.uk/panos/info/Experiments/Micros/202CDE/Intro%20to%20the%20MCC18%20C%20compiler.pdfFor the sensorshttp://web1.eng.coventry.ac.uk/panos/info/Experiments/Micros/202CDE/Opto%20Sensors.pdfFor the stepper motorshttp://web1.eng.coventry.ac.uk/panos/info/Experiments/Micros/202CDE/Stepper%20Motor%20Experiment%20PIC.pdfOpto sensorshttp://web1.eng.coventry.ac.uk/panos/info/Experiments/Micros/202CDE/Opto%20Sensors.pdfInterruptshttp://web1.eng.coventry.ac.uk/panos/info/Experiments/Micros/202CDE/Interrupts%20intro%20%20PIC18%20.pdfLight Dependent Resistorshttp://web1.eng.coventry.ac.uk/panos/info/Experiments/Micros/202CDE/Interrupts%20intro%20%20PIC18%20.pdf 36 | P a g e

×