ROBOTICS TASK
Doing everything at one time is very very difficult.
So, what you have to do is to break this task into smaller portions.
TASK 1:
INTERFACE 3 IR SENSORS AT ONE
We have interfaced only one IR in the class. Here, you will interface 3 IR sensors. So, in the
Setup function, you have to set up 2 more IRs, same as we did earlier. Along with the IR, also
interface 3 LEDs one for each IR.
Finish this task in one day. I think it is not difficult to implement.
TASK 2:
INTERFACE 2 MOTORS
We have interfaced two motors in the class. But that code is basically changing the speed of
the motor continuously, as we have observed in the class. But, in this task we need only
constant speed. Along with that, in the task we also need only one direction that is forward.
So, in the code, in LOOP function, comment / remove the directionControl() line. Now, run
the code. See if it is working or not!
Your code will work 100%. In the speedControl function, remove both for loops. The code
shown in the figure below:
This code is to be removed
What you have to do here is: write the two lines:
“analogWrite(enA, 255);” and
“analogWrite(enB, 255);”
1
This will rotate the motors with the same speed.
Now, write another function by yourself, same function but with name “speedControlLEFT”
copy the speedControl function and paste it in your newer function. The only change here is
in line “analogWrite(enA, 255);” change 255 to 125. Similarly, write another function named
speedControlRIGHT and change the line “analogWrite(enB, 255);” change 255 to 125.
Do not forget to compile your code after every function creation for removing the bugs. Now,
in the LOOP() function, where speedControl() is used, change speedControl() to
speedControlLEFT() and see, one motor will rotate slowly then the other. Do this same with
the other function.
In this way we also get the code for the motor control. This code will have 3 more functions,
speedControl(), speedControlLEFT(), speedControlRIGHT() functions.
TASK 3:
INTERFACE ULTRASONIC SENSOR
We did that in the class so no need to change that.
TASK 4:
INTERFACE ULTRASONIC SENSOR and MOTORS SIMULTANEOUSLY.
From portion 2 we have moved from, interfacing task to the logic development task. Interface
both ultrasonic sensor and motors together. In the part where LED was turning ON, write
analogWrite() for turning OFF the motors.
And in part where, LED was turning ON, write a routine for the motor rotation. Means, write
simply the speedControl() function line (the same line we did that in task 2 in LOOP function).
Check the code, if it works or not.
TASK 5:
INTERFACE IR and MOTORS SIMULTANEOUSLY.
In the motor code, we have made 3 functions, speedControl(), speedControlLEFT(),
speedControlRIGHT() functions.
Now, when IR2 (center) IR is PRESSED or ON, both motors must move with the same speed.
So, you have to write the speedControl()function. If IR1 (left) IR is pressed,
speedControlLEFT() will execute. Similarly, for the speedControlRIGHT() function.
2
ONE LAST THING: DON’T WORRY!! WE WILL BE ASSISTING YOU IN YOUR
PROJECT.