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

Line Follower Robot

This document discusses controlling a line follower robot using Arduino. It provides code to control two DC motors connected to an L293D motor driver board to move the robot forward and turn based on sensor input. It also discusses using servo motors with the Arduino by importing the Servo library and writing angles to control servo position. Examples are given to sweep a servo from 0 to 180 degrees and control servo position with a potentiometer.

Uploaded by

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

Line Follower Robot

This document discusses controlling a line follower robot using Arduino. It provides code to control two DC motors connected to an L293D motor driver board to move the robot forward and turn based on sensor input. It also discusses using servo motors with the Arduino by importing the Servo library and writing angles to control servo position. Examples are given to sweep a servo from 0 to 180 degrees and control servo position with a potentiometer.

Uploaded by

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

Line Follower Robot

Line Follower Robot

2
Controlling a DC Motor
int vSpeed = 110; // MAX 255 void loop() {
int turn_speed = 230; // MAX 255
int turn_delay = 10; left_sensor_state = analogRead(left_sensor_pin);
right_sensor_state = analogRead(right_sensor_pin);
//L293 Connection
const int motorA1 = 8; if(right_sensor_state > 500 && left_sensor_state < 500)
const int motorA2 = 10; {
const int motorAspeed = 9; Serial.println("turning right");
const int motorB1 = 12;
const int motorB2 = 13; digitalWrite (motorA1,LOW);
const int motorBspeed = 11; digitalWrite(motorA2,HIGH);
digitalWrite (motorB1,LOW);
//Sensor Connection digitalWrite(motorB2,HIGH);
const int left_sensor_pin =A0;
const int right_sensor_pin =A1; analogWrite (motorAspeed, vSpeed);
analogWrite (motorBspeed, turn_speed);
int left_sensor_state;
int right_sensor_state; }
if(right_sensor_state < 500 && left_sensor_state > 500)
void setup() { {
pinMode(motorA1, OUTPUT); Serial.println("turning left");
pinMode(motorA2, OUTPUT);
pinMode(motorB1, OUTPUT); digitalWrite (motorA1,HIGH);
pinMode(motorB2, OUTPUT); digitalWrite(motorA2,LOW);
digitalWrite (motorB1,HIGH);
Serial.begin(9600); digitalWrite(motorB2,LOW);
3 delay(3000);
}
analogWrite (motorAspeed, turn_speed); if(right_sensor_state < 500 && left_sensor_state < 500)
analogWrite (motorBspeed, vSpeed); {
Serial.println("stop");
delay(turn_delay);
} analogWrite (motorAspeed, 0);
analogWrite (motorBspeed, 0);
if(right_sensor_state > 500 && left_sensor_state > 500)
{ }
Serial.println("going forward"); }

digitalWrite (motorA2,LOW);
digitalWrite(motorA1,HIGH);
digitalWrite (motorB2,HIGH);
digitalWrite(motorB1,LOW);

analogWrite (motorAspeed, vSpeed);


analogWrite (motorBspeed, vSpeed);

delay(turn_delay);

4
Libraries
Libraries
• The Arduino environment can be extended through the use of libraries, just like most
programming platforms. Libraries provide extra functionality for use in sketches, e.g. working with
hardware or manipulating data. To use a library in a sketch, select it from Sketch > Import Library.

6
Servo Motors
Servo Motors
• There are many types of servo motors and their main feature is the ability to precisely control the
position of their shaft. A servo motor is a closed-loop system that uses position feedback to control
its motion and final position.

8
Servo

9
Code
// Include the Servo library

#include <Servo.h>
// Declare the Servo pin
int servoPin = 3;
// Create a servo object
Servo Servo1;
void setup() {
// We need to attach the servo to the used pin number
Servo1.attach(servoPin);
}
void loop(){
// Make servo go to 0 degrees
Servo1.write(0);
delay(1000);
// Make servo go to 90 degrees
Servo1.write(90);
delay(1000);
// Make servo go to 180 degrees
Servo1.write(180);
delay(1000);
}

10
Angle Control
#include //Servo library

Servo servo_test; //initialize a servo object for the connected servo

int angle = 0;

void setup()
{
servo_test.attach(9); // attach the signal pin of servo to pin9 of arduino
}

void loop()
{
for(angle = 0; angle < 180; angle += 1) // command to move from 0 degrees to 180 degrees
{
servo_test.write(angle); //command to rotate the servo to the specified angle
delay(15);
}

delay(1000);

for(angle = 180; angle>=1; angle-=5) // command to move from 180 degrees to 0 degrees
{
servo_test.write(angle); //command to rotate the servo to the specified angle
delay(5);
}

delay(1000);
}
11
Servo with potentiometer

#include //Servo library

Servo servo_test;

int angle = 0;
int potentio = A0

void setup()
{
servo_test.attach(9);

void loop()
{
angle = analogRead(potentio);
angle = map(angle, 0, 1023, 0, 179);
servo_test.write(angle);
delay(5);
}

12
4

You might also like