Double Pole Double Throw Switches w servos

Hello I am John
and I'm very new to this I sort of understand the code I know I can just down load it however can someone show me how to hook everything up and tge hardware you used

I am trying to control multiple servos with double pole double throw switches for each and use the other side of the switch for signaling lights

for model railroad turnouts

any help would be great
Thanks you
John

So when the switch is closed, the servo moves forward 90 degrees and when the switch is open, the servo moves back 90 degrees.

Something like that?

yes exactly
very simple very primitive

i need to understand the simple thing first
Thank You

I have done this before using another application (Pololu)
this is my first venture with Arduino

All New to me

This is a good tutorial on how to use a servo with Arduino UNO

Thank you Jim
May I call you Jim?

Very well laid out I will do this tutorial on my work bench and go from there

I guess I can replace the POT with the DBDT switch??

Thank you Thank you very much!
John
63 year old Truck Driver and just trying to keep up with the electronics in Model Railroading!!

Ignore the pot example. The sweep example shows you how to go 0 o 180 the back from 180 to 0. That is what you want to do. Now you need to connect the toggle switch and read it via a digitalRead()
Here is how to connect the toggle

Don't put email addresses and phone numbers in these posts
Delete your last post

This sketch (program) show how to turn an LED OFF/ON with the toggle switch
You need to figure out how to combine the relavent parts of both sketches to do what you want.

/*
  State change detection

  This example shows how to detect when a toggle switch changes from off to on
  and on to off with an LED indicator

  The circuit:
  - Toggle switch connected between pin 2 and GND
  - 5.1K resistor connected between pin 2 and 5V
*/

const int  buttonPin = 2;    // the pin that the switch is attached to

byte buttonState = 0;         // current state of the button
byte lastButtonState = 0;     // previous state of the button

void setup() 
{
  // initialize the button pin as a input:
  pinMode(buttonPin, INPUT_PULLUP);
  
  // initialize the LED as an output:
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, LOW);
  
  // initialize serial communication:
  Serial.begin(9600);
}

void loop() 
{
  // read the pushbutton input pin:
  buttonState = digitalRead(buttonPin);

  // compare the buttonState to its previous state
  if (buttonState != lastButtonState) // if the state has changed
  {
    if (buttonState == LOW) 
    {
      // if the current state is LOW then the button went from off to on:
      Serial.println("on");
      digitalWrite(LED_BUILTIN, HIGH);
    } 
    else 
    {
      // if the current state is HIGH then the button went from on to off:
      Serial.println("off");
      digitalWrite(LED_BUILTIN, LOW);
    }
    // Delay a little bit to avoid bouncing
    delay(50);
  }
  // save the current state as the last state, for next time through the loop
  lastButtonState = buttonState;
}

Jim, we need to keep things as simple as possible for @johnd1024 at this stage of learning. There is (probably) no need for the 5.1K resistor. There is (probably) no need for the wire from the resistor to 5V. There is no need for the plugblock. I'm certain you know these things as well as, if not better than, I do. Can you not find a more suitable diagram with fewer extraneous components and connections?

I do appreciate that you did not present that often used diagram showing all the different ways of connecting buttons. That must scare the sh*t out most beginners!

For the toggle switch, I would recommend using the center common pin to connect to the Arduino digital pin and the other two switch terminals to the voltage references ( one to ground, one to 5V). This way the switch will output either a high or low depending on position and only 1 digital pin is needed for the toggle switch.

@johnd1024
If you have any more questions, just ask.

Jim-p
and the rest

thank you all for such good advice i will be doing each of this projects in the coming week or 2
i have been swamped at work however i see a break coming and i can get this project under way
will keep you all up to date on my progress
again thanks for your time

John

Have fun!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.