Maker Pro
Maker Pro

Rotary switch - detect which connector??

wingnut

Aug 9, 2012
255
Joined
Aug 9, 2012
Messages
255
Hi all

I want to attach 6 sensors to a 6 connector rotary switch.
Each sensor will go to the same ADC port of a PIC16f690.
I want to know which sensor is feeding input to the ADC pin.
Can anyone think of a way of detecting which connector is currently selected - best case scenario, using only one other pin of the PIC.
 

NorthGuy

Mar 24, 2016
53
Joined
Mar 24, 2016
Messages
53
I don't think it's possible.

You can use PIC with more pins, connect each sensor to its own pin and remove the switch. If you seek to use less space, bigger PIC will take less space than (smaller PIC + switch). Similarly, if you add extra components, it'll still be more space than few extra pins on the PIC. Replacing your 20-pin PIC with 28-pin enchanced midrange should do the trick.
 

Amar Dhore

Dec 2, 2015
129
Joined
Dec 2, 2015
Messages
129
I am not sure what kind of sensors are you using but let me throw an Idea. I would have 6 different voltage bias for 6 sensor, this way when I read the value I can differentiate between 6 sensors. Make sense?
 

dorke

Jun 20, 2015
2,342
Joined
Jun 20, 2015
Messages
2,342
Hi all

I want to attach 6 sensors to a 6 connector rotary switch.
Each sensor will go to the same ADC port of a PIC16f690.
I want to know which sensor is feeding input to the ADC pin.
Can anyone think of a way of detecting which connector is currently selected - best case scenario, using only one other pin of the PIC.

What sensors are you using?
Why use a mechanical selector?
 

wingnut

Aug 9, 2012
255
Joined
Aug 9, 2012
Messages
255
pic16f690.jpg

Thank you so much for your replies to date.

I bought a dozen PIC16F690's because I like their size so I don't wish to change the PIC. I use my circular saw to cut breadboards into 3 sections and this PIC with 20 pins fits nicely and has ADC.

All 8 C register pins are used to drive the 7 segment display. Pin 17 or RA2 is used to detect ADC. Whatever this analogue value is, is printed out on the 7 segment display which flashes out the value with a pause between numbers.

At various times I have measured battery voltage, temperature, IR brightness, light brightness (photoresistor CdS), soil conductivity (electrolysis), variable resistance. Trouble is that each time one does a project it takes time to calibrate each sensor to say, get the right temperature or voltage. Just as I now have a standardised PIC setup, I was thinking of a module with various sensors which have all been pre-calibrated. This way I just do it once and for all. I thought it would be nice to have this all set up, then one just clicks the rotary switch to whatever you want to measure (like a multimeter) and it spits out temp, or voltage or lux, or IR brightness etc. Currently I am using a thermistor, which can be seen on the right of the photo.

The A and B registers give me 6 potential analogue inputs, but I would still then have to choose which one to display. I suppose I could attach a press switch which toggles through each sensor in turn, but that is 7 more connectors to 7 more pins which makes it more "busy". Ideally I would like just 2 wires to the sensor board - but then I would have liked to have been born Brad Pitt, but that's not possible either.
 
Last edited:

NorthGuy

Mar 24, 2016
53
Joined
Mar 24, 2016
Messages
53
I use my circular saw to cut breadboards into 3 sections.

http://www.ebay.com/itm/2pcs-Mini-S...Contacts-Available-Test-Develop-/221890976768

I thought it would be nice to have this all set up, then one just clicks the rotary switch to whatever you want to measure (like a multimeter) and it spits out temp, or voltage or lux, or IR brightness etc.

You can use a multiplexor which will move through sensors when you press a PCB-mounted push-button. This way PIC will know which sensor is used because it switches the multiplexor. But you'll need one pin for the button and some pins for the multiplexor.

Alternatively, you can mount sensors on small PCBs. You can order really nice small PCBs at OshPark very cheap:

http://docs.oshpark.com/services/

They charge $5 for 1 sq.in. of board and they give you 3 boards with free shipping. So, for $2.50 you can get three 1/2 sq.in, boards for your sensors. You solder pins on them and then you can just stick them into breadboard. Taking them it in or out is not much harder than turning the rotary switch.
 

