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:
Remain steady on powering up the Arduino. (Currently it rotates to a certain angle and comes back on powering up Arduino).
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);
}
}
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.