Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Arduino
140 min
Share

بناء روبوت يتتبع الخطوط باستخدام الأردوينو

في عصر التكنولوجيا الحديثة، أصبحت الروبوتات حلولًا ذكية في مختلف المجالات. ومن أبرزها، الروبوت الذي يتتبع الخطوط المرسومة تلقائيًا، مما يجعله مثاليًا للاستخدام في أنظمة النقل الذكية والمستودعات الآلية لتحسين الكفاءة والدقة.

Project Video

Overview

في هذا المشروع، سنقوم ببناء روبوت قادر على تتبع الخطوط المرسومة على الأرض باستخدام مستشعرات خاصة. سيحدد الروبوت مسار الخط بدقة ويتحرك وفقًا له تلقائيًا بدون أن يحيد يمينًا أو يسارًا بعيدًا عن الخط.

Getting the Items

Arduino Uno R3 (Voltaat Version)
Get Item
IR Line Tracking Module
Get Item
2Amp 7V-30V L298N Motor Driver / Stepper Driver (2 Channels)
Get Item
3×18650 Battery Holder
Get Item
Lithium ion 3.7 V 3800mah rechargeable battery – 18650
Get Item
DC Female Jack Plug Extensioin cable (5.5 x 2.1mm)
Get Item
4 Wheel Arduino Car Kit
Get Item
Half-size Breadboard
Get Item
Jumper Wires - Male to Male (40 Pack)
Get Item
Jumper Wires – Male to Female (40 Pack)
Get Item

Steps

فى البداية, قم بتجميع السيارة ذات الاربع عجلات, يمكنك رؤية كيفية تجميعها من خلال الفيديو التالى :

Wiring it Up

قم بتوصيل الأسلاك بين حساسات تتبع الخطوط ولوحة الأردوينو وقائد المحركات والمحركات كما هو موضح في الصورة أدناه.

التوصيلات من الاردوينو الى لوحة التجارب :

• منفذ ال 5 فولت ← المنافذ الموجبة بلوحة التجارب

• منفذ الجراوند ← المنافذ السالبة بلوحة التجارب

التوصيلات من مدخل البطارية:

‍ نقوم بتوصيل الطرف الموجب لمدخل البطارية ← منفذ ال 12v  بقائد المحركات

ونقوم بتوصيل طرف الجراوند لمدخل البطارية ← منفذ الGND بقائد المحركات

التوصيلات من قائد المحركات L298N   الى لوحة التجارب :

•   منفذ ال 5 فولت من قائد المحركات ← المنافذ الموجبة بلوحة التجارب

•   منفذ الجراوند من قائد المحركات ← المنافذ السالبة بلوحة التجارب

التوصيلات من وصلة مدخل البطارية الى قائد المحركات :

• الطرف الموجب لوصلة مدخل البطارية ← منفذ ال 12+ بقائد المحركات

• الطرف السالب لوصلة مدخل البطارية ← منفذ الجراوند بقائد المحركات

التوصيلات من قائد المحركات      : L298N

• المنفذ EnA من قائد المحركات ← المنفذ رقم 5 فى لوحة الاردوينو

• المنفذ IN1 من قائد المحركات ← المنفذ رقم 11 فى لوحة الاردوينو

• المنفذ IN2 من قائد المحركات ← المنفذ رقم 10 فى لوحة الاردوينو

• المنفذ ENB من قائد المحركات ← المنفذ رقم 6 فى لوحة الاردوينو

• المنفذ IN3 من قائد المحركات ← المنفذ رقم 9 فى لوحة الاردوينو

• المنفذ IN4 من قائد المحركات ← المنفذ رقم 8 فى لوحة الاردوينو

التوصيلات من المحركات اليمنى :

•  احد اطراف المحرك الأول الأيمن ← احد اطراف المحرك الثانى الأيمن  ← المنفذ OUT1 فى قائد المحركات

•  الطرف الاخر للمحرك الأول الأيمن ← الطرف الاخر للمحرك الثانى الأيمن ← المنفذ OUT2 فى قائد المحركات

التوصيلات من المحركات اليسرى :

•  احد اطراف المحرك الأول الأيسر ← احد اطراف المحرك الثانى الأيسر  ← المنفذ OUT3 فى قائد المحركات

•  الطرف الاخر للمحرك الأول الأيسر ← الطرف الاخر للمحرك الثانى الأيسر ← المنفذ OUT4 فى قائد المحركات

التوصيلات من حساس تتبع الخطوط الأيمن   :

• منفذ ال VCC من حساس تتبع الخطوط ← المنافذ الموجبة بلوحة التجارب

• منفذ ال GND من حساس تتبع الخطوط ← المنافذ السالبة بلوحة التجارب

• منفذ ال D0 من حساس تتبع الخطوط ← منفذ رقم A0 فى لوحة الاردوينو

التوصيلات من حساس تتبع الخطوط الأيسر  :

• منفذ ال VCC من حساس تتبع الخطوط ← المنافذ الموجبة بلوحة التجارب

• منفذ ال GND من حساس تتبع الخطوط ← المنافذ السالبة بلوحة التجارب

• منفذ ال D0 من حساس تتبع الخطوط ← منفذ رقم 1A فى لوحة الاردوينو

Coding

