Connecting 2 to 9 switches on one ADC pin
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Connecting 2 to 9 switches on one ADC pin
As we know, Flowcode has made programming microcontrollers so much easier than with C code for example.
This tip is keeping with the theme of making things easier.
To do that, I have created a spreadsheet that will allow you to easily connect from 2 to 9 single pole switches, e.g tactile to a single analogue pin.
The spreadsheet should work with any free or paid for software.
For those who have not got such software here is a screen shot: All the if ADC values are dynamically changed, depending on resistor selection.
My hardware consists of 12F1840 + I2C 4x20 LCD.
Of course any microcontroller and peripherals an be used.
The attached Flowchart is an example only.
Circuit: Note: Can only operate one switch at a time.
New ADC values are required for multiple switch detection.
This tip is keeping with the theme of making things easier.
To do that, I have created a spreadsheet that will allow you to easily connect from 2 to 9 single pole switches, e.g tactile to a single analogue pin.
The spreadsheet should work with any free or paid for software.
For those who have not got such software here is a screen shot: All the if ADC values are dynamically changed, depending on resistor selection.
My hardware consists of 12F1840 + I2C 4x20 LCD.
Of course any microcontroller and peripherals an be used.
The attached Flowchart is an example only.
Circuit: Note: Can only operate one switch at a time.
New ADC values are required for multiple switch detection.
- Attachments
-
- 12F1840 9 Switches & LCD v2.fcfx
- (16.48 KiB) Downloaded 585 times
-
- Resistance-calculator-Up-to-9-Switches-V2.xls
- (14 KiB) Downloaded 575 times
Martin
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Connecting 2 to 9 switches on one ADC pin
Thanks Martin.
The other alternative is to use all the same resistor values e.g 1K2 in series, connected between +VDD & GND.
A high value resistor e.g 820K is connected between ADC pin and GND.
The ADC pin can then be connected to each series resistor junction via momentarily switches.
The disadvantage being very susceptible to electrical noise.
Therefore would strongly recommend using a decoupling capacitor across the high value resistor.
Agreed.
The other alternative is to use all the same resistor values e.g 1K2 in series, connected between +VDD & GND.
A high value resistor e.g 820K is connected between ADC pin and GND.
The ADC pin can then be connected to each series resistor junction via momentarily switches.
The disadvantage being very susceptible to electrical noise.
Therefore would strongly recommend using a decoupling capacitor across the high value resistor.
Martin
-
- Valued Contributor
- Posts: 1208
- Joined: Wed May 31, 2017 11:57 am
- Has thanked: 70 times
- Been thanked: 440 times
Re: Connecting 2 to 9 switches on one ADC pin
Hi Martin,
One query - there is some overlap in the checked values (<208 sw 1 >200 sw 2 for example)... This shouldn't pose a problem - button registered should map to first conditional statement...
Unless you just use consecutive if's (and nested is going to get a bit messy for 9 switches) in which case two switches could register?
Martin
One query - there is some overlap in the checked values (<208 sw 1 >200 sw 2 for example)... This shouldn't pose a problem - button registered should map to first conditional statement...
Unless you just use consecutive if's (and nested is going to get a bit messy for 9 switches) in which case two switches could register?
Martin
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Connecting 2 to 9 switches on one ADC pin
Hi Martin,
Thank you for your query.
You are spot on!
I just did a calculation so the ADC was in the middle of two ranges which indeed could cause issues if not nested.
I have change the excel sheet so the start in the next value is 1 greater then the end of the previous value.
It does shift from the centre point but should cause less of an issue in the long run.
Updated both files
Thank you for your query.
You are spot on!
I just did a calculation so the ADC was in the middle of two ranges which indeed could cause issues if not nested.
I have change the excel sheet so the start in the next value is 1 greater then the end of the previous value.
It does shift from the centre point but should cause less of an issue in the long run.
Updated both files
Martin
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Connecting 2 to 9 switches on one ADC pin
Brilliant and easy to follow, thanks for sharing
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Connecting 2 to 9 switches on one ADC pin
Thanks Ben,
You're welcome.
Saves changing microcontroller if not got enough pins.
You're welcome.
Saves changing microcontroller if not got enough pins.
Martin
-
- Posts: 1333
- Joined: Tue Oct 06, 2009 9:39 am
- Has thanked: 1135 times
- Been thanked: 299 times
Re: Connecting 2 to 9 switches on one ADC pin
Wow Martin, perfect and s always useful from you.
Br jorgen
NB. Why is it not possible to give thump up anymore?
Br jorgen
NB. Why is it not possible to give thump up anymore?
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Connecting 2 to 9 switches on one ADC pin
Hi jorgen,
Thank you, its appreciated.
DavidA mentioned it here.
Thank you, its appreciated.
Because of the the new server & forums update.
DavidA mentioned it here.
Martin
-
- Posts: 1333
- Joined: Tue Oct 06, 2009 9:39 am
- Has thanked: 1135 times
- Been thanked: 299 times
Re: Connecting 2 to 9 switches on one ADC pin
Thank´s Martin. I have not seen it. You get "thump up".
Br Jorgen
Br Jorgen
- AbhijitR
- Posts: 300
- Joined: Fri Nov 07, 2014 12:48 pm
- Location: Pune, India
- Has thanked: 283 times
- Been thanked: 80 times
Re: Connecting 2 to 9 switches on one ADC pin
Hello!
I do agree with Jorgen, rather it was really very easy to register the appreciation, is it not possible to add that button once again.
By the way Martin let me take this opportunity, a big Thumbs Up, cheers....
Abhi
I do agree with Jorgen, rather it was really very easy to register the appreciation, is it not possible to add that button once again.
By the way Martin let me take this opportunity, a big Thumbs Up, cheers....
Abhi
Re: Connecting 2 to 9 switches on one ADC pin
Hi Martin,
I have read this topic because it is interesting for me.
I have 8 switches in a remote control box and a cable with 3 wires. 5V, GND and a “signal” wire. This cable is some 7 meters long. The cable is in the open air. (outside) The cable has 3 x 1.5mm wires.
Wil this solution work with this cable length? I have the feeling that this solution is only working for short cables because of the voltage per switch.
Or can I better go for a digital solution such as a DS2408 from MAXIM ?
Thanks,
Frank
I have read this topic because it is interesting for me.
I have 8 switches in a remote control box and a cable with 3 wires. 5V, GND and a “signal” wire. This cable is some 7 meters long. The cable is in the open air. (outside) The cable has 3 x 1.5mm wires.
Wil this solution work with this cable length? I have the feeling that this solution is only working for short cables because of the voltage per switch.
Or can I better go for a digital solution such as a DS2408 from MAXIM ?
Thanks,
Frank
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Connecting 2 to 9 switches on one ADC pin
Hi Frank,
Sorry not tested the resistor version over any lengths of wires.
The idea of the resistors was to make the coding as simple as possible.
The DS2408 sounds like it could work but one wire timing is critical, so how well I don't know.
The other alternative is UART.
That would be easier to implement, but will work over shorter distances of up to 50ft.
If it was my project I would go with UART if I only had three wires, one being for data.
Sorry not tested the resistor version over any lengths of wires.
The idea of the resistors was to make the coding as simple as possible.
The DS2408 sounds like it could work but one wire timing is critical, so how well I don't know.
The other alternative is UART.
That would be easier to implement, but will work over shorter distances of up to 50ft.
If it was my project I would go with UART if I only had three wires, one being for data.
Martin