Live robotics updates
A guide to Day 1 of the 2026 Robotics Summit & ExpoThe Robot ReportWhy robots still struggle to see the real worldThe Robot ReportApplication engineering for assembly systems is quietly becoming manufacturing’s biggest competitive edgeRobotics & Automation NewsFigure ramps up humanoid robot manufacturing at unprecedented speedRobotics & Automation NewsFigure partners with Catalyst Brands to deploy humanoid robots in logistics operationsRobotics & Automation NewsGreenpeace robot stages deepest-ever seabed protestRobotics & Automation NewsChina to assign digital ID numbers to humanoid robots for lifecycle trackingRobotics & Automation NewsCVPR 2026 fields 16,000+ paper submissions on technical advances in AIRobotics & Automation NewsVirginia Tech researchers control soft robotics with ‘AI’s cousin’: ‘Reservoir computing’Robotics & Automation NewsFesto introduces two-finger pneumatic gripper for cobot applicationsRobotics & Automation NewsA guide to Day 1 of the 2026 Robotics Summit & ExpoThe Robot ReportWhy robots still struggle to see the real worldThe Robot ReportApplication engineering for assembly systems is quietly becoming manufacturing’s biggest competitive edgeRobotics & Automation NewsFigure ramps up humanoid robot manufacturing at unprecedented speedRobotics & Automation NewsFigure partners with Catalyst Brands to deploy humanoid robots in logistics operationsRobotics & Automation NewsGreenpeace robot stages deepest-ever seabed protestRobotics & Automation NewsChina to assign digital ID numbers to humanoid robots for lifecycle trackingRobotics & Automation NewsCVPR 2026 fields 16,000+ paper submissions on technical advances in AIRobotics & Automation NewsVirginia Tech researchers control soft robotics with ‘AI’s cousin’: ‘Reservoir computing’Robotics & Automation NewsFesto introduces two-finger pneumatic gripper for cobot applicationsRobotics & Automation News
View all
Back
Arduino sample guide

roboda-sample-0075 - Line Follow Logic 03

Use two analog sensors to make basic line-following motor decisions.

Step-by-step build

Combine sensor thresholds and motor decisions for line following robots.

1

Wire left and right sensors to A0 and A1.

2

Wire motor driver speed inputs to D5 and D6.

3

Tune lineThreshold for the track and sensor height.

4

Reduce one side speed when that sensor sees the line.

Important code parts

These are the sections learners should understand before changing the sketch.

analogRead(leftSensor)

Reads reflected light from the left sensor.

lineThreshold

Separates line color from floor color.

analogWrite(leftMotor/rightMotor)

Changes motor speed to steer.

Pin mapping for this sample

Use this first table for the exact sample wiring, then use the board-family table when moving the sketch to another Arduino board.

Code nameSample pinModeConnect toNote
left/right sensorsA0, A1analog inputIR reflectance sensor outputsTune lineThreshold for your surface.
left/right motorsD5, D6PWM OUTPUTMotor driver speed inputsUse separate motor power and common GND.

Arduino board pin reference

The code names stay the same; only the physical board pins may change by family. Always confirm with the board silkscreen when using clones or special variants.

Board familyDigitalPWMAnalogI2CSPIInterrupt
Uno / Nano / Pro MiniDefault target for these samples.D0-D13D3, D5, D6, D9, D10, D11A0-A5A4 SDA, A5 SCLD10 SS, D11 MOSI, D12 MISO, D13 SCK / ICSPD2, D3
Mega 2560Best for many sensors or multiple serial ports.D0-D53D2-D13, D44-D46A0-A15D20 SDA, D21 SCLD50 MISO, D51 MOSI, D52 SCK, D53 SS / ICSPD2, D3, D18, D19, D20, D21
Leonardo / MicroUSB serial can behave differently because the main MCU handles USB.D0-D13D3, D5, D6, D9, D10, D11, D13A0-A5 plus extra analog-capable pins by boardD2 SDA, D3 SCLICSP headerD0, D1, D2, D3, D7
Nano Every / Uno WiFi Rev2Check the board package pinout for exact PWM labels.D0-D13PWM-marked digital pinsA0-A7 on Nano Every, A0-A5 on Uno WiFi Rev2SDA/SCL marked pinsICSP/SPI marked pinsUse pins supported by digitalPinToInterrupt()
Uno R4 Minima / Uno R4 WiFi5V logic board; still confirm shield/library compatibility.D0-D13PWM-marked digital pinsA0-A5SDA/SCL marked pinsICSP/SPI marked pinsUse digitalPinToInterrupt(pin)
Due3.3V logic only; protect pins from 5V sensors.D0-D53PWM-marked digital pinsA0-A11SDA/SCL and SDA1/SCL1SPI headerUse digitalPinToInterrupt(pin)
MKR / Nano 33 family3.3V logic. Some AVR-only libraries may need alternatives.Board-marked digital pinsPWM-marked pinsBoard-marked analog pinsSDA/SCL marked pinsSPI marked pinsUse digitalPinToInterrupt(pin)

Full sample code

/*
  Roboda verified Arduino sample 0075
  Feature: Line Follow Logic
  Generated for online build, classroom practice, and hardware upload testing.
*/

const byte leftSensor = A0;
const byte rightSensor = A1;
const byte leftMotor = 5;
const byte rightMotor = 6;
const int lineThreshold = 400;

void setup() {
  pinMode(leftMotor, OUTPUT);
  pinMode(rightMotor, OUTPUT);
}

void loop() {
  int left = analogRead(leftSensor);
  int right = analogRead(rightSensor);
  analogWrite(leftMotor, left > lineThreshold ? 120 : 210);
  analogWrite(rightMotor, right > lineThreshold ? 120 : 210);
  delay(20);
}

Teacher notes

  • Compile the sample before changing wiring or constants.
  • When changing boards, keep the code names the same and update only the pin number constants.
  • For 3.3V boards, level-shift 5V sensors and modules before connecting signal pins.
  • Use the first compiler error and the Roboda diagnostic suggestion before fixing later warnings.
Roboda support Leave a message

New messages appear in the Finite LiveChat Ops Android app.