Arduino Projects

Arduino Uno for a simple tracking robot

The Line Follower Robot (LFR) is a relatively simple autonomous guided robot. It can follow a line drawn on the ground and detect black lines on a white surface or white lines on a black surface. Tracking robot is a very interesting project. In this article, we will learn how to use the Arduino Uno development board and some common components to make a tracking robot. Does it sound interesting? let’s start.


The working principle of tracking robot

As mentioned earlier, the tracking robot follows a line. In order to follow a line, the robot must first detect the line. The question now is how to implement a line sensing mechanism in a tracking robot. We all know that because the black surface absorbs the largest amount of light, the white surface reflects the most light, and the black surface reflects the least. Therefore, we will use this characteristic of light to detect lines. To detect the brightness of the light, you can use a photoresistor LDR or infrared IR sensor. In this article, we will use an IR sensor because it has higher accuracy. In order to detect the trace, we placed two infrared sensors, one of which is on the left side of the robot and the other on the right side of the robot. Then we put the robot on the line so that the line is in the middle of the two sensors.


The infrared sensor consists of two components, a transmitter and a receiver. The transmitter is an infrared LED, which generates a signal, and the infrared receiver is a photodiode, which senses the signal generated by the transmitter. The infrared sensor emits infrared light to the object, and the light that encounters the black part is absorbed, resulting in a low output, but the light that encounters the white part is reflected back to the transmitter and then detected by the infrared receiver to provide an analog output. Using the above principle, we control the movement of the robot by driving the wheels connected to the motor, which is controlled by the microcontroller.


How does the tracking robot navigate?

A typical tracking robot has two sets of motors, we call them the left motor and the right motor. The two motors respectively rotate according to the signals received by the left and right sensors. The robot needs to perform 4 sets of movements, including forward, left turn, right turn and stop. These situations are explained separately below.


go ahead:

In this case, when both sensors are on the white surface and the line is between the two sensors, the robot should move forward, that is, both motors should rotate to make the robot move forward.


Turn left:

 

In this case, the left sensor is above the black line and the right sensor is in the white part, so the left sensor detects the black line and sends a signal to the microcontroller. Since the signal comes from the left sensor, the robot should turn to the left. Therefore, the left motor rotates backward, and the right motor rotates forward. Therefore, the robot turns to the left.

 

Turn right:


This situation is similar to the left turn situation, but in this case, only the right sensor detects the line, which means the robot should turn in the correct direction. In order to make the robot rotate to the right, the left motor rotates forward and the right motor rotates backward, so that the robot turns to the right.


stop:

In this case, both sensors are located in front of the line and they can detect the black line at the same time, and the microcontroller is fed to treat this situation as a stop process. Therefore, both motors stop, which causes the robot to stop moving.

 

Required components

● Arduino Uno development board

●    L293D motor driver

● Infrared sensor module

● 7.4 or 9V battery

● Motor

● Robot chassis

● Wire

Connection principle diagram


The circuit is mainly composed of four parts: two infrared sensors, a motor driver, two motors, an Arduino, a battery and several connecting wires. The sensor senses the infrared light reflected from the surface and feeds the output to the on-board operational amplifier comparator. When the sensor is on a white background, the light emitted by the sensor is reflected by the white ground and received by the receiver. But when the sensor is above a black background, the light from the light source will not be reflected on it. The sensor senses the intensity of the reflected light to provide an output. The output of the sensor is fed to the microcontroller, which issues commands to the motor driver to drive the motor accordingly. In this article, the Arduino Uno makes the robot move forward, turn right or left, and stop based on the input from the sensor. The output of the Arduino is connected to the motor driver.


Assemble the tracking robot

After understanding the connections of all the components, we can begin to assemble the tracking robot. To make this robot, first we need a robot chassis. In this article, I use a self-made chassis. You can use a ready-made chassis or assemble it yourself.


Now, place the motor on the chassis with hot melt glue, as shown in the figure below. The next step is to place the motor driver on the chassis and connect the motor wire to the output of the motor driver.Next, solder the infrared sensor as shown.

 


Then put the sensor on the bottom of the robot and adjust the sensor according to the width of the track and the width of the robot. Remember, one sensor is used for left side detection and the other is used for right side detection.

