0% found this document useful (0 votes)
4 views

Arduino_Code_LFR_Drug_Transport

This document provides Arduino code for a line follower robot (LFR) designed for drug transport, utilizing three infrared sensors to navigate a black line on a white surface. The code defines sensor and motor driver pins, and includes functions to move forward, turn left, turn right, and stop based on sensor inputs. The robot's behavior is determined by reading the states of the left, center, and right sensors.

Uploaded by

ademasfaw222
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Arduino_Code_LFR_Drug_Transport

This document provides Arduino code for a line follower robot (LFR) designed for drug transport, utilizing three infrared sensors to navigate a black line on a white surface. The code defines sensor and motor driver pins, and includes functions to move forward, turn left, turn right, and stop based on sensor inputs. The robot's behavior is determined by reading the states of the left, center, and right sensors.

Uploaded by

ademasfaw222
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Arduino Code for Line Follower Robot

(LFR) for Drug Transport


This Arduino code is designed for a line follower robot (LFR)
using three infrared (IR) sensors positioned on the left, center,
and right of the robot's base. The robot follows a black line on
a white surface, making decisions to move forward, turn left,
turn right, or stop based on the sensor inputs.

Sensor Pins:
- Left: D2
- Center: D3
- Right: D4

Motor Driver Pins:


- Left Motor: D5 (forward), D6 (backward)
- Right Motor: D9 (forward), D10 (backward)

// Define sensor pins


const int leftSensor = 2;
const int centerSensor = 3;
const int rightSensor = 4;

// Define motor pins


const int leftMotorForward = 5;
const int leftMotorBackward = 6;
const int rightMotorForward = 9;
const int rightMotorBackward = 10;

void setup() {
pinMode(leftSensor, INPUT);
pinMode(centerSensor, INPUT);
pinMode(rightSensor, INPUT);
pinMode(leftMotorForward, OUTPUT);
pinMode(leftMotorBackward, OUTPUT);
pinMode(rightMotorForward, OUTPUT);
pinMode(rightMotorBackward, OUTPUT);
}

void loop() {
int L = digitalRead(leftSensor);
int C = digitalRead(centerSensor);
int R = digitalRead(rightSensor);

if (L == 0 && C == 1 && R == 0) {
moveForward();
}
else if ((L == 1 && C == 0 && R == 0) || (L == 1 && C == 1 && R
== 0)) {
turnLeft();
}
else if ((L == 0 && C == 0 && R == 1) || (L == 0 && C == 1 && R
== 1)) {
turnRight();
}
else if (L == 1 && C == 1 && R == 1) {
stopMotors();
}
else {
moveForward();
}
}

void moveForward() {
digitalWrite(leftMotorForward, HIGH);
digitalWrite(leftMotorBackward, LOW);
digitalWrite(rightMotorForward, HIGH);
digitalWrite(rightMotorBackward, LOW);
}

void turnLeft() {
digitalWrite(leftMotorForward, LOW);
digitalWrite(leftMotorBackward, LOW);
digitalWrite(rightMotorForward, HIGH);
digitalWrite(rightMotorBackward, LOW);
}

void turnRight() {
digitalWrite(leftMotorForward, HIGH);
digitalWrite(leftMotorBackward, LOW);
digitalWrite(rightMotorForward, LOW);
digitalWrite(rightMotorBackward, LOW);
}

void stopMotors() {
digitalWrite(leftMotorForward, LOW);
digitalWrite(leftMotorBackward, LOW);
digitalWrite(rightMotorForward, LOW);
digitalWrite(rightMotorBackward, LOW);
}

You might also like