Test1/zh-hans

来自Labplus盛思维基百科
跳转至: 导航搜索

<languages/>

黑色传感器最终版12.20-26.png

概述

可用于循迹线检测,当检测到黑色时,输出高电平,检测白色时,输出低电平。

基于红外反射原理,红外发射二极管不断发射红外线,红外光电三极管接收反射回来的红外光。由于白色对红外反射强,黑色对红外反射弱,故此可检测黑、白线。
Bluebit重力小车程序 ‎


技术参数

  • 工作电压:VCC 3.3-5V
  • 模块尺寸:24x46x7.5mm


引脚定义

VCC 电源
D1 对应D1红外接收触发值
D2 对应D2红外接收触发值
GND


使用教程

在安装循迹模块时约距离循迹线1CM左右

Arduino示例

//程序功能:根据循迹传感器两个红外对管的不同状态,控制两个电机的状态//
//红外对管1  红外对管2  电机1  电机2//
//    1          1      不转   不转 //
//    1          0      不转   转   //
//    0          1      转     不转 //
//    0          0      转     转   //
int find1Pin =2;    
int find2Pin =3;  
int motor1Pin =7;  
int motor2Pin =8;  
int a,b;
void setup() {
  Serial.begin(9600);  
  pinMode(find1Pin, INPUT);  
  pinMode(find2Pin, INPUT);  
  pinMode(motor1Pin, OUTPUT);
  pinMode(motor2Pin, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  a=digitalRead(find1Pin);
  b=digitalRead(find2Pin);
  Serial.println(a);
  Serial.println(b);
  if((a==1)&&(b==1))
  {
    digitalWrite(motor1Pin,LOW);
    digitalWrite(motor2Pin,LOW);
  }
  if((a==1)&&(b==0))
  {
    digitalWrite(motor1Pin,LOW);
    digitalWrite(motor2Pin,HIGH);
  }
  if((a==0)&&(b==1))
  {
    digitalWrite(motor1Pin,HIGH);
    digitalWrite(motor2Pin,LOW);
  }
  if((a==0)&&(b==0))
  {
    digitalWrite(motor1Pin,HIGH);
    digitalWrite(motor2Pin,HIGH);
  }
}

应用示例