Yes of course it is going to work but it is not good for the arduino. Once you put a load on the servo the arduino is dead.
I’ve read though that a guy made it work with the 7805 transistor and a 12v power supply… I’ll give a try to that…
EDIT: Do you have those servos, which sketch are you exactly using to make them work?
My suggestion, is NEVER put a load on the Arduino’s +5V regulator. If it draws too much, and the AVR will shut-down.
This is a simple 2-regulator block I use, with an external +12V supply.
both regulators are standard TO-220 modules, mounted to a single heatsink piece.
It depends on what the maximum draw of the servo is, jumping from -100% (0) to +100% (179).
A single 9V transistor battery should be plenty, through the 7805, (skipping the 7809. Yeah, I found out they existed when I scrapped a few old 16-bit sound boards.) Your code is sound, But I’m trying to find an overhead of the Arduino board, to find out if Digital-3 is a PWM (~) capable output. (and I’m seeing it is.)
The buzzing, depends on the servo’s sensitivity, too. I ran into a few Airtronics servos that didn’t like (a) conversion to constant rotation, (b) powering below 7.5V… to say nothing of how sensitive they were to PWM changes. Most servos run a bandwidth from 1000uS to 2000uS. (1500uS being center, or SHOULD be stop for constant rotation.) Anything in between, could be just off the exact 5.556uS steps, and cause the servo to bounce back & forth between the two adjacent values. :~
The only other thing I can come up with, you didn’t mention if these are fixed 180 or constant rotation servos?
If the Servos are converted ones, how was neutral ( servo.Write(90) ) determined? 2 fixed value resistors? or a trim-pot?
If a trim pot, the center of the wiper could be slightly off… If fixed values (A pair of 2.2K’s in series, center to the old wiper), the tolerance of the resistors is a factor… How much one is off from the value of the other… (2.2K both, yes, but one could be actually 2.194K (<), or the other could be 2.293K (>)…) )
A robot project of mine, uses the remains of a VeX kit, using the VeX Motor Drives (Essentially, custom Futaba S2003’s with their own version of a driver board.)… The actual dead-stop value is off by 10uS. (yep, 2-degrees off.)
Hopefully, this gives some insight.
Just did a googlesearch of the towerpro SG90, and ran across this link for the specs: http://www.servodatabase.com/servo/towerpro/sg90
HazardsMind, whether the digital pin was 9, or 3… ANY of the PWM (~) pins will work. as long as the Myservo.attach(#) code assigns one of those pins. Also, it needn’t be exactly set to specifically MyServo, With my vEx robot, I have 3 servos, running from the same library:
LWheel , RWheel, SServo assigned to pins 9, 8, and 5. (9 being the left wheel, 8 for the Right Wheel, 5 for the servo rotating the Ultrasonic Range sensor.) (which itself, wires-up similar to the 4-pin PING))), but using 2X 3-pin plugs.)
My code for those, in the setup void, would be
The servo.h library is capable of up to 6 servos on the standard arduinos, Without the board in front of me, I can’t remember how many capable on the 2560 Mega.