Hello, I need help with programing the servo I have for a project where I would like it to move 90 degrees from the press of a button and then move back to its original position at the press of the same button. I have no idea how to program this. I have checked many videos online and checked forums and cannot seem to find the answer. Any help would be greatly appreciated!
You cannot program a standard servo to read a button and go to different positions by itself; you will need some kind of separate microcontroller or control board to do that. Are you already using a specific device, like one of our Maestro Servo Controllers, or are you looking for recommendations for a device?
Hello thanks for the reply. Sorry I should have mentioned I have a Micro Maestro 6-Channel USB Servo Controller. I have connected the board to the power and the servo, and from the computer I can move the servo backwards and forwards to the positions I need. The problem I have is I’m not sure how to program it so that it will work disconnected from the computer moving 45 degrees one way then with the press of a button move back again. Any help would be much appreciated.
Thank you for the additional information. Getting the servo powered and working through the “Status” tab of the Maestro Control Center is a good start. Next, you can choose a Maestro channel to use for your button input and configure it as an “Input” in the “Channel Settings” tab. Once it is configured, you can connect your button with a pull-up resistor, as shown in the “Attaching Servos and Peripherals” section of the Maestro user’s guide. When the button is connected, you can test it by looking at the associated slider for that channel in the “Status” tab; you should see it move from one side to the other when you press the button.
Once the button is connected and working properly, the next step is to write a script that reads that button and moves the servo how you want. The “Using a button or switch to control servos” example in the “Example Scripts” section of the Maestro user’s guide is a good place to start. It looks pretty complicated because it is handling button debouncing, but since it is already done, you can just copy/paste it into your Script tab and work from there. So, you will just need to change the channel used for the button (on line 9 of the script) and the servo (on line 62 of the script) from 0 and 1 respectively to whatever channels you used, and the servo positions in the main loop (on lines 53-57).
Thank you very much for the info I will look into this at the weekend. If I have any problems is it ok to ask for your help again ?
Yes, if you try and run into problems getting it to do what you want, please include a description of the problem as well as a copy of your Maestro settings file, and I would be glad to help you figure it out. You can save a copy of your settings file from the “File” drop-down menu of the Maestro Control Center while the controller is connected. Pictures of your setup showing all of your connections might also be helpful.
Thanks again for the help I have it working as id like. There is only one thing left for me to do now and that is save the settings to the Maestro so the button will do the same job without the computer connected to it. Could you help me with that at all ?
If you already have the button and script working as you want, you can have the Maestro run that script as soon as it is powered by checking the “Run script on startup” option in the “Script” tab of the Maestro Control Center, then clicking the Apply Settings button.