普通舵机有3根线:GND(黑)、VCC(红)、Signal(黄)

 

红色的是电源正极,黑色的是电源负极,白色的是信号线。有些舵机线是红棕橘三色,分别对应红黑白。
#include <Servo.h>

Servo myservo; 
 
int pos = 90;  


void setup() {
  
  Serial.begin(9600);
    pinMode(4, OUTPUT);
    pinMode(5, OUTPUT);
     myservo.attach(9);  
 
}
 

 

Arduino舵机控制

 

博客:http://www.cnblogs.com/xiaobo-Linux/

 

void loop() {
 
   
   char val = Serial.read(); 
  
  
 

  if(val=='z')
 
{   
    pos+=30;                                 // in steps of 1 degree 
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(150);                       // waits 15ms for the servo to reach the position 
  
    Serial.println(" servo_right");    
 } 
 
if(val=='x')
{
   pos-=30;                              // in steps of 1 degree 
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(150);                       // waits 15ms for the servo to reach the position 
  
   Serial.println(" servo_left");
}

 

相关文章:

  • 2021-11-01
  • 2021-11-22
  • 2022-02-16
  • 2021-05-03
  • 2022-12-23
  • 2021-12-06
  • 2021-10-02
  • 2021-04-06
猜你喜欢
  • 2021-12-20
  • 2021-10-26
  • 2022-01-05
  • 2021-11-27
  • 2021-09-20
  • 2022-12-23
  • 2021-05-17
相关资源
相似解决方案