The KY-033 line tracking sensor module helps your robot follow a black line on a light-colored surface. This tutorial will guide you through connecting and using the KY-033 with Arduino to build a simple line following robot.
Specs
- Working Voltage: DC 3.3V-5V
- Working Current: ≥ 20mA
- Operating Temperature: -10°C to +50°C
- Detection Distance: 2-40cm
- Output Signal: TTL level (low level when there is an obstacle, high when there is no obstacle)
- Adjustment: The module has a multi-turn resistance knob to adjust sensitivity.
- Effective Angle: 35°
.
Arduino Uno
Breadboard
KY 033 Line tracker
LED
Jumper wires
#define sensor 4 //define a const. variable named "sensor" with value 4, this value refers to D4 pin. #define led 13 //define a const. variable named "led" with value 2, this value refers to D13 pin. int sensorReading; //create an integer variable named "sensorReading" to hold the sensor reading value inside. void setup() { pinMode(sensor, INPUT); //set the sensor pin as an INPUT pin. pinMode(led, OUTPUT); //set the led pin as an OUTPUT pin. Serial.begin(9600); //start the hardware serial communication. } void loop() { sensorReading = digitalRead(sensor); //save the sensor reading value inside the "sensorReading" variable. Serial.print("Line Color Is "); //print "Line Color Is " on the Serial Monitor for easu debugging. if(sensorReading == LOW){ //if there is a black line turn on the led, and print "BLACK" on the serial monitor. digitalWrite(led, LOW); Serial.println("WHITE"); } else{ //if there is a white line turn off the led, and print "WHITE" on the serial monitor. digitalWrite(led, HIGH); Serial.println("BLACK"); } }
Arduino Uno
Breadboard
L298n Motor Driver
KY 033 Line tracker 2Pcs
Cables
Motors 2Pcs
#define enA 6//Enable1 L298 Pin enA
#define in1 5 //Motor1 L298 Pin in1
#define in2 4 //Motor1 L298 Pin in1
#define in3 3 //Motor2 L298 Pin in1
#define in4 2 //Motor2 L298 Pin in1
#define enB 9 //Enable2 L298 Pin enB
#define R_S A4 //ir sensor Right
#define L_S A5 //ir sensor Left
void setup(){ // put your setup code here, to run once
pinMode(R_S, INPUT); // declare if sensor as input
pinMode(L_S, INPUT); // declare ir sensor as input
pinMode(enA, OUTPUT); // declare as output for L298 Pin enA
pinMode(in1, OUTPUT); // declare as output for L298 Pin in1
pinMode(in2, OUTPUT); // declare as output for L298 Pin in2
pinMode(in3, OUTPUT); // declare as output for L298 Pin in3
pinMode(in4, OUTPUT); // declare as output for L298 Pin in4
pinMode(enB, OUTPUT); // declare as output for L298 Pin enB
analogWrite(enA, 120); // Write The Duty Cycle 0 to 255 Enable Pin A for Motor1 Speed
analogWrite(enB, 120); // Write The Duty Cycle 0 to 255 Enable Pin B for Motor2 Speed
delay(1000);
}
void loop(){
if((digitalRead(R_S) == 0)&&(digitalRead(L_S) == 0)){forword();} //if Right Sensor and Left Sensor are at White color then it will call forword function
if((digitalRead(R_S) == 1)&&(digitalRead(L_S) == 0)){
turnRight();
delay(10);
turnRight();
} //if Right Sensor is Black and Left Sensor is White then it will call turn Right function
if((digitalRead(R_S) == 0)&&(digitalRead(L_S) == 1)){
turnLeft();
delay(10);
turnLeft();
} //if Right Sensor is White and Left Sensor is Black then it will call turn Left function
if((digitalRead(R_S) == 1)&&(digitalRead(L_S) == 1)){Stop();} //if Right Sensor and Left Sensor are at Black color then it will call Stop function
}
void forword(){ //forword
digitalWrite(in1, HIGH); //Right Motor forword Pin
digitalWrite(in2, LOW); //Right Motor backword Pin
digitalWrite(in3, LOW); //Left Motor backword Pin
digitalWrite(in4, HIGH); //Left Motor forword Pin
}
void turnRight(){ //turnRight
digitalWrite(in1, LOW); //Right Motor forword Pin
digitalWrite(in2, HIGH); //Right Motor backword Pin
digitalWrite(in3, LOW); //Left Motor backword Pin
digitalWrite(in4, HIGH); //Left Motor forword Pin
}
void turnLeft(){ //turnLeft
digitalWrite(in1, HIGH); //Right Motor forword Pin
digitalWrite(in2, LOW); //Right Motor backword Pin
digitalWrite(in3, HIGH); //Left Motor backword Pin
digitalWrite(in4, LOW); //Left Motor forword Pin
}
void Stop(){ //stop
digitalWrite(in1, LOW); //Right Motor forword Pin
digitalWrite(in2, LOW); //Right Motor backword Pin
digitalWrite(in3, LOW); //Left Motor backword Pin
digitalWrite(in4, LOW); //Left Motor forword Pin
}
I used to be suggested this website by means of my cousin. I am no
longer certain whether or not this submit is written by way
of him as nobody else realize such unique about my
problem. You are incredible! Thanks!
My blog; american style fridge freezer lg