Hi! I have making a project (you can view the prototype in istructables). The system has two operation modes.
I want put a toggle switch to change the mode. I have read an old post where an user has the same question. Someone replied and he gave the solution.
For my application I’d have to use the third terminal connecting to another digital input and to GND, true?
I think so, correct me if I’m wrong.
That’s not the problem. I have turn on a LED when I active Mode 1 and turn on another LED when I active Mode 2.
I think I have to connect the LED in the following way:
So, If I press the toggle to the left, the LED turn on and Arduino receive HIGH level from the pin 2?
The fist schematic is already flawed… Pin2 and GND have a hard connection, it’s never going to be high.
What you want, take a 2 position switch like you used in the drawing. Connect middle pin to GND. Connect both left and right to a LED with resistor (so 2, one for each mode). The anode of both LEDs connect to 5V. Now pick left or right (doesn’t really matter) of the switch and connect it to a Arduino pin as well. Use pinMode(pin, INPUT_PULL) Done!
Thanks to both of you!!
I think I have understood you.
With the above setting when I press the toggle to the left the LED will turn on and I'll receive a HIGH level in pin 2 of Arduino (configured as pull-up)?
With the above setting when I press the toggle to the left the LED will turn on
Usually the electrical terminals are opposite of the toggle position. So with the toggle to the right, the switch will (probably) be on. That connects the switched-side of the LED to ground and the LED will turn on.
and I’ll receive a HIGH level in pin 2 of Arduino (configured as pull-up)?
When the switch is off (open) pin 2 is pulled-up by the internal pull-up resistor and by the external resistor and LED. When the switch is on, pin 2 is pulled to ground (through the switch) so it will be LOW.