Electronic projects

[Electronic projects][bleft]

Arduino Projects

[Arduino Projects][bleft]

Metal detectors

[Metal detectors][bleft]

Home projects

[Home projects][bleft]

Tracking robot using AVR microcontroller ATmega16

 In this article, we will use the AVR Atmega16 microcontroller to make another small tool. If you are new to AVR microcontrollers, then you can refer to the previous AVR projects and tutorials .

Making a robot is a challenge for all electronics enthusiasts. If the robot can automatically perform certain operations without any external instructions, then this challenge can be maximized. One of the robots most often made by electronic beginners is the tracking robot. As the name suggests, the robot will follow the lines drawn on the surface. The line need not be a straight line. In addition, the line can be any color.


Most infrared sensors are used to detect lines. The infrared sensor can detect white or black surfaces very well. Although you can use other complex sensors that can detect all colors, and you can make a robot that can follow all color lines. Even if you change the path by changing the angle and keep following the line, the robot should be able to detect the line. In addition, it should stop at any point where the stop zone enters the line.


Tracking robots are now widely used in manufacturing, medical, household applications and cargo warehouses. Robots are not limited to these applications, and can expand their applications in many future applications.


The concept of tracking robots

The infrared sensor is a key component of the project. An infrared sensor is placed on the front side of the robot to track the drawn black lines and surfaces. The robot is placed between the lines. With the help of IR sensors, the robot can track the lines. The infrared sensor feeds the reading back to the microcontroller, and with the help of the infrared reading, the microcontroller moves the motor to the left or right and brings the robot to the path again.


The tracking robot can track the line with the help of IR sensors. The sensor has an infrared transmitter and an infrared receiver. The IR transmitter (IR LED) emits light, and the receiver (photodiode) waits for the emitted light to return. Only when the surface reflects, the infrared light returns. However, all surfaces do not reflect infrared light, only the white color surface can completely reflect them, and the black surface will completely absorb them, as shown in the figure below.


Now we will use two infrared sensors to check whether the robot is tracking along with the line. If the robot moves out of the track, two motors are needed to calibrate the robot. These motors require large currents and should be bidirectional; therefore we use motor drive modules like L293D. We also need a microcontroller like ATmega16 to indicate the motor based on the value of the infrared sensor. The simplified block diagram is shown below.
 
The two infrared sensors will be placed on both sides of the line. If no sensor detects the black line, the AVR microcontroller instructs the motor to move forward, as shown below.


If a black line appears on the left sensor, the microcontroller instructs the robot to turn left by individually rotating the right wheel.

 

If a black line appears on the right sensor, the microcontroller instructs the robot to turn right by individually rotating the left wheel.



If both sensors are black lines, the robot stops.



In this way, the robot will be able to follow the line without leaving the track. Now let us see what the circuit and code look like.


Required components

● DC geared motors (2 units)

● Infrared sensor module (2 units)

● L293D module

● Wireless power (such as battery, mobile power)

● Robot base

● Atmega16 microcontroller IC

● Jumper

● Breadboard

● USBASP v2.0

 Circuit schematic

Connect all components as shown in the figure below


Programming Atmega16 for tracking robots

Atmega16 uses USBASP and Atmel Studio7.0 for programming. If you don't know how to program Atmega16 with USBASP, please visit this link. The completed program is given at the end of the project, just use the JTAG programmer and Atmel Studio 7.0 to upload the program in Atmega16, as described in the previous tutorial.


We try our best to keep the code concise and clear. So we use macros and special function registers in this code.

  1. if(bit_is_clear(PINA,leftSen)){ // check if left sensor is OFF
Copy code

This statement checks whether the PA0 connected to the left sensor is low or high.

We have four conditions to read the infrared sensor. The infrared sensors are named according to their position on the front side of the robot. The left IR is the left sensor, and the right IR is the right sensor. The following conditions will determine the movement of the robot.

We wrote the code based on the above conditions. The only change is that we only use the two input pins of L293D to drive two motors.

Code

The complete code for this article is given below.

  1. /* Line Follower Robot Using Atmega16
  2.    Circuit Digest(www.circuitdigest.com) */

  3. #include<avr/io.h>
  4. #define leftSen PA0 //Connect Left Sensor At PA0
  5. #define rightSen PA1 //Connect Right Sensor At PA1

  6. int main(void)
  7. {
  8. DDRA=0xFC; // make PA0,PA1 as input for both sensors 0x0b11111100
  9. DDRC=0xFF; // make Port as output to connect motor pins

  10. while(1)
  11. {
  12. PINA=0x03; //initialize PA0 and PA1
  13. if(bit_is_clear(PINA,leftSen)){ // check if left sensor is OFF

  14.    if(bit_is_clear(PINA,rightSen)) {// check if right sensor is OFF
  15.     PORTC=0b00000000; // if both sensor zero
  16.     } // then stop the robot
  17.    else{
  18.     PORTC=0b00000001; // if right is ON then take left
  19.   }
  20. }

  21. else // check if left sensor in ON
  22. {
  23.    if(bit_is_clear(PINA,rightSen)) {// check if right sensor is OFF
  24.     PORTC=0b00000010; // it means left sensor is ON
  25. } // so take right
  26.    else{
  27.     PORTC=0b00000011; // if both sensor is ON
  28.        } // then keep moving the robot
  29.     }
  30.    }
  31. }
Copy code


 

No comments:

Comments

Arduino Projects

[Arduino Projects][twocolumns]