基于arduino的5路循迹小车(2)

基于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, 
  • 11
    点赞
  • 128
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值