Author Topic: Female Architecture student... new on using Arduinoo please I need a major HELP  (Read 2707 times)

0 Members and 1 Guest are viewing this topic.

Offline archstudent2012Topic starter

  • Beginner
  • *
  • Posts: 1
  • Helpful? 0
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/. 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

Offline amando96

  • Robot Overlord
  • ****
  • Posts: 187
  • Helpful? 1
Servo.h can only control 2 servos on pins 9 and 10, you need the megaservo library.
Rorcle, 60% complete
AATV, 5% complete

Offline madsci1016

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,450
  • Helpful? 43
    • Personal Website
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?


Offline amando96

  • Robot Overlord
  • ****
  • Posts: 187
  • Helpful? 1
How is the power? With one servo you don't need external power, with more than one you do because they pull more amps.
Quote
No longer true
You made me feel old   :P

Rorcle, 60% complete
AATV, 5% complete

Offline Hawaii00000

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 347
  • Helpful? 2
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 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)



« Last Edit: July 24, 2010, 05:57:13 PM by Hawaii00000 »
"God chose to make the world according to very beautiful mathematics."
-Paul Dirac
**************************************************************
Its Hawaii Five-O. Get it?

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
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)
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives