Pages: [1]   Go Down
Author Topic: Servo Motor Control  (Read 591 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello Friends,

I have a project where I have some externally powered servos. The arduino is powered separately and I am using it to control the position of the motors, which I already understand to do. I'm trying to make a wired controller connected to the arduino so that when a click button is  pressed, it would execute lines of code to control the servos. I'm not sure what I'm looking for code-wise or how the click button should be wired to the arduino.

Any suggestions?

I also, want to eventually make the controller wireless. Maybe just over RF or bluetooth. Any suggestions?

Thanks!
Logged

Queens, New York
Online Online
Faraday Member
**
Karma: 84
Posts: 3430
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Start with the basic servo examples, knob and sweep, and maybe the button examples and go from there.

If you get stuck, come back and we'll help you.
Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

0
Offline Offline
Tesla Member
***
Karma: 141
Posts: 9470
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Test code for two buttons controling a servo.

Code:
//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);
  }
}

Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks!

In this programming scheme, do I need to to run the power through the button?
Logged

0
Offline Offline
Tesla Member
***
Karma: 141
Posts: 9470
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks! In this programming scheme, do I need to to run the power through the button?

No, power is supplied to the buttons from the pins by making the pins high.
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm having trouble getting this to work still..

Here is my wiring setup:

Pin 7 to servo motor, motor powered separately

pin 5 to push button (https://www.sparkfun.com/products/9190) to ground

Pin 4 to push button to ground

Is the problem the type of button I'm trying to use?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, when I hold the button wired to pin 4, the motor rapidly wiggles back and forth. When I press and hold the other button, nothing happens at all.. I'm trying to get it so that once, say button four is triggered, I can use the sweep function to have the servo move to various positions without having to hold the button down.
Logged

UK
Offline Offline
Shannon Member
****
Karma: 222
Posts: 12562
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What code are you running? Have you got Serial.print statements in place so that you can confirm your button presses are being detected correctly?
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Pages: [1]   Go Up
Jump to: