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.

Keypad Implementation using A/D on a PIC18Fxxxx

Status
Not open for further replies.

rrb011270

New Member
Mabuhay,

Anyone from the community who have done keypad implementation on a PIC using Analog-to-digital conversion?

Any info, materials and/or a sample snippet ...

Thank u.
 

Nigel Goodwin

Super Moderator
Most Helpful Member
I've never actually done it, but I've seen it done a lot over the years.

The technique is very simple, you feed +5V through a resistor to the A2D input, so it now reads 5V - no button pressed. You then have a series chain of resistors from this point, with switches down to ground. So when you press a switch it creates a potential divider with the upper feed resistor. By carefully selecting the resistor values you can find which key was pressed by measuring the voltage.

It's usual to have one key which shorts directly to ground, so that key would read 0V, no key 5V, and all others somewhere inbetween.

How many buttons are you wanting?.
 

rrb011270

New Member
Nigel Goodwin said:
I've never actually done it, but I've seen it done a lot over the years.

The technique is very simple, you feed +5V through a resistor to the A2D input, so it now reads 5V - no button pressed. You then have a series chain of resistors from this point, with switches down to ground. So when you press a switch it creates a potential divider with the upper feed resistor. By carefully selecting the resistor values you can find which key was pressed by measuring the voltage.

It's usual to have one key which shorts directly to ground, so that key would read 0V, no key 5V, and all others somewhere inbetween.

How many buttons are you wanting?.

I am planning to have a 3x4 keypad on this project? can you help me on this? any information will do?

Thanx
 

Nigel Goodwin

Super Moderator
Most Helpful Member
rrb011270 said:
I am planning to have a 3x4 keypad on this project? can you help me on this? any information will do?

Keypads are usually multiplexed, I don't think you can read them using an A2D. For a 3x4 keypad you need 7 I/O pins, and scan the keypad. There are details in my tutorials at https://www.winpicprog.co.uk, these use a 4x4 keypad, but there are comments on how to use them for 3x4.
 

panic mode

Well-Known Member
would this work...?
 

Attachments

  • keypad.jpg
    keypad.jpg
    17 KB · Views: 875

Exo

Active Member
rrb011270 said:
Exo said:
Where are you going to connect the pic's input to ?

I am planning to connect my keypad output to AN0 ---> an analog input for the PIC.

I guess this URL --> https://www.reed-electronics.com/ednmag/article/CA56657?text=vitor+amorim&stt=000 will give an insight that it is possible to design a keypad matrix that only use one analog port to the PIC microcontroller.

Thanx for your reply and input.

My question was to panic mode...

@rrb011270

Scanning keys using resistors an an ADC is common practive (philips even does so in some televisions) but, as you can see on the url you gave yourself, the resistors have to be placed between the switches. These 4 x 4 keypads you want to use are internally already pre-wired (in a matrix shape) wich prevents you from connecting those resistors. If you got a keypad wich allows you to connect every switch independently then there should be no problem.
 

panic mode

Well-Known Member
Hi exo,

You can read the voltage of the R8 for example.

Problem with the previous circuit is that multiple keys pressed at
once would not be detected. For example upper left key (A-G) would
short most of the network and any other key would not be detected.
Also circuit would continuously draw current.
After some thinking I came up with another circuit which should be better.
 

Attachments

  • keypad2.jpg
    keypad2.jpg
    17.7 KB · Views: 828

panic mode

Well-Known Member
Yep, that should work.
I'd recommend ratio for the R1-R7 values 1:2:3:4:4:8:12
For example
R1=100
R2=200
R3=300
R4=400
R5=400
R6=800
R7=1200

Resistor R8 is load and for good results it should be much bigger than
the other resistors if you want really linear system (the best would be to use constand current instead of fixed 5V source). I calculated things over using 10k for R8 and that looked very good. The output signal in this case
is only few mV and needs to be amplified of course.
Using lower value does work as well, it's just that graph is slightly bent. Values similar to R7 should be acceptable. Lower R8 also provides for larger output change. Anyway, it's an idea... use it on your own risk

:lol: :lol: :lol:
 

rrb011270

New Member
Exo said:
Scanning keys using resistors an an ADC is common practive (philips even does so in some televisions) but, as you can see on the url you gave yourself, the resistors have to be placed between the switches. These 4 x 4 keypads you want to use are internally already pre-wired (in a matrix shape) wich prevents you from connecting those resistors. If you got a keypad wich allows you to connect every switch independently then there should be no problem.

Thanx for provising an info..

BTW, I use a discrete switch here a surface mount type and a surface mount type resistor network for my switches...

With this I can select higher values of resistor in -order to have minimum current consumption. The only problem with higher resistor values is the equivalent resistance which exceeds the required impedance for the analog source... a 2.5K for PIC18Fxxxx sereis and most of the PIC16Fxxx series have 10K.

The solution I use in order to meet this impedance requirement esp. I am using the PIC18F1320 I have a voltage follower and a buffer rail-to-rail OPAMP with a teraohms input and a low impedance output.

With this configuration I can utilize the extra port of my PIC for access control and monitoring.

BTW, I got my circuits working now... esp. ADC part...

Thanx
 

rrb011270

New Member
Re: 3x4 keypad thinga magig?

egg0900 said:
Did it work?

The keypad resistor network really great and I have my code working with proper keypad mapping. The PIC code can detect what appropriate keys you press..
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top