Example Code for Arduino-Line Tracking
Last revision 2026/01/06
This article provides a comprehensive guide on setting up and programming the Vortex Robot for line tracking using Arduino. It includes hardware and software preparations, a wiring diagram, sample code, and testing methods. The sample code demonstrates how to use the gray sensor on Vortex, and the test method involves checking the gray value as the robot moves across a black strip.
Hardware Preparation
- Vortex Robot, SKU:ROB0116
- micro USB cable
Software Preparation
- Arduino IDE, Download link
Wiring Diagram

| Num. | Pin |
|---|---|
| 1 | A3 |
| 2 | A2 |
| 3 | A1 |
| 4 | A0 |
| 5 | A6 |
| 6 | A7 |
Other Preparation Work
- Unscrew the screw and open the USB programming port.
- Turn on Vortex power switch, and plug in the Micro usb cable, it will install the driver automatically if you have installed Arduino IDE. If not, you can find it in the driver file in Arduino IDE folder-->Drivers folder.
- There is a switch close to the USB port, make sure the trigger is close to the USB side. This is MP3 switch, we'll teach you how to add new song in the following chapter.
- Open your Arduino IDE, select "Arduino UNO" and right "COM port" in Arduino IDE, now you can enjoy coding.
Sample Code
/***************************************************
Vortex V1.0 (Small robots like bread)
<https://www.dfrobot.com.cn/goods-1199.html>
***************************************************
This example show how to use Gray sensor on vortex.
Created 2016-2-3
By Andy zhou <[email protected]>
version:V1.0
****************************************************/
/***********Notice and Trouble shooting***************
1.Connection and Diagram can be found here
<http://wiki.dfrobot.com.cn/index.php?title=(SKU:ROB0116)_Vortex%E5%8F%AF%E7%BC%96%E7%A8%8B%E6%9C%BA%E5%99%A8%E4%BA%BA#.E6.A0.B7.E4.BE.8B.E4.BB.A3.E7.A0.81>
2.This code is tested on vortex V1.0.
****************************************************/
void setup(void){
Serial.begin(9600);
}
int analogBuf[6] = {'\0'};
void loop(void){
analogBuf[0] = analogRead(3);
analogBuf[1] = analogRead(2);
analogBuf[2] = analogRead(1);
analogBuf[3] = analogRead(0);
analogBuf[4] = analogRead(6);
analogBuf[5] = analogRead(7);
for(int i=0;i<6;i++){
Serial.print(i+1);
Serial.print(": ");
Serial.print(analogBuf[i]);
Serial.print(" ");
}
Serial.println();
delay(500);
}
Result
Test Method You can leave a black strip in front of the Vortex, moving vortex cross the strip and checking the gray value one by one.
image:Vortex_test_method_1.jpg|Leave a black strip image:Vortex_test_method_2.png|All sensors are on the white paper image:Vortex_test_method_3.png|The first one is on the Black strip and the rest are on the white paper
Was this article helpful?
