基于arduino的5路循迹小车(2)
小车5路红外循线
接第一篇链接 https://blog.csdn.net/weixin_45984029/article/details/103437347
1.硬件选用
5个红外循迹模块(推荐这种,性价比较高)
2.接线
VCC接开发板3.3V
GND接开发板GND
D0接开发板信号口(具体位置对应代码)
A0不接
3.代码
int Left_motor_go1 = 24; //左电机前进 AIN1
int Left_motor_back1 = 25; //左电机后退 AIN2
int Right_motor_go1 = 22; //右电机前进 BIN1
int Right_motor_back1 = 23; //右电机后退 BIN2
int Left_motor_pwm1 = 3; //左电机控速 PWMA1
int Right_motor_pwm1= 5; //右电机控速 PWMB1
int Left_motor_pwm2 = 4; //左电机控速 PWMA2
int Right_motor_pwm2= 6; //右电机控速 PWMB2
//循迹红外引脚定义
//TrackSensorLeftPin1 TrackSensorLeftPin2 TrackSensorMid TrackSensorRightPin1 TrackSensorRightPin2
// A1 A2 A3 A4 A5
const int TrackSensorLeftPin1 = A1; //定义第一个循迹红外传感器引脚为A1
const int TrackSensorLeftPin2 = A2; //定义第二个循迹红外传感器引脚为A2
const int TrackSensorMid = A3; //定义第三个循迹红外传感器引脚为A3
const int TrackSensorRightPin1 = A4; //定义第四个循迹红外传感器引脚为A4
const int TrackSensorRightPin2 = A5; //定义第五个循迹红外传感器引脚为A5
//定义各个循迹红外引脚采集的数据的变量
int SLL;
int SL;
int SM;
int SR;
int SRR;
void setup()
{
//初始化电机驱动IO口为输出方式
pinMode(Left_motor_go1, OUTPUT);
pinMode(Left_motor_back1, OUTPUT);
pinMode(Right_motor_go1, OUTPUT);
pinMode(Right_motor_back1, OUTPUT);
//定义四路循迹红外传感器为输入接口
pinMode(TrackSensorLeftPin1, INPUT);
pinMode(TrackSensorLeftPin2, INPUT);
pinMode(TrackSensorMid,INPUT);
pinMode(TrackSensorRightPin1,