Arduino Nano PWM干扰SERVO------。

问题描述 投票:0回答:1

我试着为我的孩子做肥皂 - 泡沫机器人。它是简单的。有杠杆的伺服,浸泡在肥皂水中的环,并放置在前面的风扇。问题是,当我激活PWM伺服开始行为不端(抖动,颤抖到0位置),虽然他们不在同一时间运行。似乎在PWM期间伺服引脚有一些噪音。

  #include <Servo.h>
  Servo myservo;  // create servo object to control a servo
  #define MOTOR_PIN 11 
  int pos = 0;    // variable to store the servo position

  void setup() {
    myservo.attach(4);
    pinMode(LED_BUILTIN, OUTPUT);
    pinMode(MOTOR_PIN, OUTPUT);

  }

  void loop() {
    analogWrite(MOTOR_PIN,0);
    delay(100);
    for (pos = 30; pos <= 120; pos += 1) { 
      // in steps of 1 degree
      myservo.write(pos);              
      delay(10);                      
    }

     for (pos = 120; pos >= 30; pos -= 1) { 
      myservo.write(pos);              
      delay(10);                      
    } 

      digitalWrite(LED_BUILTIN, HIGH);   
      delay(200);                       
      digitalWrite(LED_BUILTIN, LOW);    
      delay(150);                       
      digitalWrite(LED_BUILTIN, HIGH);   
      delay(150); 

      analogWrite(MOTOR_PIN, 400);

      digitalWrite(LED_BUILTIN, LOW);    
      delay(150);      
      digitalWrite(LED_BUILTIN, HIGH);  
      delay(150);                       
      digitalWrite(LED_BUILTIN, LOW);  
      delay(150);      
      delay (3000);

  }

原子板伺服和PWM的图像。

arduino noise pwm servo arduino-nano
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.