Newbie Question-Rotary Switch

Hello all,

Has anyone ever connected a rotary switch to an Uno R3? I can't find any switches that are specifically designed for the Arduino. I am making a light with multiple functions (PIR, darkness detection, blinking). Would this be the best way to change the modes for my light? Which pin should I assign the rotary switch to? Thanks for your help :slight_smile:

You can use Finite State Machine with single button will do.

http://playground.arduino.cc/Code/FiniteStateMachine

Hi Billy,

Thanks for the reply. I am afraid your link was a bit too complicated for me to understand. I haven't even begun to learn how to code :o

Any suggestions on where to start learning the language?

The simplest rotary switch is a single pole N way. Where N is the number of states. You wire up the common to ground and each output to an Arduino input and you enable the internal pull up resistors in your code.

There are hex switches, with four outputs for connecting to four inputs. This gives you 16 different patterns of high and low on these four outputs one for each of the 16 switch positions.

http://www.jameco.com/1/3/hexadecimal-rotary-switch

http://www.mouser.co.uk/ProductDetail/Apem/PT65503/?qs=sGAEpiMZZMsfGXvUAbE5P77o%252bw6vaF%2FJkM7TbLN7lPU%3D

jshields:
Any suggestions on where to start learning the language?

How about the "learning" tab at the top of this page? :slight_smile:

Excellent advice guys and thanks for the links.

there are different ways to select some part of your program to run

there is no arduino specific hardware except the shields. everything else is just parts that you have to make work.

as for your rotary switch, if you put a resistor on each part of your multi pole switch, you could bring that value back to an analog pin. use a voltage divider with a fixed resistor. now, each switch point will cause a different voltage on the voltage divider circuit, the analog input can see that voltage and know what position your switch is in. this offers 1 pin, multiple switch positions.


a one button option is that with each press, it goes to the next thing.
press once and the LED turns on, press twice and it blinks slowly, press a third time, it blinks faster, a fourth time.....
at some point you would come back to the first stage of 'LED turns on'.


you can use a timer to determine state

you hold the momentary switch, the type that completes the circuit when pressed, then opens when released.

if you hold it for less than 1/4 seconds, nothing happens, this would be your debounce.
hold it for 1/4 to 1 seconds, and you do one thing, hold it for 1-2 seconds and some other thing happens,
the longer you hold it, the more things you can do.

this is usually used with a feedback to let you know what stage you would be in if you released.
I have one with 4 stages, the 4th being turn everything off

as for your rotary switch, there is a reason we do not use them often. you use one pin for each stage of the switch,
that type of switch does not offer any benefit because we can do the same thing with one pin, pins are a valuable commodity and we do not use them if we do not have to. we can do the same thing with a simple, common button switch and not have to buy a special rotary switch.

also, you can get a thumb button switch

http://www.mpja.com/BCD-Thumb-Pushbutton-Switch/productinfo/32083+SW/

you can gang them to have a few in a row., don't forget to get the end plates.

All great suggestions guys. I'm trying to prototype a new product and the rotary switch seemed like the most user friendly. However, they are quite expensive (.10 to .50). I think the idea to map each mode to a give voltage is a good solution. It wouldn't drain the battery to monitor the switch like that would it?

jshields:
All great suggestions guys. I'm trying to prototype a new product and the rotary switch seemed like the most user friendly. However, they are quite expensive (.10 to .50). I think the idea to map each mode to a give voltage is a good solution. It wouldn't drain the battery to monitor the switch like that would it?

is this for a battery operated unit ?
the button select, multiple buttons, can be near zero power consumption.

Yes, Dave. It is a battery operated unit.