Arduino 5 Minute Tutorials: Lesson 5 - Servo Motors

@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

sir!, I want to control four mecanum wheels with the help of servo motor.The wheels should carry around 25kg weight.For that which type of servo motor and driver board i want to use?.

@ajith You likely mean industrial servo motors (as opposed to RC). RobotShop currently does not carry industrial servos and as such, unfortunately we cannot provide any options.

sir!,i want to connect 5 micro servomotors to ardunio with the helpof 9v battery…plz help me

Most RC servo motors are powered at 4.8V to 6V, so if you want to use a 9V battery, you’d need a 5V regulator. Also, 9V batteries are meant to power low current electronics, not servos, so there’s a strong chance that even powering two servos might create brown outs. Last, 9V batteries have very low capacity, meaning the servos won’t operate for long. Micro servos tend to consume high current under load. You should consider using an IO shield for easy connection.

Hi sir,
I connected my arduino with the servo and a potentiometer with cables and it works very good.
In the project I made, i want to control the servo motor, placed in a boat over an antenna. How can i control my servo over a distance, using an antenna.
Sorry for my English (i’m Belgian/Dutch). But i like to control my servo motor, placed in a boat over an distance. In the remote contole is an arduino nano and in the boat an arduino uno… What are the commando’s for programming my arduino?
sorry for my English…

@wdefossez You’ll need a way to send signals wirelessly from where you are to the Arduino. An Arduino Nano on its own does not hare wireless capability (unless you purchased a special unit(, and an antenna only does not transmit or receive. If you don’t want to use a normal RC wireless system, you’ll need the following:

RF device: https://www.robotshop.com/en/general-rf-data-telemetry.html
MCU: https://www.robotshop.com/en/microcontrollers.html (one to read the potentiometer on land, the other to control the servo)

Note that a handheld RC system handles all of this (so no programming needed):
https://www.robotshop.com/en/wireless-rc-pwm-servo-controllers.html

Would you please update the original tutorial because when I clicked on the link to buy the parts, the links point to the whole store? For example, when clicking on the Arduino, it took me to the page where there are a whole bunch of boards. Not sure which one is the correct one?

@long-11 You are correct that this series dates back many years and the products included have long since been replaced. The series as a whole could use an updating. The latest official Arduino Uno:

@cbenson
thank you for you response. I am about to click the button to place my order, but wanted to check with you to make sure that parts I am about to order are all compatible and are what I need. So, here are my requirements:

  1. No soldering. I just want to connect the servo to the Arduino board without any soldering and need to have the connection to stay permanently.
  2. Need to have the shafted extend to at least 1 inc

Here are parts I am about to order:

  1. https://www.robotshop.com/en/arduino-uno-r3-usb-microcontroller.html
  2. https://www.robotshop.com/en/hitec-hs-422-servo-motor.html
  3. https://www.robotshop.com/en/sfe-power-supply-9vdc-650ma.html
  4. https://www.robotshop.com/en/actobotics-2x1-4-precision-d-shaft.html
  5. https://www.robotshop.com/en/actobotics-set-screw-hitec-servo-shaft-coupler-14.html

As soon as you confirm, i will place my order and start tinkering. Thank you so much in advance for your help

Provided your servo doesn’t encounter much resistance, it should not consume much current and can therefore be powered from the Arduino’s pins. Note that the servo has one 3x1 pin female connector, and you’ll need to break that out to be able to wire black to GND, yellow to one of the digital pins and red to 5V on the Arduino.

@cbenson,
would you please recommend some LED lights that can be connected to Arduino Uno R3 board that does not require soldering?

@long-11 You’ll really like an IO shield like this: https://www.robotshop.com/en/gravity-i-o-expansion-shield-arduino-v7.html
It allows you to use products with 3-pin headers (like servos, sensors, breakout boards. For example, LED lights:
https://www.robotshop.com/en/gravity-digital-piranha-led-module-red.html
https://www.robotshop.com/en/octopus-5mm-led-brick-red.html

hi @cbenson,
this is long-11 (i had to create a new user name). So, I purchased the parts I listed in March. Specifically, I bought the R3 Uno board along with the Hitek HS-422. I wrote the source code the way you showed, but not sure how to connect the servo to the Uno. I tried both the 3 pins in the middle of the board and the one next to the USB port, but the servo won’t rotate. Would you please show which pin I should connect the servo to?

@longlac Welcome back. You didn’t opt for the shield in the previous reply? The objective of using that was to easily connect the servo, LEDs etc. Ideally the Arduino’s pins would not power the servo motor directly, but if there’s minimal load (i.e. it won’t consume much current at all), you’d connect the black cable to GND, the middle red cable to 5V and the yellow to a digital pin. It’s best not to connect the pins and provide power (can fry some or all electronics). Feel free to provide a clear photo showing the connections before providing power / connecting to the computer via USB.

I am attaching here my connection

I also tried these pins

I was hoping that I did not have to buy the shield as I tried to keep the cost down for my customers. I am thinking that since I am connecting to the pins different than what you showed in the tutorial, I need to change the source code, but not sure what pin number to use for my connections