Arduino Forum

Using Arduino => Programming Questions => Topic started by: Falchion on Jan 07, 2013, 05:34 am

Title: Need some help for a science project.
Post by: Falchion on Jan 07, 2013, 05:34 am
I decided to make a robotic hand out of simple materials (here is the project summary:http://www.sciencebuddies.org/science-fair-projects/project_ideas/Robotics_p003.shtml) and I need some help programming the fingers so I can get them to move. What I want it to do involves picking up a chess piece and placing it in its designated spot. I have very little programming experience, and I would greatly appreciate it if you could explain it in basic terms.  :)
Title: Re: Need some help for a science project.
Post by: JimboZA on Jan 07, 2013, 06:04 am
Wow this is a biggy for a starting point..... but nothing quite like jumping in the deep end!

That site says:

Quote
Once you have your robot hand


which makes that part sound pretty simple. Have you got that far yet?- ie the mechanical part?

My advice is to grab your Arduino and work through the simple examples on this site, such as good old Blink (http://arduino.cc/en/Tutorial/Blink). Then grab a servo and a potentiometer and work through the two servo examples, namely Sweep (http://arduino.cc/en/Tutorial/Sweep) and Knob (http://arduino.cc/en/Tutorial/Knob).

I really think that to start, you have to get your mind how an Arduino program hangs together and how a servo is controlled.

First Things First....

Edit... by the way, to get the hand to move to a point is more than just building and programming the hand. A hand, to be useful, needs to be on an arm, that's another 4-5 servos and some fairly major construction. Not to mention the logic and sensing involved in knowing where QB4 is on the board....
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 07, 2013, 07:04 am
I almost have the fingers done. Thank you for the advice though. Also, how do you get the wires out of the servo motor? I'm using the Futaba S3003 servo motors if that helps.
Title: Re: Need some help for a science project.
Post by: JimboZA on Jan 07, 2013, 07:15 am
Quote
how do you get the wires out of the servo motor


Not sure what you mean...

There is usually a three wire connection coming out of a servo into a small plug with holes for 3 connectors- usually red and black for 5v and ground, and yellow or orange for the control. You need to stick wires (preferably with pins on the end) into those sockets and take them to the power supply and Arduino pin. You can see the 3 way plug clearly in this pic of your servo (http://www3.towerhobbies.com/cgi-bin/wti0001p?&I=LXH288).

You may find that standard size servo a bit big especially if you have 5 of them next to each other. Might be an idea to consider a micro servo like this (http://www.hobbyking.com/hobbyking/store/__662__HXT900_9g_1_6kg_12sec_Micro_Servo.html).

Edit.... you should have a look at DuaneB's acclaimed servo tutorials here (http://rcarduino.blogspot.com/2012/04/servo-problems-with-arduino-part-1.html) and here (http://rcarduino.blogspot.com/2012/04/servo-problems-part-2-demonstration.html).
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 07, 2013, 07:38 am
I got the red wire out successfully, and when I put it into 5V, it felt pretty loose. Is it supposed to feel that way?
Title: Re: Need some help for a science project.
Post by: AWOL on Jan 07, 2013, 08:43 am
Quote
I got the red wire out successfully, and when I put it into 5V, it felt pretty loose. Is it supposed to feel that way?

I'm really not sure what you're saying here.
Title: Re: Need some help for a science project.
Post by: wildbill on Jan 07, 2013, 01:20 pm

I got the red wire out successfully, and when I put it into 5V, it felt pretty loose. Is it supposed to feel that way?


Note that the arduino can sometimes, depending on the servo, just about manage to power one. For the multiple ones you're going to need, you'll need a separate power supply for the servos. DuaneB's tutorials mentioned above should help you with how to wire them up.
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 07, 2013, 11:33 pm
Is this what its supposed to look like when you take the wire out?
Title: Re: Need some help for a science project.
Post by: wildbill on Jan 07, 2013, 11:49 pm
Why did you remove the wire from the socket? What do you intend to attach it to?

edit: typo
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 07, 2013, 11:53 pm

Why did you remove the wire from the socket? What do you intent to attach it to?
The 5V port on the Arduino. Did I do something wrong?  :~
Title: Re: Need some help for a science project.
Post by: wildbill on Jan 08, 2013, 12:06 am
Well normally at this stage of your project, you'd be more likely to use some breadboarding wire to stick into the servo's socket and then attach those wires to whatever is going to power the servo - which should not be the arduino - it can't provide sufficient current for more than one, if that.

Later you might wire it up using a male connector into the servo's socket so that it's easier to replace the servo from your robot if it is damaged, or solder it all together if you decide you don't need that luxury.
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 08, 2013, 12:46 am
So I need to buy these wires to plug them into the sockets?
Title: Re: Need some help for a science project.
Post by: Grumpy_Mike on Jan 08, 2013, 12:55 am
At the very least yes. You actually need to get a pin header and solder the wires from the servo to it.
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 08, 2013, 01:07 am

Well normally at this stage of your project, you'd be more likely to use some breadboarding wire to stick into the servo's socket and then attach those wires to whatever is going to power the servo - which should not be the arduino - it can't provide sufficient current for more than one, if that.

Later you might wire it up using a male connector into the servo's socket so that it's easier to replace the servo from your robot if it is damaged, or solder it all together if you decide you don't need that luxury.
What should it be powered by then?
Title: Re: Need some help for a science project.
Post by: wildbill on Jan 08, 2013, 01:23 am
For initial experiments, I searched around my house for an old wallwart in the right range - 6-7 volts IIRC. The ones I found didn't provide enough current for more than a couple of servos though. You may need to buy (or build) something that provides more juice. Even though your robot sounds like it will be stationary, you might look at lipo batteries to avoid the need for acquiring what would effectively be a beefier wallwart.
Title: Re: Need some help for a science project.
Post by: zoomkat on Jan 08, 2013, 01:55 am
Quote
What should it be powered by then?


Four 1.5v batterys in series would do for simplicity, like below.

(http://web.comporium.net/~shb/pix/servo-wire.jpg)
Title: Re: Need some help for a science project.
Post by: JimboZA on Jan 08, 2013, 03:55 am
Did you have a look at DuaneB's servo tutorials as I suggested in post #3? They really do explain servos very clearly.
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 09, 2013, 05:22 am
Yes, I looked at the tutorials. I'm starting to understand the concept more.
Title: Re: Need some help for a science project.
Post by: JimboZA on Jan 09, 2013, 05:57 am

Yes, I looked at the tutorials. I'm starting to understand the concept more.


Cool.... for what it's worth my daughter's busy with a servo controlled arm... so far just a shoulder and an elbow. Shoulder is two standard servos on a pan and tilt bracket; elbow is a micro. It's mounted with Meccano (= Erector Set) in a small wooden box to stop it falling over and the upper and lower arm are Meccano too. Pic attached....
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 10, 2013, 04:21 am
I got the wires and the breadboard yesterday.  :)
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 10, 2013, 06:03 am
I just need to obtain a battery that can support all of these servo motors.
Title: Re: Need some help for a science project.
Post by: JimboZA on Jan 10, 2013, 06:27 am

I just need to obtain a battery that can support all of these servo motors.


Yep, and there's a lot of discussion about power supply on this forum!

I've just (literally yesterday) been given a 650W ATX PSU and using an Instructable like this (http://www.instructables.com/id/ATX--%3E-Lab-Bench-Power-Supply-Conversion/) we're converting that to a lab supply. The servos I have are happy at 5v, and I can also use the 5v to supply Uno through the USB. (Alternatively I might regulate that up to 7.x V with one of these (http://www.pololu.com/catalog/product/2120) (which I have) and feed that to the barrel or Vin).
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 13, 2013, 03:43 am
How many servo motors should I be using?
Title: Re: Need some help for a science project.
Post by: JimboZA on Jan 13, 2013, 05:19 am

How many servo motors should I be using?


Hey- glad you're making some progress!

I didn't read those hand instructions in any detail, but it seemed to me there's a string in each finger, is that right? Then I suppose at a maximum you would need a servo per finger. On the other hand (sorry about the pun), maybe you could gather the strings together and activate them with only one servo. Or somewhere in between- space and weight will be a consideration. You will need to experiment with that- that's part of the fun of this whole thing. I think too, that you'll need to experiment with servo positioning relative to the hand, to give the right angle when the strings are pulled, and build some kind of base for the whole thing.

Then you'll need to figure out how to attach the hand to the arm- the arm I showed has three servos: 2x standard size a "shoulder" in a pan / tilt bracket (http://dfrobot.com/wiki/index.php?title=Pan_and_Tilt_Kit_(SKU:FIT0004)) and 1x micro as an "elbow". Number of motors depends on the number of joints and the range of motions you need.

As an aside, I've asked my local supplier to see if he can source a pan / tilt bracket like that for micro servos: it would make a cool wrist.
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 17, 2013, 04:03 am
Is it possible to put these into a breadboard? http://www.amazon.com/SparkFun-Arduino-Stackable-Header-Kit/dp/B004G56J8W/ref=cm_cr_pr_product_top
Title: Re: Need some help for a science project.
Post by: Grumpy_Mike on Jan 17, 2013, 10:18 am
I would have thought so but what is the point. A breadboard is a pile of sockets, you just make some of them higher.
Those in the link are very expensive, an electronics distribuitors will have them cheaper.
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 20, 2013, 04:01 am
I have obtained all of the materials that I need for the hand.  :D Once the hand is completed (which should be tonight), where do the Arduino and the servo motors come in? Keep in mind that I'm still a beginner, and I don't know the ins and outs of robotics. Here are the articles if you're interested in reading them. http://www.sciencebuddies.org/science-fair-projects/project_ideas/Robotics_p003.shtml
http://www.sciencebuddies.org/science-fair-projects/project_ideas/Robotics_p001.shtml
Title: Re: Need some help for a science project.
Post by: arduinohabib on Jan 20, 2013, 04:21 am
Have you tried uploading the example sketches?



My advice is to grab your Arduino and work through the simple examples on this site, such as good old Blink (http://arduino.cc/en/Tutorial/Blink). Then grab a servo and a potentiometer and work through the two servo examples, namely Sweep (http://arduino.cc/en/Tutorial/Sweep) and Knob (http://arduino.cc/en/Tutorial/Knob).
I really think that to start, you have to get your mind how an Arduino program hangs together and how a servo is controlled.

Good luck!
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 20, 2013, 04:31 am
Example sketches of the hand?
Title: Re: Need some help for a science project.
Post by: arduinohabib on Jan 20, 2013, 04:49 am
No. Upload the sketches in the photos linked.
http://flic.kr/p/dMX4Ri
http://flic.kr/p/dMX4RV
Title: Re: Need some help for a science project.
Post by: JimboZA on Jan 20, 2013, 04:51 am

Example sketches of the hand?


There IS no example sketch for the hand: that surely is the whole purpose of the project, to learn how to do that.

As to where "the Arduino and the servos come in"....  well your p003 link very glibly says:

Quote
Once you have your robot hand, you will need to add small servo motors......... To control the servos, you will need a hobbyist microprocessor board


By its own admission, p003 is an abbreviated project idea, and list as a pre-requisite:

Quote
Once the hand is assembled, adding the servo motors, connecting the microprocessor, and writing the code for the microprocessor will require familiarity with a hobbyist microprocessor board (like ones using ArduinoTM, PICĀ®, or similar). The student should be comfortable with connecting, programming, and testing projects on these boards.


Title: Re: Need some help for a science project.
Post by: Falchion on Jan 20, 2013, 04:56 am
Oh. Now I understand what you mean. I did sweep and it worked, but I haven't tried knob yet, because I don't have a potentiometer.
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 20, 2013, 04:57 am
I'll figure it out myself I guess.
Title: Re: Need some help for a science project.
Post by: JimboZA on Jan 20, 2013, 05:06 am

I'll figure it out myself I guess.


Well, yeah isn't that the whole idea? (But with a little help from your friends here too.....)

So, what you need to do now, now that you a) have a hand and b) can get a servo working ala sweep, is figure out how to get the servo to activate the fingers.

You see by now that the servo axle (with one or other of those plastic thingies attached- they're called "horns") goes back and forth. So you need to experiment with how that can (for example) pull one of the finger strings to clench the finger. That experiment will involved figuring out how to mount the hand and the motor on some kind of support, in the correct position relative to each other so that when the horn moves, the string clenches the finger without anything snagging.

I haven't read the hand instructions fully.... what opens the finger when you release the string?- is it just the "springiness" in the straw's plastic at each knuckle? Assuming that, then moving the horn one way will pull the sting and clench the joint; moving the horn the other way will release the tension and the straw will spring back.

Once you have that working on one knuckle you can then extend the idea to the whole project. I think you will be challenged by the space that the motors will take up: you'll have to engineer the positioning carefully to get the strings pulling and releasing freely.

Edit.... you should consider micro servos, like the one I show in my previous pic of the "elbow"... they take up about 1/8 of the room of standard servos
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 20, 2013, 05:38 am
Thank you for the advice. I'm going to be working tirelessly on this project all weekend and on my day off from school too.
Title: Re: Need some help for a science project.
Post by: arduinohabib on Jan 20, 2013, 05:48 am
That's the spirit! I had a time when I would bring a bunch of electronic components and sometimes my Arduino to school and secretly experiment during classes.
Good luck!
Title: Re: Need some help for a science project.
Post by: JimboZA on Jan 20, 2013, 05:59 am
Quote
bunch of electronic components and sometimes my Arduino to school and secretly experiment during classes.


And the result was the spaghetti tangle in your av, right?  8)

@Falchion.... take it slow and carefully. Get a plan together, don't try attach a zillion servos to a zillion strings: get one joint working then one finger. (Here's a thought.... it might be an idea to make a "test-finger", as distinct from the hand, just to simplify things while you get that sorted.) Then extend that thinking to the hand as a whole.

I think each knuckle has a string?- in theory that means one servo per knuckle... maybe you can "bunch" strings together and use one servo to move a finger?- I don't think you need to move each finger segment individually do you? So if you pull all the strings on a finger at once, you can probably clench the whole finger.

If it comes to that, maybe you can clench the whole hand with one servo?

Title: Re: Need some help for a science project.
Post by: Falchion on Jan 20, 2013, 06:12 am
This is the only part I don't get. I just don't understand how the servo will move the fingers..  :~
Title: Re: Need some help for a science project.
Post by: arduinohabib on Jan 20, 2013, 06:19 am
The servo is connected to your Arduino, I presume you will be connecting strings from the fingers to the servo, like a pupet. Then you write a program for the Arduino to rotate the servo quite exactly. (Eg. 25 degrees left)
Title: Re: Need some help for a science project.
Post by: JimboZA on Jan 20, 2013, 06:25 am
Ok, I'll try explain but difficult without a model. Have a look at the photo I attached below. I can't remember where it came from, so thanks to whoever's pic it is.

The pic isn't what you have, obviously, but shows the principle; best I can do right now. As you can see it's a gripper, so like a pair of scissors: One side stays still, the other moves. The servo is at bottom left and a wire goes from the horn (the white plastic thing with holes) across to the right hand arm of the gripper.

When the servo rotates say 20 degrees clockwise, the wire pulls the arm to the left and closes the grip. Rotate servo anti clock, and the grip is released because the wire pushes the arm back to the right

So similarly, your servo horn will pull a string and clench the finger. Only difference is (if I understand correctly) is that your string (being string) can't push, so the finger un-clenches by the springiness in the straw.

That help?
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 20, 2013, 06:29 am
Where would I put the strings? Here is picture of the "hand" if it helps at all.
Title: Re: Need some help for a science project.
Post by: michinyon on Jan 20, 2013, 06:32 am
consider the way in which your muscles and tendons bend the fingers of your own hand.
Title: Re: Need some help for a science project.
Post by: arduinohabib on Jan 20, 2013, 06:34 am
Just what I was going to say. Look at this- it will help
(http://upload.wikimedia.org/wikipedia/commons/3/38/Wrist_extensor_compartments_%28numbered%29.PNG)
Title: Re: Need some help for a science project.
Post by: JimboZA on Jan 20, 2013, 06:37 am
Well you need to attach each string to the horn of a servo- perhaps more than one string per servo if that works.

You can probably lose those rings and just tie the strings to the appropriate holes in the servo horns.

I guess you need some kind of frame to support the hand and on which you can mount the servos.

Instead of a gazillion servos, use as few as possible, enough of course to give a smooth clench of the fingers, and perhaps use a few small hooks and eyes - see photo- to route the strings so they don't tangle. If you make some kind of wooden base or frame you can screw them into the wood.

EDIT.... 15 strings means 15 servos if you don't attach more than one string to each servo. That's going to take up a huge amount of space, and be impossible to hook up to a Uno. You basically have to attach more than one string to a servo, and you'll need to figure that out by a bit of trial and error. If you pull all strings at once, does the hand clench? If so, maybe one or two servos will do the trick. Otherwise as a maximum I'd say one servo per finger. Even 5 servos will take a lot of space: if you haven't bought them yet, consider micro servos.
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 20, 2013, 06:43 am
I UNDERSTAND NOW!
Title: Re: Need some help for a science project.
Post by: arduinohabib on Jan 20, 2013, 06:47 am
[highfive/]
Title: Re: Need some help for a science project.
Post by: JimboZA on Jan 20, 2013, 06:55 am
Excellent....

Word of caution with servos: even tiny ones are quite strong and they move quite quickly.

Here's what I'd do: build a dummy "test" finger that you can afford to destroy if the servo goes wild... That way you won't rip your whole hand to pieces. Then set up a test rig with that finger and a servo mounted on a wooden frame or something, and or rope some folk in to hold stuff for you. Position the servo and its horn so that it looks like it will pull smoothly, then turn the servo motor by hand to test it, ie not under power! Note that where you push the horn onto the servo- called a spline- you can position the horn on the teeth to get the best angle.

You've used the sweep program you said?- so modify that just to sweep from say 0 to 10 and back. Increase the delay to much longer one just to be safe, and then make it smaller again once you check nothing is snagging. If you get a snag I think the servo might tear stuff, so be careful.

Well done so far... you're doing great and you get 10/10 for persistence!
Title: Re: Need some help for a science project.
Post by: arduinohabib on Jan 20, 2013, 07:05 am
Do you need help programming the Arduino?
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 20, 2013, 07:08 am
I need all the help I can get.
Title: Re: Need some help for a science project.
Post by: JimboZA on Jan 20, 2013, 07:14 am

I need all the help I can get.


Yeah but not to the extent where you don't learn anything.....

Get one servo working, clenching a finger using sweep as I suggested, with suitable changes for the range of movement and the delay.

Then tie another string to another servo.... change the program to have more than on servo attached and double up the part that does the movement of say myservo1 and myservo2 (or finger1 and thumb or whatever) and get two fingers or knuckles or whatever clenching.

Get each piece working as you go, and save old versions of sketches so you can backtrack to the last version that worked if you make a screwup
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 21, 2013, 12:09 am
I don't understand how to add multiple servos to the breadboard... I read this tutorial (http://rcarduino.blogspot.com/2012/04/servo-problems-with-arduino-part-1.html),and I don't get how he added the last 4(?) servos towards the end. I did Sweep on the Arduino UNO, but I don't think there are enough ports on it to support many servos at once. Can I get some help?  :(
Title: Re: Need some help for a science project.
Post by: PaulS on Jan 21, 2013, 12:33 am
Quote
I did Sweep on the Arduino UNO, but I don't think there are enough ports on it to support many servos at once.

A port consists of 8 pins. It only takes one pin to drive a servo. The UNO has more than enough pins to drive 4 servos.
Title: Re: Need some help for a science project.
Post by: JimboZA on Jan 21, 2013, 04:15 am
Quote
I don't get how he added the last 4(?) servos


Well you only need one pin per servo for control remember, the power being taken care of off the Arduino. Let's say you have the following lines in your code (extract from sweep):

Code: [Select]
Servo myservo;

myservo.attach(9);

myservo.write(pos);


You could have this (incomplete code!) for three servos:

Code: [Select]
Servo myservo;
Servo myotherservo;  // <<<< note new names; you would call these "thumb", "middlefinger" maybe
Servo yetanotherservo;

myservo.attach(9)
myotherservo.attach(10)  // <<<<<<< note the new pin numbers for the yellow / orange control wire
yetanotherservo.attach(11)

myservo.write(pos);

myotherservo.write(pos);

yetanotherservo.write(pos);


So how did you get on yesterday?- Did you get one finger clenching and unclenching?

Quote
What is that cord on the battery holder called? I really need one.


No idea
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 22, 2013, 02:55 am
I'm on step 3 of this tutorial (http://rcarduino.blogspot.com/2012/04/servo-problems-with-arduino-part-1.html) and the servo doesn't move when I upload the sketch. Can I get some help?
Title: Re: Need some help for a science project.
Post by: Quick5pnt0 on Jan 22, 2013, 03:04 am

I'm on step 3 of this tutorial (http://rcarduino.blogspot.com/2012/04/servo-problems-with-arduino-part-1.html) and the servo doesn't move when I upload the sketch. Can I get some help?


Post your sketch and a picture of your wiring.
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 22, 2013, 03:19 am
// Multi Sweep, Duane B
// Using the servo library created by Michael Margolis
// to control 12 Servos with one Arduino Uno

#include <Servo.h>
// Sample sketch for driving 12 Servos from an Arduino UNO, servos are attached to digital pins 2,3,4,5,6,7,8,9,10,11,12,13

#define CONNECTED_SERVOS 12

// macro just adds two - the first servo is attached to digital pin 2, this gives us upto 12 servos - digital 2 to 13
#define SERVO_TO_PIN(x) (x+2)

Servo myServos[CONNECTED_SERVOS];

#define COUNT_DOWN -1
#define COUNT_UP +1
#define INCREMENT 10 // move in steps of 10 milliseconds

int nPulseWidth = DEFAULT_PULSE_WIDTH ; // 1500, defined in servo.h
int nDirection = COUNT_UP;

volatile unsigned long ulStart = 0;
volatile unsigned long ulStartToEnd = 0;

void setup()
{
  // attach the servos
  for(int nServo = 0;nServo < CONNECTED_SERVOS;nServo++)
  {
    myServos[nServo].attach(SERVO_TO_PIN(nServo));
  }
 
  // the library sets all servos to 1500 ms pulse width by default, this is center for a steering servo
  Serial.begin(9600);
  Serial.println("Completed setup"); 
}

void loop()
{
  delay(10);  // give the servos time to move after each update
 
  if(ulStartToEnd)
  {
    Serial.println(ulStartToEnd);
    ulStartToEnd = 0;
  }
 
  nPulseWidth += nDirection * INCREMENT;
 
  if(nPulseWidth >= 2000)
  {
    nPulseWidth = 2000;
    nDirection = COUNT_DOWN;
  }
 
  if(nPulseWidth <= 1000)
  {
    nPulseWidth = 1000;
    nDirection = COUNT_UP;
  }
 
  for(int nServo = 0;nServo < CONNECTED_SERVOS;nServo++)
  {
    myServos[nServo].writeMicroseconds(nPulseWidth);
  }
}
Title: Re: Need some help for a science project.
Post by: JimboZA on Jan 22, 2013, 04:09 am
Hi-

I can't figure that circuit out from that pic. What's that mishmash of wires on the breadboard?

You need to take a clearer pic- maybe straight down from above?- and also draw a circuit on paper and post that as well.

Here's a test you should do: with the circuit like it is, use the SWEEP sketch. If necessary change the pin number in sweep to match the pin you used for the servo control- looks round about pin 10 or so from that photo?- and compile and upload to Uno.

Code: [Select]
myservo.attach(9); <<<<<<<<<< make sure this number is correct in sweep

Assuming sweep works, you'll at least know that the servo and the circuit are good. If servo doesn't sweep, and we know the sweep sketch is good, then you can try see what's wrong with the circuit.

Edit.... To make your sketch easier to read, when you post code you should select it all and hit the # button above the  ;) smiley. That formats the code like mine in this post.
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 22, 2013, 04:46 am
Here a close up.
Title: Re: Need some help for a science project.
Post by: JimboZA on Jan 22, 2013, 05:39 am
Quote
Here a close up.


Still can't make it out, it's very fuzzy and the angle's crap. We're trying to help, but you're not making it easy for us.

Draw the circuit neatly and take a clear pic of that.... You could also use Fritzing (http://fritzing.org/) to make a pic: advantage of that is that as you do the Fritzing pic it kinda forces you to think about the circuit.
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 22, 2013, 06:17 am
I'm downloading it right now. Sorry for the late replies.
Title: Re: Need some help for a science project.
Post by: JimboZA on Jan 22, 2013, 06:20 am
Fritzing will also be useful when you hand the project in. You can print them out and use them in your report, or on your presentation boards or ppt shows.

It's easy to use- there's a library of standard stuff including what you need: breadboard, servos, batteries, wire etc.

But if you're pushed for time, draw the circuit on paper and take a pic of that to post.
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 22, 2013, 06:38 am
Here ya go. http://fritzing.org/projects/multiple-servo-setup/
Title: Re: Need some help for a science project.
Post by: JimboZA on Jan 22, 2013, 06:46 am
According to that I think you have the power to the servo back to front.... looks to me like red power to servo black and black power to servo red?

And you have the control on pin 13.... make sure that pin is one of the ones used in the sketch
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 22, 2013, 06:52 am
Well I'll be heading to bed now. Thanks for all the help, and I will start fixing my mistakes tomorrow.  XD
Title: Re: Need some help for a science project.
Post by: wildbill on Jan 22, 2013, 01:10 pm
When I flipped the power connections to a servo, it destroyed it. Bear that in mind once you have it correct and it still doesn't work.
Title: Re: Need some help for a science project.
Post by: JimboZA on Jan 22, 2013, 01:16 pm

Bear that in mind once you have it correct and it still doesn't work.


Unless of course (as I hope) it was a Fritzing transcription error not an actual error....
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 24, 2013, 05:02 am
Is six batteries too much power for the servo motor? I'm using 6 lithium ion batteries instead of 4 AA's in the tutorial.
Title: Re: Need some help for a science project.
Post by: JimboZA on Jan 24, 2013, 05:24 am
You need to be more specific than that with a question: what voltage do the servos require?- usually 4.8 to 6V but check the maker's specification sheet. Then what voltage do those batteries provide... then you can answer your question yourself. I hope you have a meter, and can check the voltage of the batteries? If not, you really really need one for this kind of work

The word "power" has a specific meaning and is volts x current (amps), although I suspect you mean volts. As long as the current the battery can supply is more than the motors require, and the voltage is in the range required, you should be ok.

Battery provides too high a voltage and boom.
Battery provides too low a voltage and probably motor wont work.
Battery provides too low a current and I'm not sure... might damage the battery by trying to draw too much, dunno
Battery provides too high a current, no problem because devices only draw what they need.

Title: Re: Need some help for a science project.
Post by: Falchion on Jan 24, 2013, 06:05 am
It says here that its 1.5v. http://data.energizer.com/PDFs/l91.pdf
Title: Re: Need some help for a science project.
Post by: JimboZA on Jan 24, 2013, 06:13 am
Yes but you have them in a holder thingy according to your photo-1 from the other day. That will connect them + to - inside the holder, known as "in series" and the voltages add up. So that thing will be putting our 6 x 1.5 = 9v nominal.

It may even be more, if those fresh batteries are more than 1.5 out of the packet. So yeah, you may well be putting too many V's into the motor.
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 24, 2013, 06:17 am
Me and a friend were discussing this at school, and he told me that the servo might have died. Should I just use 4?
Title: Re: Need some help for a science project.
Post by: JimboZA on Jan 24, 2013, 06:20 am
You need to answer that question yourself by looking at the maker's spec sheet and providing whatever voltage it says there.

Do you have a multi-meter (http://adafruit.com/products/850)?
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 24, 2013, 06:27 am
No. I can't get one either, because my mom doesn't want to buy anymore things for my science project.
Title: Re: Need some help for a science project.
Post by: JimboZA on Jan 24, 2013, 06:33 am
That's a shame... suggest to her that every home should have one anyway, and it'll be a home item not a science item.  8)

Btw, your Fritzing diagram the other day showed you had the power hooked up with + and - reversed... I hope that was a mere Fritzing error not a real error? I've never hooked a servo up with the polarity reversed, but I suspect it's bad for it.
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 24, 2013, 06:47 am
Alright. I'll keep that in mind.
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 25, 2013, 05:48 am
So I tried to do sweep with my Uno, and it decided that it does not want to work anymore, so now I have to do a completely different science project.
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 25, 2013, 05:49 am
I also have an extra that I haven't touched at all and that isn't working either.
Title: Re: Need some help for a science project.
Post by: arduinohabib on Jan 25, 2013, 05:59 am
Aw... Sorry to hear that. Don't drop Arduino now you've picked it up though...
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 25, 2013, 06:03 am
Nevermind. It was a false alarm.  :smiley-roll:
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 25, 2013, 06:36 am
However, one of them did die on me. Whenever I plug the USB in, the green LED turns on and then immediately turns off. 
Title: Re: Need some help for a science project.
Post by: arduinohabib on Jan 25, 2013, 06:51 am
The led on the servo, on the computer or on the Arduino? If it's on the Arduino, there's a short circuit and you must be very careful or you might destroy your Arduino.
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 26, 2013, 01:04 am
The Arduino.
Title: Re: Need some help for a science project.
Post by: arduinohabib on Jan 26, 2013, 02:10 am
The green led? YOu mean the TX and RX leds?
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 26, 2013, 03:02 am
Yeah, that's what I'm talking about. It started working again though.
Title: Re: Need some help for a science project.
Post by: arduinohabib on Jan 26, 2013, 03:28 am
The TX and RX leds only flash when your uploading a sketch.
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 26, 2013, 04:19 am
Woops. I actually meant the ON LED.  :smiley-roll:
Title: Re: Need some help for a science project.
Post by: arduinohabib on Jan 26, 2013, 04:30 am
You must be careful when that happens. It means there's a short circuit somewhere.
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 26, 2013, 05:03 am
This is getting out of hand... I'm doing everything it says in this tutorial, (http://rcarduino.blogspot.com/2012/04/servo-problems-with-arduino-part-1.html) and it still isn't working... I have to have this thing done by February 4th, and this is worth a TON of points, so if it doesn't get done, my grade will suffer...
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 26, 2013, 05:13 am
Wait a second... How do I add a servo? Here's the line of code.
Quote

  // attach the servos
  for(int nServo = 0;nServo < CONNECTED_SERVOS;nServo++)
  {
    myServos[nServo].attach(SERVO_TO_PIN(nServo));
  }

Title: Re: Need some help for a science project.
Post by: JimboZA on Jan 26, 2013, 06:05 am
At the top of DuaneB's code it says this...

Code: [Select]
#include <Servo.h>
// Sample sketch for driving 12 Servos from an Arduino UNO, servos are attached to digital pins 2,3,4,5,6,7,8,9,10,11,12,13

#define CONNECTED_SERVOS 12


It sweeps a whole load of servos on those pins....

So to attach servos to the board, you control them by putting their yellow / orange wires into those pins.

(The #define CONNECTED_SERVOS 12 tells it there are 12 and you could reduce that number I guess to just have however servos you have)

This part:

Code: [Select]
// attach the servos
 for(int nServo = 0;nServo < CONNECTED_SERVOS;nServo++)
 {
   myServos[nServo].attach(SERVO_TO_PIN(nServo));
 }



... uses the value of "CONNECTED_SERVOS" which is 12 if you didn't alter it at the top as the upper limit of a counter in a loop and runs the "attach" line as many times as you have servos to as many pins as there are servos.

This is an automated way of doing what I showed you a few posts back where I had something like myservo.attach and anotherservo.attach. The myServos[nServo] in Duane's code is a way of automating say myServos5 and myServos9 or whatever where nServo is a variable instead of hardcoding the same line a stack of times each with a different number.
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 26, 2013, 06:32 am
This is all so confusing, but it has to get done...
Title: Re: Need some help for a science project.
Post by: PeterH on Jan 26, 2013, 03:40 pm

This is all so confusing, but it has to get done...


After seven pages I've lost track of what you have got working, and where you're stuck.

What's the current problem?
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 26, 2013, 06:20 pm
It's cool. Here's where I am right now... I built the hand itself, but I need to get multiple servo's running at once, so I can tie the strings on the fingers into the holes in the servo motor and I'm having some trouble getting 1 to run on external power.
Title: Re: Need some help for a science project.
Post by: JimboZA on Jan 26, 2013, 06:34 pm

I'm having some trouble getting 1 to run on external power.


Here's my suggestion then:

1- Put DuaneB's multi servo sketch aside for now.
2- Reload sweep, which I think u said was working before?
3- Carefully check the wiring* of the one servo, your Fritzing pic showed you had the red and black confused. Keep the Arduino powered from the PC...
4- Run sweep to verify that the servo runs from external power.
5- Then and only then, edit sweep along the lines of my suggestion many posts back, to have a second servo ("myOtherServo" for instance) on another pin and run that new sketch to verify two servos

Then we'll talk some more...

* wiring is battery +ve to servo red, -ve to servo black and also Arduino ground, yellow / orange to Arduino pin to which servo is attached in sketch. Check the voltage is what the servo needs, probably 4.8 to 6, not the 9 you were using
Title: Re: Need some help for a science project.
Post by: JimboZA on Jan 26, 2013, 06:51 pm
Something along the lines of the Fritz attached
Title: Re: Need some help for a science project.
Post by: JimboZA on Jan 26, 2013, 07:07 pm
And two would be thus....

Make sure the yellow wires go to the pins you attach the servos to in the skecth
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 26, 2013, 08:52 pm
Will a battery holder that can hold 6 batteries work with only 4 inside?
Title: Re: Need some help for a science project.
Post by: AWOL on Jan 26, 2013, 08:57 pm
Not normally, no
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 26, 2013, 09:01 pm
Thanks. It works fine with 6.  :)
Title: Re: Need some help for a science project.
Post by: retrolefty on Jan 26, 2013, 09:02 pm

Will a battery holder that can hold 6 batteries work with only 4 inside?


Only if you jumper out the two empty spaces with a soldered jumper wires, or find solid brass rods of the same size as the batteries to use as 'dummy cells'.

Lefty
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 26, 2013, 09:38 pm
Hmmm... I got one servo running from external power on pin 9, but the code I tried to write (newbie programmer here) doesn't seem to work. I looked at the reference library on the Arduino website too.
Title: Re: Need some help for a science project.
Post by: AWOL on Jan 26, 2013, 09:44 pm
Quote
, but the code I tried to write (newbie programmer here) doesn't seem to work

That's sad.
(Hint)
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 26, 2013, 09:58 pm
#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
  }
}
Title: Re: Need some help for a science project.
Post by: AWOL on Jan 26, 2013, 10:00 pm
OK, so what does it do that it shouldn't and what doesn't it do that it should?
Code tags would be good too.
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 26, 2013, 10:04 pm
It doesn't move at all when I upload it.
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 26, 2013, 10:39 pm
And everything is plugged in correctly too.
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 26, 2013, 11:42 pm
I setup the 2nd servo just like in the picture, and the power is somehow routed to the first one... Why?
Title: Re: Need some help for a science project.
Post by: AWOL on Jan 26, 2013, 11:48 pm
Quote
the power is somehow routed to the first one..
how?
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 26, 2013, 11:53 pm
I have no idea. I'm going to start over.
Title: Re: Need some help for a science project.
Post by: AWOL on Jan 26, 2013, 11:55 pm
Well, you're the one with the eyeball on the subject.
Guessing games are for children.
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 26, 2013, 11:58 pm
Gee, thanks...
Title: Re: Need some help for a science project.
Post by: AWOL on Jan 27, 2013, 12:04 am
You're welcome.
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 27, 2013, 12:09 am
This isn't going to work and I'm running out of time, so I think I'll just use one servo...
Title: Re: Need some help for a science project.
Post by: JimboZA on Jan 27, 2013, 05:34 am
I'm getting more confused by the minute here....

You say you have the one servo working.... using the sweep sketch or what?

Then you say the second isn't working, but the code you posted (which I think is virgin sweep?) is only for one servo. Post the code (inside # tags) for the sketch which purports to run two servos.... it should be much like sweep but with code added to "double up" for the second servo as explained a week or so back.

Hint on breadboard: the power rails are usually split in the middle: there is no connection between the left and right side of the board. Have you hooked the second servo on the right hand side of the split? My Fritz showed the 2nd servo connected towards the left. If you need to use power from the right you'll probably need to jump that gap as shown attached. Without a multi meter or a test LED you can't tell if your breadboard needs that bridge or not.

My suggestion a while back was to set up a dummy finger to minimise damage to your hand if the servo goes brainless (ie moves too far too fast and rips things to bits)... if you DO actually have one servo working with sweep, now's maybe the time to hook it up to one test finger and get the finger clenching.

Then yes, maybe ditch the second servo in the interests of time and get all fingers clenching with on servo. You'll need to engineer the string layout on a board or something to get the angles right and to prevent tangling...
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 27, 2013, 06:30 am
I'll give that a shot, but if I can't get it to work, then I'll just stick with one servo.
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 27, 2013, 06:32 am
And I happily thank all of you guys for helping me with and teaching me more about robotics.  XD
Title: Re: Need some help for a science project.
Post by: JimboZA on Jan 27, 2013, 06:39 am

I'll give that a shot, but if I can't get it to work, then I'll just stick with one servo.


With careful layout of the strings, you'll probably be able to get it clenching with one.

Clarify for me please, I didn't look at the hand project too carefully when you posted originally: does the unclenching rely on the springiness of the straw?
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 27, 2013, 06:41 am
I believe so. The guide said as long as the straw doesn't crack when you apply pressure to it, it should work.
Title: Re: Need some help for a science project.
Post by: JimboZA on Jan 27, 2013, 07:17 am
Yeah thought so, so go verrrrrry carefully when you hook the servo up.

Servos kick off with quite a wrench, as you may have noticed if you were holding one when it moved. The torque (turning strength) is many orders of magnitude (x10's) more than you need, I'm sure. Have your sweep move only a few degrees maybe, and make the delay longer between steps.

I think I suggested earlier that once you have it hooked up a servo to your test finger, turn the servo by hand to start, to check that nothings snagging and estimate by eye what the range of degrees should be.

Title: Re: Need some help for a science project.
Post by: JimboZA on Jan 28, 2013, 03:26 pm
You might have a look at this thread (http://arduino.cc/forum/index.php/topic,108293.0.html).

Similar to yours in that strings move the fingers with lots of servos. It might help you with the layout of the physical aspects......

Jim
Title: Re: Need some help for a science project.
Post by: Falchion on Jan 29, 2013, 11:09 pm
That's amazing.
Title: Re: Need some help for a science project.
Post by: Falchion on Feb 07, 2013, 03:48 am
Guess who made TOP 10 in the science fair?  :smiley-mr-green:
Title: Re: Need some help for a science project.
Post by: JimboZA on Feb 07, 2013, 05:31 am
Awesome.... well done!

So post a few pix so we can see how the whole thing turned out....

Title: Re: Need some help for a science project.
Post by: Falchion on Feb 09, 2013, 05:57 am
Here is a picture of the finished product.  :smiley-mr-green:
Title: Re: Need some help for a science project.
Post by: Falchion on Feb 09, 2013, 06:04 am
Here's the board and the hand too.
Title: Re: Need some help for a science project.
Post by: JimboZA on Feb 09, 2013, 06:05 am
Thanks, and Well Done, again....

Looks like you used the Uno as a backing plate for attaching the hand?

Next you need to get that up on YouTube so others can see what you did and how it works.

Also I'm pretty sure the guys at Science Buddies (http://www.sciencebuddies.org/science-fair-projects/project_ideas/Robotics_p003.shtml) would be keen to see that you put their motor idea into practice.

Edit: Nice display board, too
Title: Re: Need some help for a science project.
Post by: Falchion on Feb 09, 2013, 06:11 am
I'll make sure I do that. Also, I might be a potential winner for the science fair at my school, and if I get 1st or 2nd place, I get to go to a prestigious college to show my project off.  8)
Title: Re: Need some help for a science project.
Post by: JimboZA on Feb 09, 2013, 06:16 am
Quote
I get to go to a prestigious college to show my project off


Well that would be fantastic.

.... and maybe meet Sheldon, Leonard, Rajesh and Howard.....

Title: Re: Need some help for a science project.
Post by: arduinohabib on Feb 09, 2013, 06:24 am
WOW! Congrats!!