/* EDGE AVOIDING ROBOT */ /* Right edge detecting module is connected at P1_0 Left edge detecting module is connected at P1_1

Right Motor is Connected at P2_0 & P2_1 Left Motor is Connected at P2_2 & P2_3 */ ______________________________________________________________________ #include<P89V51RD2.h> #include<delay.h> #define fwd 0×05 // 01 01 Motor 1 and 2 in forward direction #define left 0×06 // 01 10 Motor 2 in forward direction and Motor 1 in reverse direction #define right 0×09 // 10 01 Motor 1 in forward direction and Motor 2 in reverse direction #define rev 0×0A // 10 10 Motor 1 and 2 in reverse direction void main() { P1= 0xFF; // Port 1 intitialised as input P2= 0×00; // Port 2 intitialised as output while(1) { if (P1_0==1 && P1_1==1) // NO EDGE { P2= fwd; //Here forward and delay are given in small intervals DELAY(10); //to reduce the speed of the motor P2= 0×00; //This acts as PWM signal of 50% duty cycle

// speed reduction is required. //for proper detection of edge and //avoid fallin of robot over the edge. . DELAY(10). } if (P1_0==1 && P1_1==0) // EDGE ON LEFT { P2= right. } if (P1_0==0 && P1_1==0) //EDGE IN FRONT { P2= rev. DELAY(25). DELAY(25). P2= 0×00. DELAY(10). P2= 0×00.DELAY(10). } if (P1_0==0 && P1_1==1) //EDGE ON LEFT { P2= left. P2= right. DELAY(10).

DELAY(10). P2= 0×00.DELAY(25). } } } .

Sign up to vote on this title
UsefulNot useful