Society of Robots - Robot Forum
Electronics => Electronics => Topic started by: archstudent2012 on July 24, 2010, 12:25:25 PM
-
Hello, I am a female Arch student and I am taking this class that focuses on creating interactive object using an Arduino... my project requires 4 servo and a Maxbotix Ultrasonic Rangefinder - LV-EZ1.. The idea is that when someone comes close to my project the sonar detects it and the 4 servos moves from 0-90 degrees... first i am trying to make the 4 servos work... I found this tutorial online on how to wire a single servo http://www.instructables.com/id/Arduino-Expermentation-Kit-How-to-get-Started-wi/step6/A-Single-Servo-Servos-CIRC04/. (http://www.instructables.com/id/Arduino-Expermentation-Kit-How-to-get-Started-wi/step6/A-Single-Servo-Servos-CIRC04/.) i followed it and it works but know i am trying a wire more servos by replicating the wirings on the tutorial and it doesn't work..im am so frustrated and hopeless to make this project work... if anyone can show me step by step how to wire these four servo and make it move i would gladly appreciate.. below is the code that i used to control the servo:
// Sweep
// by BARRAGAN <http://barraganstudio.com>
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop()
{
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
thanks alot guys for any help
-
Servo.h can only control 2 servos on pins 9 and 10, you need the megaservo library.
-
Servo.h can only control 2 servos on pins 9 and 10, you need the megaservo library.
No longer true as of version 0017. the regular servo.h supports 12 servos on the regular Arduino.
Is this the code from the example, or what you are writing? I only see one servo used in this code. Are you just trying to have the 4 servos move in unison, or each controlled separately?
-
How is the power? With one servo you don't need external power, with more than one you do because they pull more amps.
No longer true
You made me feel old :P
-
Here's how you want to wire your servos if you want them to be controlled separately. This method also requires you to modify your code to allow for more servos. (I believe this is right, hopefully someone else can verify)
- The yellow wire on each servo should be connected to its own digial IO.
- The black wires of all the servos should be connected to one of the gnd pins (They can all be connected to the same one.)
- The red wire of all the servos should be connected straight to the + of you battery. (This is so you don't draw to much power through the arduino)
If all your servos are doing the same thing at the same time (ie They don't need to be controlled individually) then you can buy three of these of these (http://www.servocity.com/html/6__y-harnesses.html) and connect them so that a single plug branches into four.
If you do it this way you still need to connect the battery/gnd the same, but you only need to use one digital IO (pin 9 accordin to the code)
-
Hi,
int pos = 0; // variable to store the servo position
You need one for each servo - each with a unique name.
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
You need to assign each servo object the pin number that the servo is attached to.
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
During a delay, the controller does nothing else, so for the 15ms, it's out to lunch and won't handle any other servo or even the simplest 1+1.
It is clearly just a quick piece of code to demo the simplest use of a servo. For running 4 servos plus the US, in a loop, you must do something like:
(Pseudo code)
Do
Get US reading
If People_Detected = TRUE Then
Call ServoRoutine(S1, S2, S3, S4)
End If
Loop
Proc ServoRoutine(S1, S2, S3, S4)
myservo1.write(S1)
myservo2.write(S2)
myservo3.write(S3)
myservo4.write(S4)
End Proc
Or the latter part may include a series of timed moves.
You'll need to decide when to stop the action and return the servos to whatever you call the start position as well - eg. nn seconds after the last detection of people, or just after a certain time from initial detection (perhaps with another preconfigured delay before it's able to start over).
Is this a standard part of the curriculum?
(I've seen so many similar posts and blogs, primarily from art students though, that pretty soon, an exhibition of static art will be considered cutting edge, with the "new" concept of resting your eyes and soul ;D)