Self-contained DPDT Switch with OFF/ON LEDs and Arduino INPUT lead

I have an already designed enclosure for a DPDT switch with 2 LEDs (white=OFF, green=ON).

  • The common lead is fed by +5V from Arduino Mega board.
  • The OFF lead goes to the WHITE LED, then forks into the LED-protect resistor.
  • The ON lead goes to the GREEN LED, then forks into the LED-protect resistor.
  • The LED-protect resistor goes to Arduino GND.
  • The ON lead also goes to Arduino D11 INPUT pin (bypassing GREEN LED).

Arduino D11 is meant to register the position of the switch.

In this configuration, the D11 never changes (it always reads OFF, regardless of switch position).

I added a 10K resistor between the switch ON lead and D11, so now D11 reads OFF when the switch is off. However, it now alternates between ON and OFF when the switch is ON.

Also, it takes 3 seconds for D11 to read OFF when the switch is turned to the OFF position.

Is there an easy way to make this circuit work as desired (so D11 reads ON/OFF correctly), or is it doomed (i.e., my self-contained, already-made, back of the console component must be redesigned)?
LedSwitchCircuit

CODE:

const int MOTOR_SWITCH_PIN = 11;
const int MOTOR_ENABLE_PIN = 10;
**(ellipsis)**
void setup() {
  Serial.begin(9600);

  pinMode(MOTOR_SWITCH_PIN, INPUT);
  pinMode(MOTOR_ENABLE_PIN, OUTPUT);
**(ellipsis)**
}

void loop() {
  if (motorSwitchIsOn())
    Serial.println("MOTORS ON");
  else
    Serial.println("MOTORS OFF"); 
**(ellipsis)**
}

bool motorSwitchIsOn () {
  int value = digitalRead( MOTOR_SWITCH_PIN );
  Serial.print(value);
  Serial.print(":");
  return !value;
}
**(ellipsis)**

Nice Schematic. I am assuming the software will need to change a bit. Remove R2 and place it between D11 and Ground, this is to prevent a possible voltage level from the White LED. D11 will be high when on and low when off.

Your circuit won't work.

Try this.
Both LED anodes to 5volt.
Two current limiting resistors for the two cathodes of the two LEDs, going to 1 and 3 of the switch.
Pin 2 of the switch to ground.
Arduino pin to 1 or 3 of the switch, with this in setup
pinMode(LEDpin, INPUT_PULLUP);
Leo..

That worked for me, gilshultz. Thanks!

I will use this solution, for now, unless someone knows a reason it might cause problems with the controller.

UPDATED schematic:

LedSwitchCircuit-edit

Thanks for your advice, Wawa!

gilshultz's solutionseems to work, but I will look at yours when I get more time. I would like to understand these circuits better, and I believe I read somewhere that the way I have the switch wired is not recommended.

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