Line Robot - Basic lessons - Exercises - Line following with 4 transistors
We already learned how to follow a line with 2 transistors. It's time to go further.
Task: line following with 4 transistors.
You can use any 4 transistors to make a program that will be able to follow a line even if there are right-angled curves. You can use as a template the program we already made:
void RobotLine::loop() {
if (line(5))
go(-60, 90);
else if (line(3))
go(90, -60);
else
go(60, 60);
}
Solution
One of the possible solutions, definitely not the best, is here:
void RobotLine::loop() {
if (line(8))
go(-90, 90);
else if (line(0))
go(90, -90);
else if (line(5))
go(-30, 90);
else if (line(3))
go(90, -60);
else
go(60, 60);
}
Edge transistors turn the robot in place, overcoming most of the right angles.
Try to understand why edge transistors must be tested before the other ones. A hint: robot can detect the line with multiple transistors at the same time.
If robot doesn't follow line successfully, decrease speed.