Finally, you'll code an app that uses the IR line sensors to make your robot count line markers it crosses as it follows a line. The robot will stop driving when it reaches a specific line number. You can then make the robot turn and start following a new line.
The advantage of counting line markers while following a line is that the robot will follow the path more reliably (even if the robot's turns aren't perfect), and the path doesn't necessarily have to form a closed loop. You can also create complex patterns with straight paths, curved paths, and loops.
The limitation of counting line markers while following a line is that you have to create a continuous line for each path, and different paths must intersect each other at 90° angles.
Your teacher might have set up one or more sets of line paths for the class to use for this tutorial.
If not, then create a set of lines and line markers on your floor or surface (e.g., large sheet of paper, etc.) similar to the diagram below, which represents an area about 3 feet by 4 feet in size.
REUSE LINE PATH: If you still have the line path that was created in tutorial E-2, you could modify it by adding lines to match the diagram below.
Each line or line marker should be about 0.5—0.75 inch wide.
Any line markers that intersect another line should be about 4—6 inches long.
Any lines or line markers that intersect should cross at a 90° angle.
In your Arduino code editor, use the "Save As" command to save a copy of the follow_line_test
app as a different app named: follow_count_lines_test
Once you saved the new app name, modify the block comment near the beginning of the app code to change Follow Line Test
to Follow and Count Lines Test
.
You'll add a custom function named followCountLine()
which will contain code to make your robot follow a line while using readings from the IR line sensors to count line markers that it crosses. The robot will stop when it reaches a specified line number. You can then make the robot turn and start following a new line.
Add this custom function after the loop()
function:
IMPORTANT: The followCountLine()
function requires two other custom functions, in order to work:
followLine()
function — used to make the robot follow the current line
driveDistance()
function — used to center the robot on the target line marker
So your app will also need to have both of these custom functions. Luckily, the saved app that you re-used for this current app already has the followLine()
function.
The followCountLine()
function calls the driveDistance()
function once the target line count is reached. The robot drives forward 3.5 inches, in order to center the robot's wheels on the target line marker.
So you'll need to add the driveDistance()
custom function, which contains code to make your robot drive in a straight line for a specified distance by using the wheel encoders.
Copy the driveDistance()
function from tutorial C-4 (use your browser's back button to return this page after copying), and add the function after the loop()
function.
Once your robot reaches a specific line marker using the followCountLine()
function, you'll usually turn the robot to start following a new line. Typically, you'll pivot the robot 90° right, 90° left, or 180° around.
So you'll also need to add the pivotAngle()
custom function, which contains code to make your robot pivot by a specified angle by using the wheel encoders.
Copy the pivotAngle()
function from tutorial C-5 (use your browser's back button to return to this page after copying), and add the function after the loop()
function.
Your app will need to create a new object (as a global variable) to represent the robot's wheel encoders, which are used by the driveDistance()
and pivotAngle()
functions.
Add this code statement before the setup()
function:
The robot will start on the inner line inside the loop. When the D12 button is pressed to "start" the robot, we want to make the robot follow the current line until it has counted 1 line marker (i.e., reached marker A in the diagram). Then we'll make the robot turn 90° right and follow the outer loop line until it has counted 4 line markers (which will bring it back to marker A). Then the robot will turn 90° right again, and follow the inner line until it has counted 1 line marker (i.e., returned to the start). Finally, the robot will turn around (180°) and "pause" itself, so it's back in its starting position.
First, delete the existing code statement within the if
statement in the loop()
function that calls the followLine()
function when started
is true
.
Then add these code statements within the if
statement in the loop()
function, so they will be performed when started
is true
:
Follow the steps to connect your robot to your computer, and upload the app.
Unplug the USB cable from the robot, and place the robot on the inner line with the robot's IR line sensors in front of the "start" line marker (so it will not be counted as the first line marker).
Press the D12 button to "start" the robot. The robot should follow the inner line. After the robot has reached the outer line, the robot should turn right and follow the outer line clockwise around one complete loop before turning right and returning to its starting position.
If you want to test the robot again, press the D12 button to "start" the robot again.
As further practice, you could modify the app to make the robot drive in different patterns using this same set of lines and line markers. For example, you could try to make the robot drive from the "start" line to line marker A, then turn left and drive to line marker D, then turn around (180°) and return to the start.
First, you'll code an app to test your robot's IR line sensors by sending serial data to your computer.
Open your Arduino code editor, and create a new app template.
Add a block comment at the beginning of the app code to identify your new app:
Rename the the new app as: line_sensors_test
If you need a reminder, here are .
. (You don't need to add the library to your code editor again — just include the library in this new app.)
The SparkFun RedBot Library also defines a class named RedBotSensor
that can be used to control the IR line sensors.
You'll need to create three new RedBotSensor
objects for your line sensors as part of the global variables in your app. Add this code before the setup()
function:
Hopefully, the code syntax for creating new objects looks familiar by now:
RedBotSensor
declares the class for the new object.
leftLine
, centerLine
, and rightLine
represent unique names for each object. Again, you decide what to name your objects. The names should make sense to anyone reading the code.
A3
, A6
, and A7
represent the I/O pin numbers that the left, center, and right line sensors should be connected to. If your sensors were connected to different pins, you'd change these pin numbers.
When your robot and computer are connected with a USB cable, they can communicate with each other by transferring serial data.
In this app, your robot will send data (IR sensor measurements) to your computer. Your Arduino code editor has a serial monitor window that can be used to view this serial data communication.
Add this code statement within the setup()
function:
This starts the serial data communication and sets the data transfer rate to 9600 bits per second.
You'll add a custom function named testLineSensors()
which will contain code to read the values from each IR line sensor and send these to your computer as serial data.
The RedBotSensor
class defines a method named read()
which is used to read the value from a specific IR line sensor. The read()
method will return an integer value (whole number) between 0-1023 representing a measurement of how much reflected IR light was detected:
Lower values indicate more IR light was reflected back. This indicates a lighter-colored surface.
Higher values indicate less IR light was reflected back. This indicates a darker-colored surface.
If the values are very high (greater than 1000), this probably indicates a surface drop-off (such as: a stair step leading down, the edge of a table, a hole in the surface, etc.).
Add this custom function after the loop()
function:
As you hopefully remember, the code within a custom function is only performed if the custom function is "called" by its name within another function, such as the setup()
function or loop()
function.
Add this code statement within the loop()
function:
By listing the name of the custom function, the custom function is "called" — so the code within that custom function will be performed one time.
For this app, this will be only code statement listed within the loop()
function. Since the loop()
function repeats itself continuously, the testLineSensors()
function will be called repeatedly.
Connect your robot to your computer using the USB cable. Turn on your robot, and upload the app to your robot.
After the upload is complete, do not unplug the USB cable. You have to keep the robot connected to your computer to allow the serial data communication.
In your Arduino code editor, open the serial monitor, so you can view the serial data communication from your robot:
Arduino Create (Web Editor): Click the Monitor menu link in the left navigation to display the serial monitor in the middle panel.
Arduino IDE (Desktop Editor): Under the Tools menu, select "Serial Monitor." A new window will appear displaying the serial monitor.
Place the robot on a sheet of white paper on your desk or table. View the IR sensor readings in the serial monitor. Even for a white sheet of paper, the sensor readings will probably be between 400-700. Your sensor readings will probably have different values. All of this normal — the IR sensor readings can be affected by the ambient light in the room.
Position the robot so only the center line sensor is above the dark line. View the IR sensor readings in the serial monitor. You should see that the center sensor reading is higher than the left and right sensors (which are positioned above a white surface). For a uniform black line, the center sensor reading should be at least 800 (or higher).
Then rotate the robot so all three line sensors are "on" the dark line. View the sensor readings in the serial monitor. All three sensor readings should be at least 800 (or higher).
Finally, position the robot near the edge of your desk or table. Then slowly roll the robot towards the edge until the IR line sensors are just hanging over the edge (be sure the robot won't roll off). View the sensor readings in the serial monitor. All three sensor readings should be about 1000 (or higher).
POWER DOWN: When you're done testing the IR line sensors, turn off your robot's power to conserve battery power.
Next, you'll code an app that uses the IR line sensors to make your robot avoid a line. The line acts a border to keep the robot inside (or outside) a certain area or path.
You'll use the same line as you did in the previous test — except for this test, the robot will be placed inside the area enclosed by the line. As the robot drives around, it will turn away from the line whenever the line is detected. In this case, the line will act like a border to keep the robot inside the area.
If you were to place the robot outside the area, then the line would act as a border to keep the robot outside of the area.
The robot's goal when avoiding a line is to check for a line as the robot drives and turn away when a line is detected. To do this, the robot can just check the left and right IR line sensors (rather than all three).
If the robot is trying to avoid a line, there are 3 possible situations when a line is detected:
If both the left and right IR line sensors detect the line, this means the robot has "hit" the line head-on. In this situation, the robot should turn around to avoid the line.
If only the left IR sensor detects the line, this means robot has "hit" the line at angle from the left. In this situation, the robot should turn right to avoid the line.
If only the right IR line sensor detects the line, this means robot has "hit" the line at angle from the right. In this situation, the robot should turn left to avoid the line.
In your Arduino code editor, use the "Save As" command to save a copy of the follow_line_test
app as a different app named: avoid_line_test
Once you saved the new app name, modify the block comment near the beginning of the app code to change Follow Line Test
to Avoid Line Test
.
You'll add a custom function named avoidLine()
which will contain code to use readings from the left and right IR line sensors to decide whether to drive straight, turn left, turn right, or turn around the right.
Similar to following a line, avoiding a line works best at slower speeds (otherwise the robot might drive past the line before detecting it), so this function uses a value of 100
for the motor power.
This function assumes that your robot will be avoiding a dark line on a light-colored surface. However, you can modify the function to instead avoid a light line on a dark surface.
This function generates a random number for the amount of time (in milliseconds) for each turn (pivot) in order to produce variation in the robot's new direction. The ranges for the random numbers were selected to make the pivot times close to a 90° turn or a 180° turn. However, you can modify the function to instead use fixed pivot times (such as 650 ms for a 90° turn and 1300 ms for a 180° turn).
MINIMUM PIVOT: Be sure to make the robot turn at least 90° whenever it detects a line. If the robot were to "hit" a line at a nearly perpendicular angle (almost head-on), then a pivot of less than 90° might not be enough to turn away from the line.
Add this custom function after the loop()
function:
When the D12 button is pressed to "start" the robot, we want make the robot drive forward while avoiding the line.
First, delete the existing code statement within the if
statement in the loop()
function that calls the followLine()
function when started
is true
.
Then add this code statement within the if
statement in the loop()
function, so it will be performed when started
is true
:
Follow the steps to connect your robot to your computer, and upload the app.
Unplug the USB cable from the robot, and place the robot inside the area enclosed by the line, so none of the robot's IR line sensors are on the line.
Press the D12 button to "start" the robot. The robot should start driving and should avoid the line by making turns to stay within the area enclosed by the line.
When you're done testing the robot, you can pick it up, and press the D12 button to "pause" the robot (or you can press the Reset button).
If you want to test further, place the robot back on the line, and press the button to "start" the robot again.
Next, you'll code an app that uses the IR line sensors to make your robot follow a line. The line determines the robot's path.
Your teacher might have set up one or more line paths for the class to use for this tutorial
If not, then create a line on your floor or surface (e.g., large sheet of paper, etc.) that forms a closed path (i.e., an oval or rounded rectangle). The line should be about 0.5—0.75 inch wide. The line should not have any "sharp" turns — instead, use a curved path to make any turns.
The diagram below represents a line enclosing an area about 3 feet by 4 feet in size. You'll also use your line for the next test (), so be sure the area enclosed by the line is at least 2 feet by 3 feet.
The robot's goal during line following is to try stay centered on the line as the robot drives.
Let's assume that the robot is trying to follow a dark line on a light-colored surface. When the robot is centered on the line, the center IR line sensor will have a high reading (due to the dark line) while the left and right sensors will have low readings (due to the light-colored surface on either side of the line).
If the robot is trying to follow a line, there are 3 possible situations at any given point:
If only the center IR line sensor detects the line, this means the robot is centered on the line. In this situation, the robot should drive straight to keep following the line.
If only the left IR sensor detects the line, this means the line has started to curve to the left. In this situation, the robot should adjust its motors to curve left and keep following the line.
If only the right IR line sensor detects the line, this means the line has started to curve to the right. In this situation, the robot should adjust its motors to curve right and keep following the line.
In your Arduino code editor, use the "Save As" command to save a copy of the line_sensors_test
app as a different app named: follow_line_test
Once you saved the new app name, modify the block comment near the beginning of the app code to change Line Sensors Test
to Follow Line Test
.
Your app will need to create new objects (as global variables) to represent the robot's motors and button. Add this code before the setup()
function:
This app will use the "Press to Start" code. You'll press the D12 button to "start" the robot. Once the robot is "started," you can press the button again to "pause" the robot. (Pressing the button yet again will "start" the robot again.)
You need to declare global variables for the LED pin and speaker pin. You also need a global variable to keep track of whether or not the robot has been "started." Add this code before the setup()
function:
Set the pin modes for the LED and speaker by adding this code within the setup()
function:
This app does not need the Serial.begin()
statement within the setup()
function. You can turn this code statement into a comment by typing two forward slashes //
at the beginning of the statement.
Next, you need to add the custom function named checkButton()
that will check whether the D12 button is pressed, in order to "start" or "pause" the robot.
Add this custom function after the loop()
function:
Next, delete the code statement that calls the testLineSensors()
function within the loop()
function. This will give you an "empty" loop()
function.
Now add this new code within the loop()
function:
Later, you'll add the code to be performed when the robot is started or paused.
You'll add a custom function named followLine()
which will contain code to use readings from the three IR line sensors to decide whether to drive straight, curve to the left, or curve to the right.
Line following works best at slower speeds, so this function uses an initial value of 100
for the motor power (but shifts each motor power up or down by 50
in order to curve left or right).
This function assumes that your robot will be following a dark line on a light-colored surface. However, you can modify the function to instead follow a light line on a dark surface.
Add this custom function after the loop()
function:
When the D12 button is pressed to "start" the robot, we want the robot to follow the line.
Add this code statement within the if
statement in the loop()
function, so it will be performed when started
is true
:
Once the robot has been "started," the D12 button can be pressed again to "pause" the robot.
When the robot is "paused," we want make the robot stop driving.
Add this code statement within the else
statement in the loop()
function, so it will be performed when started
is false
:
Follow the steps to connect your robot to your computer, and upload the app.
Unplug the USB cable from the robot, and place the robot on your line, so only the robot's center IR line sensor is "on" the line.
Press the D12 button to "start" the robot. The robot should (hopefully) follow the line.
When you're done testing the robot, you can pick it up, and press the D12 button to "pause" the robot (or you can press the Reset button).
If you want to test further, place the robot back on the line, and press the button to "start" the robot again.
If your robot is unable to consistently follow the line, here are several things you could investigate:
Make sure your line path does not have sharp turns.
Make sure your line is dark enough and the right width. A uniform black line about 0.5–0.75 inch wide is ideal.
Make sure your surface is lighter in color than your line. A uniform white surface is ideal. However, the surface could be another color or have a pattern, as long as the IR sensor readings for the surface are consistently and significantly lower than the readings for the line.
You can use the line_sensors_test
app to check the IR sensor readings for your line and surface. The readings for a dark line should be consistently high (i.e., line readings of 800 or higher). The readings for your surface should consistently be at least 100 less than your line readings. If necessary, you can modify the value assigned to lineThreshold
in the followLine()
function.
LOW BATTERY: As your robot's battery power gets low, the IR line sensors will stop working — even though there still might be enough power to keep driving. If your robot was previously successful at line following and then starts having problems, try replacing the robot's batteries.
In this fifth tutorial, you'll learn how to make your robot detect lines on the surface by using its IR line sensors.
The goals of this tutorial are to help you:
Program a robot app that uses the IR line sensors to follow a line
Program a robot app that uses the IR line sensors to avoid a line
Program a robot app that uses the IR line sensors to count lines crossed
The RedBot has three IR line sensors (left, center, and right) mounted at its front close to the surface. The bottom of each line sensor has an LED that transmits infrared (IR) light, which is invisible to the human eye. The bottom of each sensor also has an IR detector, which measures how much of the IR light is reflected back by the surface that the robot is driving on.
The amount of reflected IR light that is detected depends on several factors, including the color of the surface, as well as the distance between the sensor and the surface:
A light-colored surface reflects more IR light, while a dark-colored surface reflects less IR light.
If the surface is farther away from the sensor, the IR light becomes more scattered, and less IR light will be reflected back to the detector. Even a small increase in the distance between the sensor and the surface will significantly reduce the amount of reflected IR light.
The most common use of the IR sensors is to detect a line on the surface. The robot can be programmed to follow the line, avoid the line, count the number of lines crossed, etc.
The IR sensors can also be used to detect a surface drop-off (such as a stair step leading down, a hole in the surface, etc.). The robot can be programmed to avoid driving over the drop-off by stopping, changing direction, etc.
Detecting lines with the IR sensors works best with a uniform dark line on a uniform light surface (or vice versa). The line also needs to be the right width: not too wide – but not too narrow. The line must be at least 0.25 inch wide – but no more than 1 inch wide.
If you have a light-colored hard surface (such as tile floor, etc.), black electrical tape works very well for making lines.
If you have a dark-colored hard surface, white electrical tape or white masking tape works well for making lines.
If you are using large sheets of paper (e.g., butcher paper, flip chart paper, etc.) for your surface, you might be able to use tape to make lines on the paper. However, be aware that black electrical tape is elastic and can pull on the paper (causing the paper to wrinkle, which interferes with line detection). To minimize this, use short sections of electrical tape, and avoid stretching the electrical tape when applying it to the paper.
If you are drawing lines on large sheets of paper, be sure to use a black felt-tip permanent marker (e.g., Sharpie) to make lines. Dry erase markers generally do not work well (pigment is not dark enough).
Also be sure to keep the paper as flat and smooth as possible when using (or when storing). Wrinkles or folds in the paper interfere with line detection. Paper can be rolled for storage, but roll carefully to avoid wrinkling.
Next, you'll code an app that uses the IR line sensors to make your robot count line markers it crosses as it drives straight. The robot will stop driving when it reaches a specific line number. You can then make the robot turn and start driving in a new direction.
The advantage of counting line markers while driving straight is that you can map out the robot's path by simply marking each point where the robot might stop or turn — without needing to create a continuous line to follow. You can also create complex patterns with intersecting paths.
The limitation of counting line markers while driving straight is that each specific path must be straight, and different paths must intersect each other at 90° angles.
Your teacher might have set up one or more sets of line markers for the class to use for this tutorial.
If not, then create a set of 4 line markers on your floor or surface (e.g., large sheet of paper, etc.) similar to the diagram below:
Each line marker should be about 0.5—0.75 inch wide and about 6—12 inches long. (In theory, the line markers could be only 3 inches long if the robot always drives perfectly straight and makes perfect turns, but you'll make the lines longer to account for the fact that the robot won't be perfect.)
The set of line markers should be arranged in a straight row along the robot's path. Each line marker should be perpendicular to the robot's path.
For this test, make the total distance from the 1st line to the 4th line about 48 inches (4 feet). This means you could space the line markers about 18 inches apart (though they do not have to be even spaced for line counting to work).
If you are drawing the lines on a large sheet of paper (approximately 3 feet wide by 6 feet long), be sure to draw the lines along the top of the paper, so later you'll be able to add another set of lines along the bottom of the paper.
In your Arduino code editor, use the "Save As" command to save a copy of the drive_straight_test
app as a different app named: count_lines_test
Once you saved the new app name, modify the block comment near the beginning of the app code to change Drive Straight Test
to Count Lines Test
.
Your app will need to create new objects (as global variables) to represent the robot's IR line sensors. Add this code before the setup()
function:
You'll add a custom function named countLine()
which will contain code to make your robot drive straight continuously while using readings from the IR line sensors to count each line marker that it crosses. The robot will stop when it reaches a specified line number. You can then make the robot turn and start driving straight in a new direction.
Add this custom function after the loop()
function:
IMPORTANT: The countLine()
function requires two other custom functions, in order to work:
driveStraight()
function — used to make the robot drive straight
driveDistance()
function — used to center the robot on the target line marker
So your app will also need to have both of these custom functions. Luckily, the saved app that you re-used for this current app already has the driveStraight()
function.
The countLine()
function calls the driveDistance()
function once the target line count is reached. The robot drives forward 3.5 inches, in order to center the robot's wheels on the target line marker.
So you'll need to add the driveDistance()
custom function, which contains code to make your robot drive in a straight line for a specified distance by using the wheel encoders.
Once your robot reaches a specific line marker using the countLine()
function, you'll usually turn the robot to start driving in a new direction. Typically, you'll pivot the robot 90° right, 90° left, or 180° around.
So you'll also need to add the pivotAngle()
custom function, which contains code to make your robot pivot by a specified angle by using the wheel encoders.
When the D12 button is pressed to "start" the robot, we want to make the robot drive straight until it has counted 3 line markers. Then we'll make the robot turn around (180°) and return by driving straight until it has counted another 3 line markers. Finally, the robot will turn around again (180°) and "pause" itself, so it's back in its starting position.
First, delete the existing code statement within the if
statement in the loop()
function that calls the driveStraight()
function when started
is true
.
Then add these code statements within the if
statement in the loop()
function, so they will be performed when started
is true
:
Follow the steps to connect your robot to your computer, and upload the app.
Unplug the USB cable from the robot, and place the robot centered on the "start" line, so the robot's IR line sensors are in front of the line (so the start line will not be counted as the first line).
Press the D12 button to "start" the robot. The robot should start driving straight. After the robot has counted 3 line markers (meaning it has reached the 3rd line after the start line), the robot should stop, turn around, and then drive back. After counting another 3 line markers (meaning the robot has returned to the start line), the robot should stop and turn around again (facing its original direction). The robot will "pause" itself automatically.
If you want to test the robot again, press the D12 button to "start" the robot again.
Next, you're going to modify the line maker pattern by adding more line markers to create a pattern similar to the diagram below:
Convert the 2nd line into a "plus sign" by creating another line (same length) at 90° to the original line. A "plus sign" line marker indicates where two (or more) paths intersect each other.
Create a 2nd "plus sign" below the first "plus sign," so they are aligned with each other, and their centers are about 18 inches apart (though the exact distance is not important).
Create 2 more line markers that are aligned with the 2nd "plus sign" to form another straight path for the robot.
The diagram below has red lines to show you the possible paths that the robot can take using this new line marker pattern. Each of the line markers has been labeled with a letter (A-F). (Do not add the red lines to your line marker pattern.) As you can see, the robot's possible path has multiple branches. Each line marker represents a possible stopping point or turning point along a specific path.
For example, maybe this pattern represents a set of paths for a warehouse robot to drive down two different aisles of shelving to deliver (or pick up) boxes. Path A-B-C represents the first aisle, while path D-E-F represent a second aisle. Path A-D connects the two aisles.
Here are guidelines to use when creating your own line marker patterns:
Each line marker should be about 0.5—0.75 inch wide and about 6—12 inches long.
Line markers that are part of the same path should be aligned to form a straight path. Each line marker should be perpendicular to the robot's path.
Line markers must be used to indicate the beginning and the end of a specific straight path.
Line markers can be used in the middle of a path to represent places where the robot might stop or turn around. However, it is not required to have line markers in the middle of a path.
Line markers that form a "plus sign" indicate where two (or more) paths intersect at a 90° angle.
You'll modify the app so the robot will drive from the "start" line to line marker F (see previous diagram) and then back again.
To do this, robot must drive to the 1st intersection ("plus sign") by counting 1 line marker. Then it should turn 90° right and drive to the 2nd intersection by counting 1 line marker. There it should turn 90° left and drive to the end of that path by counting 2 more line markers. Then it will turn 180° around and drive back to the "start" line again by counting lines and making turns.
First, delete the existing code statements within the if
statement in the loop()
function that are performed when started
is true
.
Then add these code statements within the if
statement in the loop()
function, so they will be performed when started
is true
:
Follow the steps to connect your robot to your computer, and upload the modified app.
Unplug the USB cable from the robot, and place the robot centered on the "start" line, so the robot's IR line sensors are in front of the line (so the start line will not be counted as the first line).
Press the D12 button to "start" the robot. It should drive from the "start" line to the end of the 2nd path that you added and then return back to the "start" line again.
If you want to test the robot again, press the D12 button to "start" the robot again.
As further practice, you could modify the app to make the robot drive in different patterns using this same set of line markers. For example, you could try to make the robot drive from the "start" line to line marker B, then turn around and drive to line marker E, and finally turn around and return to the start again.
Next, use a black permanent marker to draw a line (about 0.5 inch wide and about 3 inches long) in the middle of the paper. .
Copy the driveDistance()
function from (use your browser's back button to return this page after copying), and add this function after the loop()
function.
Copy the pivotAngle()
function from (use your browser's back button to return this page after copying), and add this function after the loop()
function.