Translate

Arduino Self-Learning Colour Following Robot

 1. Introduction

Prototype

A Self-Learning Colour Following Robot is an advanced robotics system that can learn any colour dynamically and follow it without reprogramming.

Unlike traditional robots where colour is fixed in code, this robot uses a push button to capture and store RGB values of the target colour and then follows it in real time.

This project is ideal for:

  • Robotics students
  • Automation learning
  • Smart industrial applications

2. Components

  • Arduino UNO / Nano
  • TCS3200 Color Sensor
  • L298N Motor Driver
  • DC Motors (2)
  • Robot chassis + wheels
  • Push Button
  • Battery pack
  • Jumper wires

3. Circuit and Connections

Pinout Diagram of Arduino Uno R3

Pinout Diagram of TCS3200 Sensor





Pinout Diagram of L298N Motor Driver Module

Pinout Diagram Push Button Module

🔹 TCS3200 Sensor:

  • VCC → 5V
  • GND → GND
  • S0 → Pin 2
  • S1 → Pin 3
  • S2 → Pin 4
  • S3 → Pin 5
  • OUT → Pin 6

🔹 Motor Driver:

  • IN1 → Pin 7
  • IN2 → Pin 8
  • IN3 → Pin 9
  • IN4 → Pin 10

🔹 Push Button:

  • VCC  → VCC
  • GND → GND
  • Signal → Pin 11

👉 Use INPUT_PULLUP in code if you use push button button 


4. Circuit Working

Working Diagram TCS3200 Sensor

🔍 Step-by-Step Working

🔹 1. Color Detection

The TCS3200 sensor detects RGB light reflected from the surface using filtered photodiodes.


🔹 2. Frequency Conversion

The sensor converts light intensity into frequency:

  • More light → Higher frequency
  • Arduino reads using pulseIn()

🔹 3. Learning Phase (IMPORTANT)

When the button is pressed:

  • Current RGB values are captured
  • Stored as:

    targetR, targetG, targetB

👉 This becomes the target colour


🔹 4. Detection Phase

Robot continuously reads current RGB values and compares with stored values.


🔹 5. Matching Logic

abs(current - target) < tolerance

👉 If all RGB values match → correct colour


🔹 6. Robot Action

  • Match → Move forward
  • No match → Stop

🔹 7. Continuous Loop

The process repeats continuously:

  • Read → Compare → Decide → Move

👉 Enables real-time colour tracking


5. Code

#define S2 4
#define S3 5
#define sensorOut 6

#define buttonPin 11

int redValue, greenValue, blueValue;

// Learned values
int targetR = 0, targetG = 0, targetB = 0;

int in1 = 7;
int in2 = 8;
int in3 = 9;
int in4 = 10;

void setup() {
pinMode(S2, OUTPUT);
pinMode(S3, OUTPUT);
pinMode(sensorOut, INPUT);

pinMode(buttonPin, INPUT_PULLUP);

pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);

Serial.begin(9600);
}

int readColor(int s2, int s3) {
digitalWrite(S2, s2);
digitalWrite(S3, s3);
return pulseIn(sensorOut, LOW);
}

void loop() {

redValue = readColor(LOW, LOW);
greenValue = readColor(HIGH, HIGH);
blueValue = readColor(LOW, HIGH);

// Learn color
if (digitalRead(buttonPin) == LOW) {
targetR = redValue;
targetG = greenValue;
targetB = blueValue;

Serial.println("Color Learned!");
delay(1000);
}

Serial.print("R: "); Serial.print(redValue);
Serial.print(" G: "); Serial.print(greenValue);
Serial.print(" B: "); Serial.println(blueValue);

if (abs(redValue - targetR) < 40 &&
abs(greenValue - targetG) < 40 &&
abs(blueValue - targetB) < 40) {

forward();
}
else {
stopRobot();
}

delay(200);
}

void forward() {
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
}

void stopRobot() {
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
}

6. Code Working

  • readColor() → Reads RGB values using sensor
  • Button press → Stores target colour
  • abs() → Calculates difference between current and stored values
  • If difference is within tolerance → Match

Movement:

  • Match → forward()
  • No match → stopRobot()

7. Tips

  • Maintain constant sensor height (1–2 cm)
  • Use same lighting conditions
  • Adjust tolerance (20–80) based on environment
  • Avoid shadows and reflections
  • Press button only when colour is stable

8. Uses

  • Smart industrial robots
  • Automated sorting systems
  • Warehouse automation
  • Robotics competitions
  • AI-based learning systems

9. Conclusion

The Self-Learning Colour Following Robot is an advanced and intelligent robotics project that demonstrates real-time sensing and adaptive decision-making.

It eliminates the need for reprogramming and allows dynamic colour selection, making it highly useful in modern automation systems.

തുടക്കക്കാർക്കായി ഇലക്ട്രോണിക്സ് ലളിതമായി പഠിക്കാം.

Empowering students in Kerala with hands-on technical skills.