在这篇文章中,我们学习了如何使用Arduino构建线路追随者机器人电路,该机器人将在特定绘制的线路布局上运行,并将忠实地遵循它,只要它可以通过其传感器提供并可以追溯。
By Navneet Sajwan
什么是线路追随者机器人
An autonomous robot is a machine that can take a series of actions as instructed by the programmer, without being manually controlled by a human being in real-time.
线路追随者(LFR)也是自动驾驶机器人车,由一个或多个传感器和黑色或白色线路指导。它们构成了现代自动驾驶汽车的基础。
Like every autonomous robot , line followers have a signal processing and decision making unit , sensors and actuators. If you are a beginner in robotics and want to take it up seriously, this is where you should start. Let’s begin making it.
I have used two infra-red sensors and three wheel drive for making this project. Minimum number of sensors that can be used is one and maximum of eight are sufficient for PID based line following.
Components Required:
Arduino Uno
Chassis
两个电池(b.o。)电动机和兼容轮胎
Castor ball
两个红外传感器
电机驱动器模块
Power Supply
Arduino IDE software
Now, let’s have a look at our components:
Arduino Uno:Imagine it as the control room of our robot .Now, there are a lot many development boards, that were considered for this project, but Arduino UNO was simply no match to others. It isn't that our protagonist was superior in terms of its multidimensional features.
如果是这种情况,Raspberry Pi和Intel Edison会在眼睛之间击打它。导致Arduino Uno选择的最引人注目的论点是由项目,价格,规模和要求的组合形成的。
Some relevant reasons were:
尺寸:It is quite small compared to Atmega16 or Atmega8 based development boards, consumes a little space on chassis, so you get a compact and handy bot.
这在机器人竞赛中确实很重要。相信我,您讨厌整天漫游的机器人漫游,改变场地。
尺寸较小,机器人更快,转弯更有效。
BEST PROTOTYPING BOARD:Undoubtedly, Arduino UNO has the best combination of features for原型。一旦你的电路是在地方和您的项目works perfect you can replace it with something smaller and cheaper like Arduino Nano and Attiny85 ic.
For those ,making line follower for college projects , I suggest replacing UNO with Nano at the end.
机壳:It is the frame that holds the all the components in position. There are a few points to consider while buying a new chassis ,
It should be lightweight and strong.
For projects, it's better if you buy one from market. But If you are preparing for competition, I strongly suggest you customize your own ,keeping in mind the dimensions and the requirements of the competition.
Choose a plastic or wooden chassis. When metallic frames come in contact with Arduino , a number of pins get shorted. This is a big factor to focus on while looking out for chassis.
Keep your chassis as low as possible - this gives stability to the bot.
马达S:Use light weight battery operated (B.O.) d.c. motors.
CASTOR BALL:Normal wheels provide translatory motion along a single axis but a castor ball is designed to move along any direction on surface. It gives us three wheel drive.
偏爱三轮驱动超过4轮的原因是由于其相对更快的转动动作。您可能已经注意到人力车在爬行动物等交通中刺穿。我们的机器人也是如此。
SENSORS:It is a device that detects or measures any physical parameter of our environment and converts it into electric signals. In this case the parameter detected is infra-red rays.
Sensors are highly fundamental for any robot. Well, if arduino is our bot’s brain, sensors might as well play the role of eyes. Here are a few things about sensors:
传感器必须以导致面部地面的方式定向。
Should be placed at the front end of your bot.
Minimum spacing between them must be greater than the width of the black line.
马达DRIVER BOARD:Motor-drivers are buffer circuits that take up low voltage signals to power up the motors that require higher voltage.
在我们的情况下,Arduino可以提供足够的电压来驱动电动机,但不能提供充足的电流。Arduino Uno的5V和GND引脚的当前评级为200mA,而任何GPIO PIN的评级为40 MA。这比我们需要的启动和失速电流电动机低。
There are two motor drivers that I prefer for this project: L298N and L293D. Both of them are equally suitable for making this project.
Though,L293D相对便宜但是电流等级低。他们的连接几乎相同。由于,我已经给出了两者的联系,因此完全取决于您如何制作机器人。
POWER SUPPLY:
Use a 12 v adapter or a battery (not more than 12 volts).
Placement of components (from front to back end):
传感器在机器人头部。
中间的蓖麻轮。
Motors and tyres in one line at the back.
Connections:
SENSORS to ARDUINO:
Connect the sensor pin to arduino pin as shown,
| 传感器引脚 | Arduino pin |
| VCC(5v) | 5V |
| gnd(g) | gnd |
| 剩下SENSOR OUT(DO) | pin 6 |
| RIGHT SENSOR OUT(DO) | pin 7 |
Note :To check if your sensors are powered up, point your cell phone camera at the IR transmitter led. You will see led glowing on screen which cannot be seen by our naked eyes. Some modern cell phone cameras have Infra red filter. So, please take that into account.
马达to MOTOR DRIVER:
Each motor has two terminals which need to be connected to motor driver. Never try to connect them directly to arduino. Looking from the back of your bot , with motors near to you and sensors away, connect them as follows:
| 马达 | L298N | L293D |
| 左马达 | 引脚1和2 | PIN 7 AND 8 |
| RIGHT MOTOR | 引脚13AND 14 | PIN 9 AND 10 |
马达DRIVER to ARDUINO UNO:
| 马达DRIVER(L298N) | Arduino Uno |
| 引脚4 | Vin |
| 引脚5 | gnd |
| 引脚6 | 5V |
| PIN 8 & PIN 9 | 引脚3& PIN 9 |
| 引脚10& PIN 11 | 引脚5& PIN 10 |
| PIN 7 & PIN 12 | 5V |
| 马达DRIVER(L293D) | Arduino Uno |
| 引脚3 | Vin |
| 引脚2 | gnd |
| 引脚1 | 5V |
| 引脚5和引脚6 | 引脚3& PIN 9 |
| 引脚11和引脚12 | 引脚5& PIN 10 |
| 引脚4AND PIN 5 | 5V |
注意:L298N的PINS 8和9用于控制连接到1和2的电动机。并且,连接到销钉13和14的10和11控制电动机。相似地,使用L293D的PINS 5和6用于控制连接到连接到的电动机7和8和12和11控制电动机连接到销钉9和10。
Here we are guys, to the end of the design part. We still have the coding to do but before that we will go through the principles that allow line-following.
红色传感器如何工作:
红色传感器(IR传感器)可用于感知颜色和物体接近的对比度。IR传感器工作器工作后的原理非常基本。
如我们所见,它具有两个LED - 发射LED和一个光电二极管。它们充当发射机收益对。当障碍物在发射器射线的前面时,它们会反射回并被接收器拦截。
This generates a digital signal which can be fed to microcontrollers and actuators to take necessary action on encountering obstacle.
基本物理学告诉我们,黑体会吸收所有电磁辐射,而白色体反映了它。该原理是通过线路追随者来区分白色和黑色表面的。
How a line follower robot works:
In normal condition, the robot moves in such a way that both the sensors are over white and the black line is amidst the both sensors.
It is programmed to rotate both the motors such that the bot moves in forward direction.
很自然,随着时间的流逝,两个传感器之一越过黑色线路。
如果left sensor comes over the line, left motors are brought to rest and as a result bot begins turning towards left unless the left sensor comes back on white surface and normal condition is achieved.
Similarly, when right sensor comes over black line, right motors are stopped and consequently bot now turns towards right unless the sensor comes back over white surface. This mechanism of turning is known as differential drive mechanism.
CIRCUIT DIAGRAM:
接线详细信息:
PROGRAMMING AND CONCEPTS:
Having done with the circuit part, we will now move on to the programming part . In this section, we will understand the program that controls our robot. Here is the code:/*Created and tested by Navneet Singh Sajwan
*基于两个传感器的数字输出
*Speed control added
*/
int left, right;
int value=250;
void setup()
{
pinMode(6,INPUT);//left sensor
pinMode(7,INPUT);//right sensor
pinMode(9,OUTPUT);//left motor
pinMode(3,OUTPUT);//left motor
pinmode(10,输出); //右电动机
pinmode(5,输出); //右电动机
//Serial.begin(9600);
}
void read_sensors()
{
左= DigitalRead(6);
right= digitalRead(7);
}
void move_forward()
{
模拟值(9,值); // 3,9左电动机
digitalWrite(3,LOW);
analogWrite(10,value);//10,5 for right motor
digitalWrite(5,LOW);
}
void turn_left()
{
digitalWrite(9,LOW);//9,3 for left motor
digitalWrite(3,LOW);
analogWrite(10,value);//10,5 for right motor
digitalWrite(5,LOW);
}
void turn_right()
{
analogWrite(9,value);// 9,3 for left motor
digitalWrite(3,LOW);
digitalWrite(10,LOW);// 10,5 for right motor
digitalWrite(5,LOW);
}
void halt()
{
digitalWrite(9,LOW);// 9,3 for left motor
digitalWrite(3,LOW);
digitalWrite(10,LOW);// 10,5 for right motor
digitalWrite(5,LOW);
}
void print_readings()
{
serial.print(“ leftsensor”);
Serial.print("\t");
Serial.print(left);
Serial.print("rightsensor");
Serial.print("\t");
Serial.print(right);
Serial.println();
}
void loop()
{
read_sensors();
while((left==0)&&(right==1)) // left sensor is over black line
{
turn_left();
read_sensors();
print_readings();
}
while(((lest == 1)&&(右== 0))//右传感器在黑线上
{
turn_right();
read_sensors();
print_readings();
}
while((left==0)&&(right==0)) // both sensors over the back line
{
halt();
read_sensors();
print_readings();
}
while((left==1)&&(right==1))// no sensor over black line
{
move_forward();
read_sensors();
print_readings();
}
}
所用功能的描述:
read_sensors(): It takes the readings of both the sensors and stores them in the variables left and right.
move_forward(): When the arduino executes this function , both the motors move in the forward direction.
turn_left():Left motor stops. Bot turns left.
turn_right():右电动机停止。机器人向右转。
halt():机器人停止。
print_readings():在串行显示器上显示传感器的读数。为此,您必须在Void设置中取消注释“ serial.begin(9600)”。
传感器读数:
| 传感器在线 | SENSOR READINGS | |
| 剩下 | RIGHT | |
| 剩下SENSOR | 0 | 1 |
| RIGHT SENSOR | 1 | 0 |
| NONE | 1 | 1 |
| BOTH | 0 | 0 |
SPEED CONTROL:
有时,电动机的速度是如此之高,以至于在Arduino解释传感器信号之前,机器人失去了线路。简而言之,由于高速,机器人不会遵循线路,并且即使算法正确,也不会损失线路。
为了避免这种情况,我们使用PWM技术降低了机器人的速度。在上面的代码中,有一个变量命名值。
只需降低函数中的数值即可降低速度。在Arduino Uno中,您只能在0到255之间具有PWM值。
analogWrite(pin, value)
0< = value <=255
This the end of my post on line follower. I hope it is detailed enough to answer all your burning queries and if in the rarest reality it is not, then we always have the comment section available for you. Comment your doubts out. Have a happy tinkering!
I’m wondering if you would help me I want to build a smart dustbin for my final year project using line follower robot but it should only start following line when the dustbin is full (using ultrasonic sensor module) and return to it’s origin when it is cleaned. Hoping to get reply!
谢谢你。
您能否详细说明垃圾箱和线路追随者应该如何固定和操作?
灰尘箱将安装在机器人上,并将超声模块放置在垃圾箱盖下方。
The ultrasonic module should give the input to the motors so that the dustbin only moves when the dustbin is full
超声波传感器电路和线路追随者电路都很容易在网上提供,唯一需要完成的是整合两者,可以使用晶体管驱动器电路进行。
just feed the ultrasonic circuit output to a transistor relay driver, and wire the relay contacts with the line follower supply line. Once this is done, the system will start responding as required by you.
可以通过参考以下文章来进行中继驱动器阶段:
//www.addme-blog.com/how-to-make-relay-driver-net//
您可以将电路图和源代码发送给我吗
I’ll try
所示的连接需要修正。如果it is followed as it is, the programmer will get the board’s burnt. Pl don’t publish such wrong drawings.
I have informed the author about this comment, I hope he will respond soon
Please specify what is wrong in the circuit. I will surely make amends if required.