- Rokit Smart Tutorials Home
- Programming Tutorials
- All Robots
- Programming the Mouse Bot
- Programming the Sumo Bot
- Programming the Crab Bot
- Programming the Soccer Bot
- Programming the Truck Bot
- Programming the Pirate Ship Bot
- Programming the Turret Bot
- Programming the Motion Capture Bot
- Programming the Gorilla Bot
- Programming the Bug Bot
- Programming the Line Follower Bot
- Programming Basics
- Programming Components
- All Robots
- Building tutorials
- Competition tutorials
How to Program the Line Follower Bot
This lesson will go over how to program the Line Follower Bot
What it Does
The Line Follower Robot is designed to follow a black line on a white surface.
Objectives
Program the controller in such a way that:
- While left side sees white, turn right.
- While right side sees white, turn left.
Video Guide
How to Code
Firstly we need to setup our code. To do so we will include the SmartInventor library, setup our motors, and then set pins 13 and 16 (the bottom IR sensors just outside of the middle) as inputs.
[crayon-6758a1596ac88584091048/]
Now it is time to write the main section of the code. In order to do so, a “While Loop” may keep the robot following the line. (Reminder! Click here to review how “While Loop” work).
Until the sensor associated with pin 16 (middle-left sensor) reaches the black line, the left motor must keep turning the robot to the right.
[crayon-6758a1596ac93915424841/]
Until the sensor associated with pin 13 (middle-right sensor) reaches the black line, the right motor must keep turning the robot to the left.
[crayon-6758a1596ac95587235849/]
The idea of this code is that it will keep wiggling back and forth above the line. Each time it wiggles it will move forward a little bit, thus letting it move along the line.
Caution: Make sure to calibrate the control properly by placing the robot on the line and adjusting the nob on the board until it distinguishes the difference between the line and the surface clearly.
Optional: In order to customize the robot’s actions, the motor speed or the delay time may be changed accordingly.
Final Code
[crayon-6758a1596ac96168136798/]