Go Down

Topic: Interfacing RGB LED with Rotary Switches (Read 4507 times) previous topic - next topic


I need to drive a RGB LED to 6 different colours. I was thinking of having a rotary switch as a my selector through an Anlog Input pin. However, I've never worked with rotary switches before.

I was browsing through Digikey and saw that they have various amounts of turns - Single, 3, 5 and 10. However, they only have Single for Through Hole components (which would be way easier for my prototyping needs).

Does 'Single' mean it only turns once? Basicly an Off-On switch?
If this is the case, does anybody know where I can get a 6 turn rotary switch?

I'm not tied down to using a Rotary switch. Anybody have any other suggestions? I don't want to incorporate normal momentary push buttons, cause I will be using them at different places in the project and want different switched to distinguish between the different user interactions. I also looked at joysticks but can't seem to find a through hole component that is fairly cheap.

Any ideas?


I think you are getting confused. Rotary switches are digital devices and don't need to be connected to an analogue input. They are often Binary Coded Decimal (BCD for short) switches which have ten selectable positions. The outputs from the switch would go to four digital inputs and would be set as follows :

Switch poition 0 = 0 0 0 0
Switch poition 1 = 0 0 0 1
Switch poition 2 = 0 0 1 0
Switch poition 3 = 0 0 1 1
Switch poition 9 = 1 0 0 1

For your application if you can't find 6-way switches (and you do mean 6-way, not 6-turn don't you?) just ignore any input higher than 6, or have some way of telling the user that the input is invalid.


k i messed up with what I thought was a rotary switch. I was looking at rotary potentiometers. A switch takes up more inputs than i want to give up, and i don't want to use any more I/O expansion chips.

Is there a way to get a linear rotary potentiometer with just 6 set ranges? I know I can handle ranges in my code (1024/6) but was hoping for a better hardware solution.

Also if I have to go the software route, is it possible to get potentiometers that reset at the end? I've only dealt with potentiometers that have a hard start and stop. I want something like a radio control knob for selecting FM ranges. Once you reach a certain frequency and keep turning, it resets back to the lower frequency, that way you can keep scrolling in one direction if you want.


Feb 05, 2009, 04:43 pm Last Edit: Feb 05, 2009, 04:46 pm by Grumpy_Mike Reason: 1
If you get a pot with continuous rotation, that will wrap round at the end. But most pots are not like that, a single turn is normally only 270 degrees.

A rotary encoder is continuous it gives you pulses you can count, if you just want to count up then you need only use one pin. These type are cheap.



You could use one of these, but it won't be cheap....


K we're making progress we've gone from switches to potentiometers to encoders.

It seems like the rotary encoders are the way to go. THis one is only 94 cents: http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&name=P12331-ND

However, I need to attach 4 to a project so now I got a couple more questions:

How important are the use of interupts when using encoders? My project is already going to be encorporating 3 MAX7221 chips, so there will already be a lot going on. I really will only be updating the states of the LEDs when recieving input however.

Is there a chip I can use to expand interupts? I don't know how I would get the Arduino to handle 4 interupts otherwise

If interrupts aren't important, can I use 4 encoders with a Parallel In-Serial Out chip, or will that severely reduce performace?


Feb 05, 2009, 07:58 pm Last Edit: Feb 05, 2009, 07:59 pm by Grumpy_Mike Reason: 1
As each encoder requires two signal lines then how about using an MCP23016. It is an I2C device. This gives up to 16 I/O lines, with a line out that changes when ever any one input changes. You can wire that up to the interrupt input and have one interrupt line service them all.

They are important as you have to see what the other signal is doing when pulses occur.


Why not use a single 6 position rotary switch with 6 different resistors hooked up to one single analog input.

This would easily give you 6 different values from the analogRead on the pin, if the resistor values are spaced reasonably well.


this is pretty cool, I completely forgot I/O expanders had interrupt pins in them. Have you used the chip before? I've never worked with I2C communication. Is it as easy as using SPI or software serial?

This page seems to do what I want but without the interrupt pin: http://www.neufeld.newton.ks.us/electronics/?p=241

From reading the datasheet it seems that the input pin goes high when there is an input change and goes low when I read the port. If I got this right, it shouldn't be too hard to interface... I hope anyway


Why not use a single 6 position rotary switch with 6 different resistors hooked up to one single analog input.

This would easily give you 6 different values from the analogRead on the pin, if the resistor values are spaced reasonably well.

hmm.. could you explain further? are you talking about a 6 pin voltage divider?



Is a 6 pin Voltage Divider the answer to MikMo's suggestion?




Is a 6 pin Voltage Divider the answer to MikMo's suggestion?

This is, in effect, what he is suggesting making, but no such device exists commercially nor is the name "6 pin Voltage Divider" known outside these pages.


The "6 pin voltage divider" is probably the easiest and least complicated approach.  The name's a little strange, but I can't think of a better one.  ;)

Get a single-turn, 6-position rotary switch and 5 equal-value resistors.  (a switch that can rotate all the way around without stopping would be best)  The 1st and 6th position will be your highest and lowest values.  The positions between will be evenly spaced along the analog range.  Apply +5v to position 1 and Ground to position 6, then solder the 5 resistors between successive positions. This will give you the voltage divider.  The common pin on the switch will go to the Arduino analog input.

It's large enough steps that you shouldn't have any troubles with noise, but try to keep the leads between the switch and Arduino short.  Also, you will need to do some testing/calibrations in your code to find the right range of values for each of the 6 positions.  If you use 1% or better resistors, it will be easier to calibrate.

Here's a high-quality schematic I made in MS Paint to clarify.   :D

What about elevensies? Luncheon? Afternoon tea? Dinner? Supper?


Just did the calculations for all the resistors for my rotary switches. I thought it would be kind of a 6 pin voltage divider, just wanted to confirm that this is what was meant.

I am still a little thrown off by the cost of a rotary switch. The cheapest one I found that fits my need is going to cost me 10 bux each. PLus the wiring aint simple to test on a bread board, so I am probably going to need to make a few breakout boards for testing, especially cause I am going to have high school kids work with them

Anyway, I am gonna go down to the electronic surplus store tomorrow and take a look to see what they offer in terms of encoders and switches. If they have some deals going on, I might be able to grab a few switches on the cheap.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131