Pages: [1] 2   Go Down
Author Topic: Interfacing RGB LED with Rotary Switches  (Read 2511 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 354
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 23
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.




Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 354
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 618
Posts: 33959
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

http://www.arduino.cc/playground/Main/RotaryEncoders
« Last Edit: February 05, 2009, 10:46:35 am by Grumpy_Mike » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 23
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 354
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 618
Posts: 33959
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: February 05, 2009, 01:59:51 pm by Grumpy_Mike » Logged

Copenhagen / Denmark
Offline Offline
Edison Member
*
Karma: 6
Posts: 2360
Do it !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 354
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 354
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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?
Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 354
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

bump.

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

Montreal
Offline Offline
Full Member
***
Karma: 0
Posts: 185
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There is also rotary encoder as bourn switch
http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&name=EM14R0D-R20-R016S-ND
Logged

Patgadget
Montreal

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 618
Posts: 33959
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

Atascadero, CA
Offline Offline
Sr. Member
****
Karma: 2
Posts: 468
Arduino addict
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.  smiley-wink

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.   smiley-grin



Cheers!
Logged

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

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 354
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1] 2   Go Up
Jump to: