Hello All,
First post here, So here it goes!
I want to use a servo to control a model railway track switch, how ever i don't want to be tethered to a PC to set the value (1-179) and want to do this with buttons and code.
So here is my thought, one Program set button that allows me to select the servo and then 2 other buttons to "increase" and one to "decrease" values.
Any input on this would help a lot!
That shouldn't be too hard...
Do you have a servo and an Arduino, and have you played around with the servo library?
And, take a look as some of the examples using switches & pushbuttons.
Other than the servo library, it's probably just going to require some [u]if-statements[/u] in a loop.
And if you are going to select between servos with a single button, you may need an LED indicating which servo is being addressed.
Do they use servos to switch tracks? Isn't it usually a 2-state device? Is there any need for in-between angles?
DVDdoug, I have a Uno with one servo and have messed around with it for a bit here, just need some more experienced help to get my feet wet as i am coming into this programming a bit "green".
Ideally, i wouldn't need to adjust the "angles" but due to possibly running into different mounting spots for the servo the angles that i program in the code may not be enough to operate the switch correctly.
I am looking at this to help introduce a less expensive way to control switches rather than spending $15 to $20 on a single switch motor, I could buy 6 servos and a Arduino for less than 2 regular switch motors.
Two button servo code.
//zoomkat servo button test 12-29-2011
// Powering a servo from the arduino usually *DOES NOT WORK*.
#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);
}
}