[英]Servo motor issue
I have a problem in my project. 我的项目有问题。 If there is an available parking lot, I want the servo to rotate 90 degrees.
如果有可用的停车场,我希望伺服器旋转90度。 I used two sensors, one for the car's entry and one if cars want to leave.
我使用了两个传感器,一个用于汽车进入,另一个用于汽车要离开时。
This is my code: 这是我的代码:
for(int i=0;i<11;i++)
{
if (parks[i]!='0' && parks[i]!=' ')// if there is available park
{
aPark=1;
}
else
{
aPark=0;
}
}
if(analogRead(A0)>200 && aPark==1) // if there is available park and car want to enter
{
myservo.write(90);
delay1=millis()+5000;
}
if(analogRead(A1)>200) // for leaving cars.
{
myservo.write(90);
delay1=millis()+5000;
}
if(delay1<millis())
{
myservo.write(0);
}
When I connect everything and upload the code the servo is not rotating. 当我连接所有东西并上传代码时,伺服器没有旋转。 Is there a problem in my code?
我的代码有问题吗? Or is it because the sensor is not not detected?
还是因为未检测到传感器?
i would verify the connections on the servo and even if the arduino is not sending any commands to the servo you should hear a buzz or some electric noise when its first powered on, next i would try adding serial.println statements to know if your code functions correctly and if the sensors are well connected, don't forget to Serial.begin(115200); 我会验证伺服器上的连接,即使arduino没有向伺服器发送任何命令,您也应该在第一次通电时听到嗡嗡声或一些电子噪音,接下来我会尝试添加serial.println语句来了解您的代码正常运行,并且如果传感器连接正确,请不要忘记Serial.begin(115200); in the setup code, for example ;
在设置代码中,例如;
for(int i=0;i<11;i++) {
if (parks[i]!='0' && parks[i]!=' ')// if there is available park
{
aPark=1;
Serial.println("aPark=1");
}
else
{
aPark=0;
Serial.println("aPark=0");
} }
if(analogRead(A0)>200 && aPark==1) // if there is available park and car want to
enter
{
myservo.write(90);
delay1=millis()+5000;
Serial.println("1.servo 90 delay mil+5000");
}
if(analogRead(A1)>200) // for leaving cars.
{
myservo.write(90);
delay1=millis()+5000;
Serial.println("2.servo 90 delay mil+5000");
}
if(delay1<millis())
{
myservo.write(0);
Serial.println("servo 0");
}
Have you included servo library? 包括伺服库吗?
#include <Servo.h>
should be at the top of your code. #include <Servo.h>
应该位于代码的顶部。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.