Button+Servo

Hi all I am Brand New to Arduino and i am in need of Guidance.

i have a Uno R3, with a 40kg/cm (high torque) Servo which requires 6v

now i want the arduino to move the servo at least 100 degrees when i push a button(or implement the EASY VR) to pull an object.

if anyone could direct me to the right spot or just steer me in the right direction that would be quite helpful!

thanks.

Yes, I was there a few months ago.
I suggest you start with the servo example sketch in the IDE called sweep. That will show you a lot.

Servo test code that might be of use.

//zoomkat servo button test 12-29-2011

#include <Servo.h>
int button1 = 4; //button pin, connect to ground to move servo
int press1 = 0;
int button2 = 5; //button pin, connect to ground to move servo
int press2 = 0;
Servo servo1;

void setup()
{
  pinMode(button1, INPUT);
  pinMode(button2, INPUT);
  servo1.attach(7);
  digitalWrite(4, HIGH); //enable pullups to make pin high
  digitalWrite(5, HIGH); //enable pullups to make pin high
}

void loop()
{
  press1 = digitalRead(button1);
  if (press1 == LOW)
  {
    servo1.write(170);
  }    
  
  press2 = digitalRead(button2);
  if (press2 == LOW)
  {
    servo1.write(10);
  }
}

thanks guys that was very helpful.

what would be the setup for the survo and buttons
(servo in pin 9, 5v and GRND) button in what??

Now is there a way to increase the voltage of the arduino output to 6v??

What for? If your servos are using 6V, they should accept a 5V signal from the Arduino.

its this servo.

http://www.ebay.com/itm/261192968049?ssPageName=STRK:MEWAX:IT&_trksid=p3984.m1423.l2649

but if you think it will work just fine. i guess i will try it then

Now is there a way to increase the voltage of the arduino output to 6v??

Don't know for sure how you are trying to power the servo, but do not try to power it from the 5V on the arduino board. It needs a separate power supply. The signal pin should be hooked to the arduino data output, and the ground hooked common, but not the plus voltages.

ahh! i see so a rechargable battery that is 6v run that into the poer and then both the battery ground and the servo ground into the arduino?

Yes, sounds like you’v got it.

yes i do! thanks a lot 8)

but 2 more things, what pins do the button go in to make it turn when pressed?

and finally what is a command that when its pressed then released it goes right back to its 1st position?

exapmle: press switch, Servo goes up 90 degrees then returns, know what i mean :stuck_out_tongue:

I think the sketch that zoomkat provided would be a great start.

Any pins you want!

int button1 = 4; //button pin, connect to ground to move servo

In his code it is 4 but you could make it anything…

int button1 = 5; //button pin, connect to ground to move servo

exapmle: press switch, Servo goes up 90 degrees then returns, know what i mean

How long do you want it to stay at 90 degrees? Do you want it to stay there while the button is being pressed, or just reach 90 degrees and then snap back? The code he has has two buttons when you press one it goes to 170 then when your press the next one and the servo goes to 10.

Also I have attached an image of how your servo should be attached

thanks for the picture!

and i want it to go to 90 degrees then snap back.

but where would the button go? yes any pin, but would you mind drawing it?
or ill take a stab. so have one leed on7 and the other leed on 6?

//zoomkat servo button test 12-29-2011
// edited by Drew Davis

#include <Servo.h>
int button1 = 4; //button pin, connect to ground to move servo
int press1 = 0;
Servo servo1;

void setup()
{
  pinMode(button1, INPUT);
  servo1.attach(7);
  digitalWrite(5, HIGH); //enable pullups to make pin high
}

void loop()
{
  press1 = digitalRead(button1);

  if (press1 == LOW)
  {
    servo1.write(90);
delay(1000); 
    servo1.write(0);


  }    
  
  
}

Thant code should work, but I can’t draw you a button as I don’t know which one you have… post a link.

Go look at http://fritzing.org/pages/welcome/

@drew

digitalWrite(5, HIGH); //enable pullups to make pin high

I believe you meant that to be

digitalWrite(button1, HIGH); //enable pullups to make pin high

ok by button i mean like a Pressure switch, really just a generic switch.

and the modified code, it like randomly goes off when im not using the button.. :~

and why doesn't it work when i connect it to the exterior power source? 9v battery via the power plug

Ok, a normally open push button, that will close as long as you hold the button down, then when released, it will open again. OK.

Based on the sketch from zoomkat,

int button1 = 4; //button pin, connect to ground to move servo

Connect your button to the D4 pin (data 4), and the other side of the button to ground.

Simple servo single button code:

//zoomkat servo button test 7-30-2011

#include <Servo.h>
int button1 = 4; //button pin, connect to ground to move servo
int press1 = 0;
Servo servo1;

void setup()
{
  pinMode(button1, INPUT);
  servo1.attach(7);
  digitalWrite(4, HIGH); //enable pullups to make pin high
}

void loop()
{
  press1 = digitalRead(button1);
  if (press1 == LOW)
  {
    servo1.write(160);
  }
  else {
    servo1.write(20);
  }
}

Thanks zoomkat, that should make things more clear.
So the button is connected to D4
and the servo control is connected to D7. I think that should work fine. Did that work for you StrikeForceInd ?