/*

Voltaat learn (https://www.voltaat.com)

The function of this sketch is to controll a robot to track lines drawn on the

ground using special sensors called line tracking sensor. The robot will accurately

determine the path of the line and automatically move accordingly, without deviating

to the right or left.

Connections from the Arduino to the breadboard:

• Arduino 5v pin → breadboard 5v line

• Arduino GND pin → breadboard GND line

The connections from the L298N motor driver to the breadboard:

• 5V pin from the motor driver → breadboard 5v line

• GND pin from the motor driver → breadboard GND line

The connections from the battery input to the motor driver:

• Positive terminal of the battery input → +12V port on the motor driver

• Ground terminal of the battery input → Ground (GND) port on the motor driver

Connections from the l298n motor driver :

• ENA pin → Arduino pin 5

• In1 pin → Arduino pin 11

• In2 pin → Arduino pin 10

• In3 pin → Arduino pin 9

• In4 pin → Arduino pin 8

• ENB pin → Arduino pin 6

The connections from the right motors:

• One terminal of the first right motor → One terminal of the second right motor → OUT1 port in the motor driver

• The other terminal of the first right motor → The other terminal of the second right motor → OUT2 port in the motor driver

The connections from the left motors:

• One terminal of the first left motor → One terminal of the second left motor → OUT3 port in the motor driver

• The other terminal of the first left motor → The other terminal of the second left motor → OUT4 port in the motor driver

Connections from the Right Line Tracking Sensor:

• The VCC pin of the Right Line Tracking → breadboard 5v line

• The GND pin of the Right Line Tracking → breadboard GND line

• The D0 pin of the Right Line Tracking → Pin A0 on the Arduino board

Connections from the Left Line Tracking Sensor:

• The VCC pin of the Left Line Tracking Sensor → breadboard 5v line

• The GND pin of the Left Line Tracking Sensor → breadboard GND line

• The D0 pin of the Left Line Tracking Sensor → Pin A1 on the Arduino board

*/

// Define motor control pins for L298N

#define in1 11  // Motor1 (Right Motor) Input 1

#define in2 10  // Motor1 (Right Motor) Input 2

#define in3 9   // Motor2 (Left Motor) Input 3

#define in4 8   // Motor2 (Left Motor) Input 4

#define enA 5   // Enable Pin for Motor1 (Right Motor) - PWM

#define enB 6   // Enable Pin for Motor2 (Left Motor) - PWM

// Define IR sensor pins

#define R_S A0  // Right IR sensor

#define L_S A1  // Left IR sensor

// Define speed variable

int speed = 100; // Speed for both motors (0-255)

void setup() {

 // Set sensor pins as input

 pinMode(R_S, INPUT);

 pinMode(L_S, INPUT);

 // Set motor control pins as output

 pinMode(in1, OUTPUT);

 pinMode(in2, OUTPUT);

 pinMode(in3, OUTPUT);

 pinMode(in4, OUTPUT);

 pinMode(enA, OUTPUT);

 pinMode(enB, OUTPUT);

 // Initialize motor speed (PWM)

 analogWrite(enA, speed); // Set initial speed for Motor1 (Right Motor)

 analogWrite(enB, speed); // Set initial speed for Motor2 (Left Motor)

 delay(1000); // Initial delay

}

void loop() {

 // Read sensor values and control motors

 if ((digitalRead(R_S) == 0) && (digitalRead(L_S) == 0)) {

   forward(); // Move forward if both sensors detect white

 }

 if ((digitalRead(R_S) == 1) && (digitalRead(L_S) == 0)) {

   turnRight(); // Turn right if right sensor detects black

 }

 if ((digitalRead(R_S) == 0) && (digitalRead(L_S) == 1)) {

   turnLeft(); // Turn left if left sensor detects black

 }

 if ((digitalRead(R_S) == 1) && (digitalRead(L_S) == 1)) {

   Stop(); // Stop if both sensors detect black

 }

}

// Function to move forward

void forward() {

 digitalWrite(in1, HIGH); // Right Motor forward

 digitalWrite(in2, LOW);

 digitalWrite(in3, LOW);  // Left Motor forward

 digitalWrite(in4, HIGH);

 analogWrite(enA, speed); // Set speed for Right Motor

 analogWrite(enB, speed); // Set speed for Left Motor

}

// Function to turn right

void turnRight() {

 digitalWrite(in1, LOW);  // Right Motor backward

 digitalWrite(in2, HIGH);

 digitalWrite(in3, LOW);  // Left Motor forward

 digitalWrite(in4, HIGH);

 analogWrite(enA, speed); // Set speed for Right Motor

 analogWrite(enB, speed); // Set speed for Left Motor

}

// Function to turn left

void turnLeft() {

 digitalWrite(in1, HIGH); // Right Motor forward

 digitalWrite(in2, LOW);

 digitalWrite(in3, HIGH); // Left Motor backward

 digitalWrite(in4, LOW);

 analogWrite(enA, speed); // Set speed for Right Motor

 analogWrite(enB, speed); // Set speed for Left Motor

}

// Function to stop

void Stop() {

 digitalWrite(in1, LOW); // Right Motor stop

 digitalWrite(in2, LOW);

 digitalWrite(in3, LOW); // Left Motor stop

 digitalWrite(in4, LOW);

 analogWrite(enA, 0); // Set speed for Right Motor to 0

 analogWrite(enB, 0); // Set speed for Left Motor to 0

}

Testing it Out

بعد رفع الكود البرمجي، قم بوضع الروبوت على أي مسار به خط باللون الأسود ستجد أن الروبوت يتتبع الخط ولا يبعد عنه يميناً أو يساراً.

Resources

No items found.