Hi, I'm having trouble with my sensor triggering my servos so they can move to a different position What do I need to do with my code to get this to work?
There are some logic problems within your instructions. Maybe it would be more fruitful if you tell us what do you expect the code to do (EDIT: @Paul_KD7HB asked first...)
This is uneffective, since you´re writing the same position the servos were already in.
myservo1.write(pos1 - pos3); // This is returning a negative angle
myservo2.write(pos1 + pos3); //This is returning an angle that is beyond 180°
This doesn´t appear to be correct...
Before anything else, however, I can tell you that HC-SR04 (if this is your us sensor) can behave strangely in too close distances and it will return zero (so, < 10) whenever the object is out of range.
Not that it makes any functional difference, but your code will be easier for others (and you maybe) to follow if you use meaningful names like servoLeftLeg rather than myservo1 and legUp (or whatever it is) rather than pos1.
I also try to remember to put comments after closing braces so it's easy to see at a glance where sections end, like } //end of loop.
I'm trying to make an obstacle avoiding robot and pos1 - pos2 makes the robot walk forward and pos1 - pos3 should make it go backward. The robot goes forward great it just won't go backward. Should I try
First of all, if you could determine the upper and lower limits of your servos, that would be useful to know. The suggestion in post #9 is a useful tool that will help. P.S. there's lots of servo examples for reference.
You were asked for the operationmode.
does this mean that the servo horn move 180 degrees clockwise and then back 180 degrees counter-clockwise?
As a general advice: how many postings do you want to wait for the final solution?
As more details, datasheets, pictures of your project you are posting the less
"asking back for this and that details"-posting are nescessary.