wingnut

Aug 9, 2012
255
Joined
Aug 9, 2012
Messages
255
http://www.ebay.com/itm/2pcs-Mini-S...Contacts-Available-Test-Develop-/221890976768



You can use a multiplexor which will move through sensors when you press a PCB-mounted push-button. This way PIC will know which sensor is used because it switches the multiplexor. But you'll need one pin for the button and some pins for the multiplexor.

Alternatively, you can mount sensors on small PCBs. You can order really nice small PCBs at OshPark very cheap:

http://docs.oshpark.com/services/

They charge $5 for 1 sq.in. of board and they give you 3 boards with free shipping. So, for $2.50 you can get three 1/2 sq.in, boards for your sensors. You solder pins on them and then you can just stick them into breadboard. Taking them it in or out is not much harder than turning the rotary switch.

Thanks. I will get some small PCBs and mount the sensors on them.
What I will probably do is wire each sensor to its own ADC pin, and have a switch toggle between the sensors.
It will mean a few more wires between breadboard and PCB, but in the end will probably be simplest.
 

wingnut

Aug 9, 2012
255
Joined
Aug 9, 2012
Messages
255
I would like to ask for some advice regarding calibrating sensors.

My analog port is working and when I say, attach a thermistor, it gives me various raw data outputs.
What I do, since I don't have a thermometer, is immerse the sensor (in waterproof protection) in ice water (0 degrees C), in room temp water (20 degrees) and in a kettle of boiling water (100 degrees). This gives me three sets of analog output data.

Next I look for a regression analysis website such as ...
http://www.mathportal.org/calculato...tor/correlation-and-regression-calculator.php or ...
http://ncalculators.com/statistics/linear-regression-calculator.htm

These sites kick out an equation which supposedly allows one to calculate any temperature reading from any analog output of the thermistor. This works for voltage readings etc.

Trouble is that it just lacks perfect accuracy. Sometimes it comes close, but no cigar.

Any suggestions as to how to tighten the accuracy?

For instance on the websites above I input made up raw data values of x = 1, 2, 3 and y = 1, 4, 9 (i.e. the square of the x values) and the equations spat out are y = -3.3333 + 4 x
To me, y = x^2
When I try this for x = 4 it gives value 12.67 which is not 16.

Anyone know how I can find better regression analysis or any other suggestions?
Thanks in advance
 

NorthGuy

Mar 24, 2016
53
Joined
Mar 24, 2016
Messages
53
Linear regression assumes linear relationship between the variables - graph of one variable vs another is a straight line. That's why they call it linear.

If the relationship is not linear, as may be the case with thermistors, you need to read the sensor datasheet. It'll have some sort of table or formula that you can use to linearize it. They may also recommend calibration procedures.
 

wingnut

Aug 9, 2012
255
Joined
Aug 9, 2012
Messages
255
Linear regression assumes linear relationship between the variables - graph of one variable vs another is a straight line. That's why they call it linear.

If the relationship is not linear, as may be the case with thermistors, you need to read the sensor datasheet. It'll have some sort of table or formula that you can use to linearize it. They may also recommend calibration procedures.
I guess the "linear" in linear regression did not ring a bell with me :(. I don't know the type of thermistor, so no data sheet.

I used the PIC ADC to read the ADC values at 2, 18, 49, 95 degrees C and got 207, 425, 721, 934 reading respectively. This forms a nice gentle curve.

Then I went to...
http://www.had2know.com/academics/quadratic-regression-calculator.html
...with its quadratic regression calculator and got it to calculate a quadratic equation for the data, which it did giving y= 0.0001x^2 - 0.0336x + 4.2234 using analog values as x and degrees C as y.

Using this quadratic on a calculator it proved pretty accurate to within 2 degrees off most of the time for the range 0 to 95 degrees C, so the quadratic regression calculator seemed to work fine. Now to calibrate the other sensors.

Thanks again.
 
Last edited:

NorthGuy

Mar 24, 2016
53
Joined
Mar 24, 2016
Messages
53
The coefficients have bad rounding. Try 0.0001385 instead of 0.0001.
 
Top