DPDT Switch Input

Hello,
I have students working on a project, and they have a double pole, double throw switch (MTS-2) that runs a motor with 12v input/output (it is a pretty simple circuit). We would like to capture the input from the switch using an Arduino, and can simply use the Arduino voltage (5v or 3.3v) to power the switch (does not need to be 12v).

However, with the double pole, there are only two wires out. The position of the pole determines forward or backwards rotation of the motor (so the polarity simply reverses). Basically, for practice, we want to program a virtual environment using the controller that they already have (we cannot change the wiring in the controller).

I know that the Arduino only wants positive inputs, but I'm hoping someone might be able to shed light on how to capture the input based on the two 'on' conditions.

Thank you, in advance, for any information provided to point us in the right direction!

Use INPUT_PULLUP on the inputs.

ardui;no dpdt switch.png

ardui;no dpdt switch.png

Assuming there there is no center off position, just connect one pole to one input.

For 12v operation, add a (12v to 5v) voltage divider on the input.

If the input is low, this will be fwd; if the input is high, we will assume rev.


Suggest you add 4 kickback diodes to the motor, configured for motor reversal operation.

There's lots of conditions that can be detected, but it also depends on how its wired. Could you post an example schematic?

Hello, Thank you so much for your time and input! I really appreciate it. I have been searching for a good schematic, and this is the one that I could find online. Since we are just using the controller for input back to the arduino, we should be able to just use the 5v or 3.3v directly from the arduino. We do not need 12 volts as we do not plan on running the motors in real time, just using the controller for an 'emulator'.

We are able to get feedback from a switch, and all of the code works. Just confused by the 'switching of polarity' from positive to negative and back, and I know that the arduino does not like negative voltage; so trying to be super careful.

We did try hooking the battery inputs just to the 3.3v, and we could get the forward motor switches working. But if we try to hook the negatives up the same way, the switches are always on (which was to be expected).

Thank you for your time and guidance. I really appreciate it! This challenge is pretty cool!!! and we are learning a lot about circuits.

Screenshot - motor controller.png

Screenshot - motor controller.png

rossbr:
Since we are just using the controller for input back to the arduino, we should be able to just use the 5v or 3.3v directly from the arduino.

So the Arduino +5v will substitute for the battery +12v?

rossbr:
We do not need 12 volts as we do not plan on running the motors in real time, just using the controller for an 'emulator'.

The Arduino is to somehow emulate the motors?

Yes. We are trying to just use the 5v in place of the 12v batttery. We just want to use the analog pins to detect when the switch is in 'on-forward' position, or 'on-reverse' position.

Any digital I/O pin, and that includes the analog-capable input pins, can be used for this*. Use [url=http://[INPUT_PULLUP](Arduino Reference - Arduino Reference) and check for a LOW.

  • if an UNO is used avoid pins 0 and 1 since they're used for uploading sketches.

Cool. Thank you for your time and input! I will try this! We are using a Lenardo, as we are emulating keystrokes after we detect the input.

I was looking at this tutorial after your first post on using the INPUT_PULLUP: https://www.arduino.cc/en/Tutorial/DigitalInputPullup and they are not using a resistor for current limiting. We did use a 220 ohm resistor in just our switch testing. Do you think that we will need to add this, if we follow the linked tutorial? If not, can we just connect the motor pins directly to the I/O pins?

I totally appreciate your time and help! We (I) just don't want to screw anything up and we know just enough to be really dangerous! :slight_smile:

Thanks again!!

The fundamental thing to recognise, is the switch(es), can only be in one of the two positions.
If it’s not in position #1 (forward), it can only be in position #2 (reverse) unless it’s a three position switch.

You don’t need to detect both positions. The NOT position is always known.

There is a third position, it is an on-off-on switch. So, we do need to which position it is in. It reverses polarity for the motors to run forward/reverse. So, it is like tank drive, one side runs one motor, and there is an addition switch that runs the other motor. If both are in the off position, nothing is moving. Forward-off-reverse (just reversing polarity).

rossbr:
We are using a Lenardo, as we are emulating keystrokes after we detect the input.

Please provide a drawing showing how the Leonardo will be connected to everything.

rossbr:
We did use a 220 ohm resistor in just our switch testing. Do you think that we will need to add this, if we follow the linked tutorial?

S3 below illustrates the input pullup idea.

rossbr:
If not, can we just connect the motor pins directly to the I/O pins?

DO NOT CONNECT motor leads to the Arduino I/O pins! The microcontroller is designed to provide/accept logic signals. It is not capable of providing the current needed to drive a motor. There are specialized circuits/modules for that.

This is how it is setup at the moment, I have not plugged it in yet, as I was not sure about the resistors. There will not be motors hooked up to this... it is just the monitoring of the switches and what state they are in. This is a three position switch: on (forward)-off-on(reverse)

This is my initial code:

void setup() {
//start serial connection
Serial.begin(9600);
//configure pin 2 as an input and enable the internal pull-up resistor
pinMode(6, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
pinMode(13, OUTPUT);
}
void loop() {
//read the pushbutton value into a variable
int sensorVal6 = digitalRead(6);
int sensorVal7 = digitalRead(7);
//print out the value of the pushbutton
Serial.println(sensorVal6);
Serial.println(sensorVal7);
// Keep in mind the pull-up means the pushbutton's logic is inverted. It goes
// HIGH when it's open, and LOW when it's pressed. Turn on pin 13 when the
// button's pressed, and off when it's not:
if (sensorVal6 == HIGH) {
digitalWrite(13, LOW);
} else {
digitalWrite(13, HIGH);
}
if (sensorVal7 == HIGH) {
digitalWrite(13, LOW);
} else {
digitalWrite(13, HIGH);
}
}

Did you read dougp examples on input pullup...?

Yes, just no confidence in myself to do this correctly. I just hooked it all up and tried it, and it works as promised!! You guys are awesome! Thank you so much for your time and help!!!

rossbr:
Yes, just no confidence in myself to do this correctly. I just hooked it all up and tried it, and it works as promised!! You guys are awesome! Thank you so much for your time and help!!!

Keep in mind that switches are noisy and may well reqiure an amount of debounce in your code.

Thank you for your time and input! I really appreciate it! I'll watch for noise as we move forward. Thanks again, to everyone, for your time, help, and information!

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