Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Multiplex switches

Status
Not open for further replies.

AtomSoft

Well-Known Member
Ok i have seen a ton of ASM to make keypads for 4x4 and 3x4. My question is simpler. How can i use 1 pin to get a possible of only 3 results? Like 1x3.

I want it simple so if i need 3 switches why not use 3 diodes and 3 pull-ups?. I will be using 3 push buttons.

I wanted to know 2 things really and i know im a pain in the as* but heh i get confused learning to fast. (btw everything i see correct i save it as a PDF so i can keep a copy and not bother more lol)

Ok to the questions:
1. How would i wire this up ? (using a 18F1320 or similar)
2. How would i code it.

I know it feels like im asking for the complete info and not trying to learn but thats not true. I dont even own a programmer or chip. I did order a Junebug which is on its way. So i just want to be ready to start programming and creating some cool stuff.

Every post i read study and ask if i dont understand only to ensure that i will eventually :D :D
 
For some reason I can not upload an attachment. Connection closed by remote server

String 4 1K resistors in series. Attach one terminal of each switch to a junction common to 2 resistors. Attach one end resistor to gnd and the other to +5. Tie all the unused switch terminals together and then to an analog input pin. Use a weak pullup on the pin say 20K.

When all the switches are open you read 5V. When one closes the voltage is fixed by the resistor network. Do an ADC to figure out which switch is closed.

EDIT:
I have provided a solution to use multiple keys on a single input. Another would be to use a keyboard encoder and a serial input stream.
Better to use a PIC with enough pins so you can stay with digital inputs, use a tradition matrix where you scan row and column.
 
Last edited:
It would go a long way, both towards gaining knowledge and getting help, if you at least made a significant effort towards some preliminary design work. I, for one, am certainly not going to design a circuit for you, but if you make a positive effort, I'll be more than happy to guide you in the right direction. I can't speak for anyone else here, but that's my position.
 
**broken link removed**

There we go just made some time to do this but 2 issues didnt find the right PIC18F1320(1220) is in same fam so i assume same pinout. Also Could not find normal switches so used some wierd ones closest to normal :D

How would i program this to identify different presses? Like what exactly do i compare? and to what?

just seen your comment 3v0 will do....
 
Last edited:
Not quite. You have VDD shorted to ground so I take it one should ignore the bad label. Each resistor that is switched in forms half of a voltage divider. That should work. But the generated voltages could be further apart.

This is what I was thinking of. The resistors act as a voltage divider with several taps. The voltages
will be aprox 5V all open, (2/3)5V, (1/3)5V, and 0V. Ohms law ... Not too sure what the best value would be for the 100K all open pullup. Big is better so long as it is not so weak that it does not work.
The resistors do not have to be 1K, just as long as they are the same size the voltages will work out the same. The higher the value the less current it will draw.

You need to read up on ADC conversion. Good time to get cozy with the data sheet and the header/device/include file.
 

Attachments

  • keyboard2.png
    keyboard2.png
    3.5 KB · Views: 335
Last edited:
Not bad, except as noted you have VDD connected to ground--you don't want to do that. What you have for your keys is a set of switched voltage dividers. Now, look at the values. Use Ohm's law and plug in your VDD voltage to determine what voltage the input at AN0 sees for each keypress. Are those good values?
 
Well, close, but your resistors are in parallel.
What 3v0 means is that you want a voltage divider, where each switch will give a different output voltage, which you can then read with an analog pin.
Yours will work, but you won't have much variation in voltage between the switches. It would work better if you used 1k, 1k5, 2k, and 2k5 instead of 100, 150....

Three of us replying at the same time.

Yes, I missed Vdd connected to ground! :D
 
oh ok i thought VDD was ground and Vss was V+
VSS 5 5, 6 3, 5 P — Ground reference for logic and I/O pins.

found that ok cool now i see it

Sorry i guess i really have to double check things when actually making it.
**broken link removed**
 
Last edited:
What is the purpose of the 20k series resistor in your second schematic? Remember that the four 1k resistors in series already form a voltage divider network. Think it through. Do you need that 20 k resistor?
 
3v0 said:
String 4 1K resistors in series. Attach one terminal of each switch to a junction common to 2 resistors. Attach one end resistor to gnd and the other to +5. Tie all the unused switch terminals together and then to an analog input pin. Use a weak pullup on the pin say 20K.

Because 3v0 said to
 
oh oh so it must return a value so we close the circuit no matter what and just care if the voltage is one of mines.
Like

**broken link removed**

found the switches:
**broken link removed**
 
Last edited:
AtomSoft said:
oh oh so it must return a value so we close the circuit no matter what and just care if the voltage is one of mines.
Sort of. A pullup resistor is used to maintain a small, stable voltage on an input pin. If you left it off, your circuit MIGHT work correctly, but the pin's voltage may fluctuate, causing unwanted false inputs.
 
I²R said:
Sort of. A pullup resistor is used to maintain a small, stable voltage on an input pin. If you left it off, your circuit MIGHT work correctly, but the pin's voltage may fluctuate, causing unwanted false inputs.

I am not an EE. But I would have said steady voltage and small current?
 
ok cool. So there is no definite way to calculate the divided voltages right? Like i would have to place resistors and manually check each one to determine drop ?
All i know in ohms law is how to get 1 value from 2 others. I don't know how to subtract like 100k ohms from 5v to determine the drop on the resistor.

Hey we went from 3 to 4 switches

You have the basic idea.
yeah the concept is in the head but the head doesnt know how to draw lol

EDIT: Found this
 
Last edited:
It's simple. Consider a 20 kOhm resistor in series with a 5 kOhm resistor, with 10 V applied across them. You want to determine the voltage at the point between them. First thing you do is calculate the current through the resistors:

I = V / R

I = 10 / (15 k + 5 k)

I = .5 mA

Now that you know that, you can calculate the voltage drop across each resistor:

V = I x R

V1 = .5 mA x 15 k

V1 = 7.5 V

V2 = .5 mA x 5 k

V2 = 2.5 V

Reality check: the two voltages should sum to the total supply voltage. 7.5 + 2.5 = 10. If you have more than two resistors, you can just extend this process. Now, work out your voltage drops.
 
3v0 said:
I am not an EE. But I would have said steady voltage and small current?
A negligible current. The inputs are high impedance and measure voltage, not current.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top