Author Options:

6 multiservo random selection Answered


I would like to create a project for the random selection of shooting targets. E.g. each target should show up and stay there for 5 seconds and if not shot down the servo should pull it back. Does anyone have the code required for random selection of servos and making sure they delay between on and off is 5 secs? Ideally the random component would ensure that all targets have an equal chance of being selected but only one at a time.


That is a fairly straight forward challenge. You should look into Arduino "case statements."

The pseudo code would basically look like:

Variable == select random number between 1 - 5

Variable Case 1:

move motor 1 up
delay 5 seconds
move the motor back

Variable Case 2:

move motor 2 up
delay 5 seconds
move the motor back


This is just an idea of the structure of the code. The actual code will be formatted differently.

Also, check out the Arduino Class:

And the robot class for servos: