-1

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);                       
  }
  }
gre_gor
  • 6,669
  • 9
  • 47
  • 52
Rohit Mathur
  • 131
  • 2
  • 7
  • 1
    You should mention the specific *model* of the **motor** you are using, as well as provide a *minimal, reproducible example*. Also, you should describe what is the **expected behaviour** of *Arduino* with your code and what is the *behaviour* that you re observing intead. As it is, your post doesn't even contain a question, and as such it is unclear. – Patrick Trentin Jan 23 '17 at 11:51
  • give more information on timing of powering up and those movements. and what in god's name is a certain angle. 1° or 176° or what? how is the motor connected? – Piglet Jan 23 '17 at 14:18
  • Model :- Tower Pro SG90 As i power up my arduino the servo motor rotates back and forth to a certain angle. i dont know the exact angle but it is approximately 20 degrees. And when i click on open door button on the application on my phone it passes 'i' via bluetooth HC-05. In this condition i want it to rotate from 0 degree to 90 degree. but what it does is rotate from 0 to 90 with normal speed and suddenly it comes to 0 degree again and start rotating to 90 degree with normal speed and after 4-5 times motor just stucks to 0 degree and start making noise. – Rohit Mathur Jan 25 '17 at 14:34
  • what i want it to do is when i press the open door button it should rotate from 0 degree to 90 degree and stops. it should come back when i press close door button. and on powering up arduino it suddenly rotates with enormous torque. i want it to be steady. – Rohit Mathur Jan 25 '17 at 14:42

1 Answers1

1
  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.

Pete Kirkham
  • 48,893
  • 5
  • 92
  • 171