Connect the VCC pin to 5V and the GND pin to ground.

Now, connect the enable pin of the motor driver to pins 5 and 8 of the Arduino, and connect the motor driver input pins to pins 6, 7, 9 and 10 of the Arduino, respectively.

Finally, connect the battery to the circuit and place the battery on the chassis. Now turn the chassis upside down and use hot melt glue to install the casters, as shown in the figure below.

Arduino tracking robot code

The programming part of the tracking robot is very simple, we only need the basic Arduino functions. The procedure is explained as follows.


First define each Arduino pin number we use. Start with the pins of the driver and the sensor pins. Here, I have annotated every line of code to make it easier for everyone to understand.

  1. #define enA 5 //Enable1 L293 Pin enA
  2. #define in1 6 //Motor1 L293 Pin in1
  3. #define in2 7 //Motor1 L293 Pin in1
  4. #define in3 9 //Motor2 L293Pin in1
  5. #define in4 10 //Motor2 L293 Pin in1
  6. #define enB 8 //Enable2 L298 Pin enB
  7. #define R_S 4 // Right sensor
  8. #define L_S 2 // Left sensor

Copy code


In the setup() function, declare the pin mode of each pin. We need to read the output of the infrared sensor, so these pins are defined as inputs. The motor needs to be driven by Arduino, so the motor driver pins are defined as outputs. Finally, pull the enable pin high.

  1. pinMode(R_S, INPUT);
  2. pinMode(L_S, INPUT);
  3. pinMode(enA, OUTPUT);
  4. pinMode(in1, OUTPUT);
  5. pinMode(in2, OUTPUT);
  6. pinMode(in3, OUTPUT);
  7. pinMode(in4, OUTPUT);
  8. pinMode(enB, OUTPUT);
  9. digitalWrite(enA, HIGH);
  10. digitalWrite(enB, HIGH);

Copy code


In the loop() function, we first read the value of the infrared sensor, and then use the if condition to control the movement of the motor. The four exercise conditions are explained below.


go ahead:

  1. if((digitalRead(R_S) == 0)&&(digitalRead(L_S) == 0)){forward();}

Copy code

In this case, if the right sensor and the left sensor are above the white line at the same time, the robot should move forward, then we call the forward function. (Note: 0 here means that the infrared sensor output is high, because the sensor is on the white line)


Turn to the right:

  1. if((digitalRead(R_S) == 1)&&(digitalRead(L_S) == 0)){turnRight();}

Copy code

If a black line is detected on the right side, but the left sensor does not detect any black line, the turnRight function will be called to turn to the right.


Turn to the left:

  1. if((digitalRead(R_S) == 0)&&(digitalRead(L_S) == 1)){turnLeft();}

Copy code

If the right sensor is on the white line and the left sensor detects black, it will turn the turnLeft function to the left.


stop:

  1. if((digitalRead(R_S) == 1)&&(digitalRead(L_S) == 1)){Stop();}

Copy code

If the right sensor and the left sensor are on the black line, it will call the Stop function. In this case, the robot will stop completely.


We have defined 4 functions for the robot to work, namely Forward, turnLeft, turnRight and Stop . The function code is as follows:


Forward function:

  1. void forward(){
  2. digitalWrite(in1, HIGH);
  3. digitalWrite(in2, LOW);
  4. digitalWrite(in3, LOW);
  5. digitalWrite(in4, HIGH);
  6. }

Copy code

We pull inputs 1 and 4 of the motor driver high, so both motors will move forward.

The above is the code part. Use the USB cable to connect the Arduino to the computer, and then use the Arduino IDE to upload the code.

 

Testing and calibration

We have assembled the robot and uploaded the code. Now it’s time to see how it works. If it can’t follow the line, then we need to calibrate the robot. First put the robot on the black surface (both sensors should be on top of the black surface) and then adjust the variable resistance of the infrared module until the output LED of the infrared module goes out. Next, put the robot on the white surface and check if the LED is on, if it doesn’t, you only need to adjust the variable resistor. Repeat the process again to ensure that the output LED is operating as required.

Now, since we have calibrated the robot, all we need to do is place the robot on the black line and observe its operation.


 Original post: yiboard


 

 


Related Articles

Leave a Reply

Back to top button
error: Content is protected !!