Micromelon Robotics
Platform
Resources
NewsAbout UsDownload
Support
Build Your Kit

Stay in the loop

New activities, teaching guides, and product updates delivered to your inbox.

Micromelon Robotics

Australian-made educational robotics for the next generation of innovators.

contact@micromelon.com.au

Company

  • About Us
  • Privacy Policy
  • Terms and Conditions

Products

  • Micromelon Rover
  • Code Editor
  • Robot Simulator
  • Junior
  • Python Library

Support

  • Resources
  • News
  • Rover Repairs
  • Contact
  • Build Your Kit

© 2026 Micromelon Robotics Pty Ltd. All rights reserved.

ABN 56 623 302 296

← Back to Resources
Advanced Guides

Showcase: Rover and Arduino Line Follow

30 December 2024

Showcase: Rover and Arduino Line Follow

Using I2C and an Arduino Nano, a QTR-8RC line sensor array can be attached to the Rover for advanced line following. This guide is a showcase of how it can be done.

An overview of the I2C protocol and how to use it with the Rover can be found in the How to use I2CRelated resourceHow to use I2CUse I2C on the Micromelon Rover to communicate with external devices like servo drivers, sensor arrays, or an Arduino..

Arduino Nano + QTR-8RC sensor array mounted on the Rover

Arduino Nano + QTR-8RC sensor array mounted on the Rover

The Sensor (QTR-8RC)

The Pololu QTR-8RC is an array of 8 infrared sensors spaced approximately 9.5 cm apart. The advantage of using 8 sensors for line following is that the Rover’s speed can be significantly increased, there’s a much lower chance of losing the line when moving. When paired with the QTR library, the sensor array calculates the line’s position relative to it, returned as a value between 0 and 8000. If the line is lost, the sensor also remembers the last sensor that saw the line in the array.

Pololu QTR-8RC infrared line sensor array

Pololu QTR-8RC infrared line sensor array

The Arduino

Arduino Nano microcontroller

Arduino Nano microcontroller

The Arduino Nano is the microcontroller used to control the QTR sensor. With the sensor plugged in, the Arduino uses the QTR library to locate the line’s position under the sensor. The Arduino then communicates with the Rover over I2C, the Rover requests data and receives a buffer containing the line’s location determined by the infrared sensor array. This buffer is 2 bytes because the maximum value of 8000 is larger than what a single byte can hold.

#include <QTRSensors.h>
#include <Wire.h>
 
#define ADDRESS 10
QTRSensors qtr;
 
const uint8_t SensorCount = 8;
uint16_t sensorValues[SensorCount];
 
uint16_t position = 2000;
 
void setup() {
  Wire.begin(ADDRESS);
  Wire.onRequest(readSensor);
  // Configure the sensors
  qtr.setTypeRC();
  qtr.setSensorPins((const uint8_t[]){9, 8, 7, 6, 5, 4, 3, 2}, SensorCount);
 
  delay(500);
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, HIGH);
 
  for (uint16_t i = 0; i < 400; i++) {
    qtr.calibrate();
  }
  digitalWrite(LED_BUILTIN, LOW);
}
 
void loop() {
  position = qtr.readLineBlack(sensorValues);
}
 
void readSensor() {
  byte buf[2] = {(position & 0xFF00) >> 8, position & 0xFF};
  Wire.write(buf, 2);
}
Wiring diagram, Arduino Nano connected to the Rover over I2C

Wiring diagram, Arduino Nano connected to the Rover over I2C

Micromelon Rover expansion header pinout

Expansion Header Pinout

12-pin header. Pin 1 is top-left; top row reads left-to-right, bottom row reads right-to-left.

Pin 1I2C SCL3.3V logic
Pin 2Battery VoltageInternal
Pin 3I2C SDA3.3V logic
Pin 4UART RX3.3V logic
Pin 5UART TX3.3V logic
Pin 6GND
Pin 12ReservedInternal I2C
Pin 11ReservedInternal I2C
Pin 10ReservedNC
Pin 93.3V300mA
Pin 8ReservedNC
Pin 7USB VoltageFused to 1A

The Rover

A 3D-printed mount was designed to hold the Arduino and the line sensor array. Once all the electronics were connected, code to request data from the Arduino was uploaded to the Rover. The snippet below uses the read_sensor function to receive incoming data from the Arduino.

ADDRESS = 10
REGISTER = 0x1
 
def read_sensor():
    packet = I2C.read(ADDRESS, REGISTER, 2)
    packet = (packet[0] << 8) | packet[1]
    return packet

These concepts were then assembled to create a PID line follower.

Going Further

With PID tuning and a well-mounted sensor array, the Rover can follow tight curves at impressive speeds. Try adjusting the PID constants to see how they affect tracking accuracy and responsiveness, or experiment with different line layouts to push the system to its limits.

Continue Learning

How to Design a Rover AttachmentRelated resourceHow to Design a Rover AttachmentA guide to designing custom 3D-printed Rover attachments, from servo allocation to print connections and gears.

Getting Started with Arduino and the Micromelon RoverRelated resourceGetting Started with Arduino and the Micromelon RoverConnect an Arduino Uno to the Micromelon Rover and control it over UART using software serial.

Getting Started With Proportional ControlRelated resourceGetting Started With Proportional ControlAn introduction to proportional control, what control systems are, the key components, and how to apply proportional control on the Micromelon Rover.

← Return to Resources