土方-用arduino+红外开关测电机转速
2015-07-151.2万
AI 快速预览详细
本教程介绍了如何使用Arduino和红外开关测量电机转速。通过简单的DIY,将红外开关连接到2号脚,并在电机输出轴上捏一个橡皮泥作为摆叶。上电后即可检测电机转速。对于高转速情况,可以通过减短防抖检测时间和增大摆叶面积来提高检测精度。
红外开关接2号脚,捏个橡皮泥在电机输出轴上作为摆叶,上电即可,打开窗口即可检测。对于转速高的,本程序可能会检测不到,可以尝试减短防抖的检测时间,并增大摆叶面积。 服务器挂了不能上图~ 绝望~ |





int IRsensor = 2;
void setup()
{
Serial.begin(9600);
Serial.println("Start!");
pinMode(IRsensor,INPUT);
}
void loop(){
static unsigned long timepoint = millis();
static unsigned long timepoint1 = millis();
static byte count = 0;
if(millis()-timepoint > 2)
{
timepoint = millis();
if(digitalRead(IRsensor)) count = 0;
if( (count<30) && (++count==10) )
Speed++;
}
if(millis()-timepoint1 > 10000){
timepoint1 = millis();
Speed = Speed * 6;
Serial.print("Speed is: ");
Serial.println(Speed);
Speed = 0;
}
}
[/code]