Arduino 5 Minute Tutorials: Lesson 5 - Servo Motors

Sir, i need to activate my servo with in a range of pressure values given by fsr i have code for movement of the servo but i need this movement only with in the pressure range 10-100 all other pressure values the servo should deactivate. pls help me with this. {Code removed by moderator due to comment length}

@Jagath Dharmasiri For specific help with programming in Arduino, we suggest creating a new topic on the Arduino forum.

  1. When you plug the cables (both power and data) into the pins, will they stay? Do I need to solder the cables so they will stay connected permanently?
  2. Would you please provide a link for the batter holder so I can purchase it?
  3. If I want to attach an object (wooden a figurine, very light) to the servo so it will rotate, do I use glue or screw?

Thanks

@Long 1. If you are using male pin headers to female connectors on the board, the connection is not permanent and relies on friction between metals. You would need to use solder. 2. This depends on which battery holder you mean https://www.robotshop.com/en/standard-batteries.html 3. Either would work. Before you glue though, make sure the servo is at the correct angle. Hot glue tends to be a good option.

Coleman Benson,
thanks for your answers. I have more questions for you:

  1. I really don’t want to use a solder. If I use this servo (https://www.robotshop.com/en/25kg-goteck-metal-gear-micro-servo.html), can I just plug it in without soldering?
  2. All the servos I found so far have the shaft that is too short for my project. Is there any part that help me extend the shaft to about 1 inch longer?

@Long 1. Yes, no soldering is needed. 2. The output spline on a servo is designed to be short, but transmit the necessary torque. You’d need a different servo and a shaft adapter like: https://www.robotshop.com/en/actobotics-hitec-servo-shaft-hub-12.html and https://www.robotshop.com/en/hitec-hs422-servo-motor.html

My controller won’t connect and it also says there is a problem with the code.

@Jacob We would need far more details to help troubleshoot. Can you create a new post on the RobotShop Forum and provide links to the products you are using, photos of the setup, the code etc.?

When I try to use Arduino PID and Servo library to PID control a CIM motor using Talon SRX, the PID output only seems to be value on either of the PID output bounds, but not anything in between? Could I please know why? Thank you sir.

@Jack If you have connected the Talon SRX to a variable input (joystick or other potentiometer as opposed to a switch) and you only get MIN / Max values, you might have the Talon in the wrong mode. For additional support, please create a new topic on the RobotShop Forum.

can i know how to make two servo motor and both start with different angle

@jamiljack Not sure what you mean, but if you just want them to start at different angles, you simply send them different position commands / pulses.

Hi!
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.

@Thomas Galanos We do not have specific code for this because of several things - each project is different in its requirements and hardware, connections and loads are different, as well as the technology used. There is a “random()” function in Arduino you can use which also has bounds of min and max values.

Hi, thanks for this tutorial. I’m absolutely sure that I hooked up my servo as instructed, but it didn’t work. Now when I plug it in, it makes my Arduino power down and disconnect from USB. I posted about it at https://arduino.stackexchange.com/questions/49727/servo-causes-disconnection and the forum advised me never to hook the servo up like this. What’s going on?

@Jim The servo likely consumes far more current than the Arduino can provide. You’ll need to use a separate power supply of between 4.8V to 6V (or battery pack). You connect he + and GND to the servo, and the GND and signal from the servo to the Arduino (ie. “common ground”). If the servos is getting hot, then you might not be sending the correct signal either (between 600 and 2400us repeated every 20ms).

Hello, thank you for the tutorial. I have a question regarding the servo motor. How can I program the motor to move in the opposite direction? Asking for a friend.

@Hans Sommelier The servo would need the “opposite” position signal. If you’re using an RC receiver, it’s not possible without physically mounting the servo upside-down. If you are sending calculated values, your microcontroller can easily calculate the opposite value. Note that RC servos tend to require a repeated pulse of 500us to 2500us with 1500us being centered.

hi, I’m using the DFRobotShop Rover V2 - Arduino Compatible Tracked Robot and would like to know how to code it so the motors both turn when the up arrow is pressed. Could you help me with this in some way?

@Crandemolisher9 There is sample code in the user guide which uses the WASD keys on the keyboard. Not an easy answer, but you will need to detect the key pressed, but note that the Arduino IDE cannot detect the arrow keys and you’ll need to use a different serial port software to communicate with the DFRobotShop Rover.
https://www.arduino.cc/en/Reference/KeyPressed
https://www.arduino.cc/en/Reference/KeyboardModifiers