can someone give me advise on limiting servo travel with program. I'm kind of new to this and sure its probably all over forum. i have servo connected to air duct and swings door around 90 degrees total from hard stop to hard stop. I'm using ESP32 and 10K pot with servo if it matters. i was hoping to keep making changes and sneak up on when door just closes on each end of travel. question i have is can you control travel with (myservo.attach(servoPin ,500,2400) or the map function (val=map(val,0, ADC_Max, 0, 180)......
Your program commands the servo to move to certain angles, so limit the command angles. The servo will burn out if driven against a hard stop.
The limits can to be determined by experiment, or use a microswitch to detect a hard stop and cut power, or reverse motion.
understand the mechanical part it just the programming----can i do it in the map function?
Do what in the map function?
Simply avoid commanding the servo to move past predetermined angles. Start with the Arduino servo sweep example to understand the basic servo positioning commands.
For example: use valid numbers other than 0 and 180 in the code excerpt below:
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
that was it ---just wanted to make sure that was the right way-----i'm using a rheostat
my code now is
val=analogRead(potPin);
val=map(val,0,ADC_Max,0,180);
myservo.write(val)
moving the rheostat swings the servo thru 180 degrees
if i change it to lets say
val=analogRead(potPin);
val=map(val,0,ADC_Max,60,120);
myservo.write(val)
that should swing thru less angle?
i will keep changing the 60 and 120 to exact close door at each end without hitting the hard stops
That should work, if the pot shaft somehow accurately represents the door angle, and does not slip.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.