arduino循迹小车
int MotorRight1=14;
int MotorRight2=15;
int MotorLeft1=16;
int MotorLeft2=17;
int MotorRPWM=3;
int MotorLPWM=5;
const int SensorLeft = 2; //左感测器輸入腳
//const int SensorMiddle= 4 ; //中感测器輸入腳
const int SensorRight = 6; //右感测器輸入腳
int SL; //左感测器狀態
//int SM; //中感测器狀態
int SR; //右感测器狀態void setup()
{ Serial.begin(9600);pinMode(MotorRight1, OUTPUT); // 腳位 14 (PWM)pinMode(MotorRight2, OUTPUT); // 腳位 15 (PWM)pinMode(MotorLeft1, OUTPUT); // 腳位 16 (PWM) pinMode(MotorLeft2, OUTPUT); // 腳位 17 (PWM)pinMode(MotorLPWM, OUTPUT); // 腳位 3 (PWM) pinMode(MotorRPWM, OUTPUT); // 腳位 5 (PWM)pinMode(SensorLeft, INPUT); //定義左感测器// pinMode(SensorMiddle, INPUT);//定義中感测器pinMode(SensorRight, INPUT); //定義右感测器
}void loop() {SL = digitalRead(SensorLeft);// SM = digitalRead(SensorMiddle);SR = digitalRead(SensorRight);if (SL == LOW&&SR==LOW)//{ digitalWrite(MotorRight1,HIGH);digitalWrite(MotorRight2,LOW);analogWrite(MotorRPWM,150);digitalWrite(MotorLeft1,HIGH);digitalWrite(MotorLeft2,LOW);analogWrite(MotorLPWM,150);} else // { if (SL == HIGH & SR == LOW)// 左黑右白, 高速左轉 { delay(1);digitalWrite(MotorRight1,HIGH);digitalWrite(MotorRight2,LOW);analogWrite(MotorRPWM,130);digitalWrite(MotorLeft1,LOW);digitalWrite(MotorLeft2,LOW);}else if (SR == HIGH & SL == LOW) // 左白右黑, 高速右轉{ delay(1); digitalWrite(MotorRight1,LOW);digitalWrite(MotorRight2,LOW);digitalWrite(MotorLeft1,HIGH);digitalWrite(MotorLeft2,LOW);analogWrite(MotorLPWM,130);}else // 都是白色, 停止{ digitalWrite(MotorRight1,LOW);digitalWrite(MotorRight2,LOW);digitalWrite(MotorLeft1,LOW);digitalWrite(MotorLeft2,LOW);;}}}
转载于:https://www.cnblogs.com/mengfanrong/p/5209165.html
arduino循迹小车相关推荐
- Arduino循迹小车教程四----代码篇
文章目录 一.完整的代码 二.循迹代码详解 1.循迹的原理 2.判断情况 3.调速代码 4.循迹代码 5.调试问题 总结 代码分享给同学们啦,在同学们运行小车的过程中,总会遇见各种奇怪的情况,比如小车 ...
- Arduino循迹小车教程一----材料篇
文章目录 前言 1.亚克力板*1片 2.T型支架*2个 3.双轴直流减速电机*4 4.杜邦线*n条 5.M3螺柱*50 6.2.54mm排针排母*1把 7.黑工胶布*1卷 8.TCRT5000循迹模块 ...
- Arduino循迹小车(三路红外)
利用红外线传感器让小车在规定路线上行进 1. 所需材料 小车车架及车轮(可以用sw建模然后利用3D打印机打印,也可以在网上直接购买小车地板,用纸板最廉价O(∩_∩)O哈哈~) 该图为3D打印效果 Ar ...
- 基于Arduino3路循迹小车
本人西伯利亚蟑螂,最近抽空回顾了一下arduino,顺手做了个arduino循迹小车 (条件所限我的小车为两驱三路循迹模块小车) 话不多说,先上干货. #define STOP 0 #def ...
- arduino黑线循迹小车程序_循迹小车:给我一条线,我能自己走完全程
在老少通吃的智能小车到底是什么呢?科普来喽!一文中,我们介绍了智能小车的分类及组成,为什么循迹小车能够追踪黑线轨迹呢? 智能小车在画有黑线的白纸 "路面"上行驶,由于黑线和白纸对光 ...
- 基于arduino的5路循迹小车(1)
基于arduino的5路循迹小车(1) 初步小车运动 1.硬件选用 1.开发板使用arduino 2560 2.电机驱动板使用 大功率电机驱动板(PWM由两个端子控制) 3.电源12V锂电池 4.降压 ...
- 基于arduino的5路循迹小车(2)
基于arduino的5路循迹小车(2) 小车5路红外循线 接第一篇链接 https://blog.csdn.net/weixin_45984029/article/details/103437347 ...
- ARDUINO NANO 的 PID 循迹小车
[Arduino项目]使用 ARDUINO NANO 的 PID 循迹小车 -------------------------------------------------------------- ...
- 基于arduino的5路循迹小车(4)与舵机控制板的通信控制
基于arduino的5路循迹小车(4) arduino与舵机控制板的通信控制 以及语音播报模块 接第一篇链接 https://blog.csdn.net/weixin_45984029/article ...
- 基于arduino的5路循迹小车(3)
基于arduino的5路循迹小车(3) 使用红外模块的定位停车 以及超声波避障 接第一篇链接 https://blog.csdn.net/weixin_45984029/article/details ...
最新文章
- 使用Volley传输网络数据
- matlab pca 测试样本,matlab_PCA,训练集与测试集分开,原理和用法
- Vim 下使用 Slimv(类似Slime) 轻松调试 Common Lisp
- Windows系统编程之进程间通信
- Linux-服务器远程控制
- Hashtable.ContainsKey跟Hashtable.Contains的区别
- 监督学习和无监督学习_机器学习的要素是什么? 有监督学习和无监督学习两大类...
- 基于JAVA+SpringBoot+Mybatis+MYSQL的科研项目评审系统
- 每日的代码量真的重要么?
- linux mint xmind运行,linux安装Xmind的经验
- Java扫码点餐小程序源码 智慧点餐系统源码 点餐APP SaaS模式
- 一起学JAVA 接口 面向接口开发
- spring @lazy注解的使用
- C语言指针用法完善篇
- 我们不应歧视任何语言,她们都是萌娘!(有图有真相)
- vue3.0之Router的使用
- java判断是否英文_java如何判断字符串是否是英文
- PDF转docx转md
- 算法:求小于N的最大素数
- 防火墙——iptables防火墙