简体   繁体   中英

Servo motor misbehavior

I am trying to make an automated door which opens/closes the door on receiving commands via Bluetooth.

All I want the servo to do is:

  1. Remain steady on powering up the Arduino. (Currently it rotates to a certain angle and comes back on powering up Arduino).

  2. Rotate from 0 degree to 90 degree and stops, on receiving another command it should rotate from 90 degree to 0 degree and stops.

This is my code :

else if (val=='i'){
myservo.write(0);
delay(4000);
for(pos = 0; pos <= 90; pos += 1){
    myservo.write(pos);              
    delay(15);                       
 }
}
  else if (val=='j'){
myservo.write(0);
delay(4000);
 for(pos = 90; pos >= 0; pos -= 1){
    myservo.write(pos);              
    delay(15);                       
  }
  }
  1. This is a characteristic of the electronics of servos. Supply the PWM signal to the servo before powering it up, or within a few milliseconds of power up. If you want to continue using an Arduino, the bootloader waits a few seconds during which the servo doesn't have a signal, so add a transistor to switch the power to the servos on as the last thing in your startup code. If you can program the microcontroller directly and remove the Arduino bootloader, then the microcontroller should start executing your servo controls quickly enough not to have a noticeable glitch. In either case, the servo will still jump to the position you tell it to on start-up rather than a random position; you can save the last commanded position in the EEROM so the jump will be less noticeable, but when unpowered the servo will move if mechanically loaded so there may still be a jump. There isn't a way of saying 'stay in your current position' to a RC servo.
  2. Your val == 'i' , val == 'j' branches move the servo quickly to zero before rotating slowly from 90 to zero or zero to 90. Remember the position you were in and don't move to zero before moving from that position to the desired position.

Mechanically, the sort of servo which is controlled by the servo library is not likely to be strong enough to open or close a normal door; if it's a door in a doll's house or a cat flap you would be OK, but otherwise you should use a more powerful actuator and end stops and some force sensor so you don't crush people.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM