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.

4-position switch through 1 wire - decode - to 4 wires

Status
Not open for further replies.

misiacik7

New Member
Hi there,

need help with decoding 1-wire output from switch (each position another resistance)

Thanks a lot
 
Last edited:
Can you see how it would work if you put a 500Ω resistor from the MCU input to ground? Try working out the voltages when the different switches are closed.

Mike.
 
I will rather modify the picture, cause, there is no MCU.

Just 4-position switch with added resistors to each position, and the output of the witch is single wire. And I need a device with four outputs which will recognise, which position was switched. I dont want it done with MCU, cause I dont have any experience with it.
 

Attachments

  • resistor_decode-Model3.jpg
    resistor_decode-Model3.jpg
    120 KB · Views: 184
Last edited:
In that case, I'd say a quad comparator, or a quad opamp as a comparator. Each comparator has a voltage threshold, say 2V, 5V, 8V. and 10V... the inputs to the comparators are tied together, along with a resistor to ground. Using your switching resistors, you're creating a voltage divider, with the switched resistors being the upper res, and the resistor from the input to your comparators to ground being the lower.

So, if you switch to position one in your diagram, yoru switch line connects to 12V. This is above all the thresholds and so all outputs will be active. If you only want one output active at a time, you will need to use feedback to create a 'majority vote' type circuit.

I can provide a diagram if you wish, but its just a lot of resistors really :)
 
If you want a one-chip solution the LM3914 would do. Configure it for 'dot' position, and read the data sheet on how to set the range
 
Hi there,

thanks to both of you for replies.

Diagram would be much better. (I want just one output to be active at time, coresponds with the selected input)
 
Something like this??? Dont know if it is right, or not.
 

Attachments

  • resistor_decode4-Model.jpg
    resistor_decode4-Model.jpg
    87 KB · Views: 171
Last edited:
Yes! that'll work, a window comparator that outputs a high if the input voltage is within range.

I came up with a quick one using 4 comparators, a few transistors and diodes. Essentially, its a 4 level comparator - the tough part is decoding the output so instead of it being 0001, 0011, 0111 and 1111, its 0001,0010,0100,1000. Mines a bit complicated..... and I drew it in LTspice, which is great for simulation of analogue, but not so clear for basic schematics, or digital stuff.

You might be able to do it with 4 comparators, and perhaps a couple of diodes. Creating two digital lines, which go into a 2-4 decoder (like the 74HC139).

But probably the smallest and quickest solution is the LM3914:

https://www.electro-tech-online.com/custompdfs/2011/11/LM3914.pdf

Its designed for bargraphs, but can do a 'dot' bargraph, where only one output is active at a time.

My schematic is more or less, a 4-way version of this, as you can see, its just one chip, where's mine uses LOTS of components, and has its faults.
 

Attachments

  • onetofourdecoder1.png
    onetofourdecoder1.png
    20.9 KB · Views: 174
  • onetofourdecoder2.png
    onetofourdecoder2.png
    22.7 KB · Views: 168
Thanks a lot....

- I need the output voltage the same as input = +12V

So which one do you consider most suitable for my needs?

does the windows comparator output voltage is the same as input? I need two comparators for each output, right? So I need 2 quad camp, for example LM239???
 
Yep, the LM239 should work. For each channel the schematic you posted would be fine. two comparators, and four transistors - not bad!
 
Thanks a lot,

and i hope last question:

Do I ignore the RV, and instead of it the input would be mine Switch's output to IC1A negative and IC1B positive ???

the range is really set by R1/R2 and R2/R3 means what???

for example for the range app. from 480Ω to 600Ω, the R1, R2, R3 would be???
 
Yes, you can omit the RV, your input will go straight into both comparators. It will behave the same, as the inputs to each comparator are still connected together, the only difference is that instead of RV supplying a variable voltage, your switch is doing so.

I suggest you read up about comparators, and also voltage dividers.
**broken link removed**

**broken link removed**


The trouble with an all-analgue project like this is you have to decide the value of every resistor :) Of course absolute value is not critical, but the value relative to other resistors in the circuit is!

If you have say, two resistors in series, connected from 12V to GND (0V). If they are the same value, then the voltage at the connection between them will be half of the supply voltage, or 12/2 = 6V. If you use 2 10ohm resistors, then total resistance is 2 x 10 = 20ohm. V=IR, I = V/R, with 12V across 20ohms = 0.6A will flow. Thats 600mA. This current is far too high for this circuit (resistance too low) and it doesn't need hardly any current to flow as the inputs to the comparators draw nA (thats nanoamps). So 20ohms = too low. But at say 10Meg, so little current flows that noise can interfere with operation. Generally, I use 10k-100k as starting values, and calculate the other resistor values based on that.

It is your project, and up to you to do all the maths :)
 
Last edited:
Hi there...

Thanks a lot Blueteeth!!!

Still dont know how to calculate R1, R2, R3 resistors for voltage dividers.

If it would be 2 resistor on single rail, i would knew, but three.... dont know. And didnt found any calculator, or formula.

V reference 1 = ?
V reference 2 = ?

Or to create 2 separate voltage dividers (i know it would be one resistor more)
- R1, R2 with voltage divider connected to positive of IC1A
- R3, R4 with voltage divider connected to negative of IC1B

But if there is formula for how to calculate resistors for voltage divider with three resistors, it would be best.

- R1 vs (R2+R3) and (R1+R2) vs R3 and caluclate it as two single dividers?
 
Last edited:
Calculating the voltages at the points between R1 and R2, then at R2 and R3 just involves treating R1 and R2 as a single resistor - or treating R2 and R3 as a single resistor. SO say R1 = 5k, R2 = 8K, and R3 = 3k. R1 connected to GND< and R3 connected to VCC.

Total resistance = 5+8+3 = 15K. The voltage between R1 and R2 = VCC* (R1/(R1+R2+R3)). The voltage between R2 and R3 = VCC*(R1+R2)/(R1+R2+R3).

As you're usnig this for a 'window', it would be best to pick a specific voltage, or rather a fraction of your power supply voltage (12v) and then set your window above and below this. Example, 4V. The window is centred at 4V, but you want between 3V and 5V for a bit of space. So VCC = 12V. V1 - 3V, V2 = 5V. Now V1 is 3V, which is 25% of 12V (VCC) so you know that:

V1 = VCC (R1/(R1+R2+R3). -> 3 = 12 * (R1/(R1+R2+R3). Treat R2 + R3 as Rx. 3= 12*(R1/ R1+Rx). 1/4 = R1/(R1+Rx).

R1 = (R1+Rx)/4. - > 4*R1 = R1+ Rx. SO Rx = 3*R1. So, R2 + R3 must be 3 times the value of R1.

It all looks complicated, but its not really - you do'nt have to be too accurate, since you're only dealing with 4 voltage levels.
 
An easy way of creating references is to use a string of resistors of the same value. Example: 10k. If you have 5 resistors of 10K, then the total is 50K, with VCC across it. The voltage across the first resistor os 10k/50k = 1/5 = 20% of VCC. Next? 20k/50k = 2/5 = 40% of VCC, then 60% of VCC, then 80% etc... So this way you can create evenly spaced voltage references :)

As you want 4 outputs, and you have 12V supply, your windows should be centred at roughly, 12/(4+1) = 12/5. S0, 2.4V, 4.8V, 7.2V and 9.6V.
 
Something fishy here, I think.

When you use 4 resistors as in the OP's circuit, the current changes.

When you use a voltage divider, which would entail another resistor, you can determine the position by measuring the divided voltage just as Blueteeth's circuit does.

The OP didn't draw a complete circuit, for there is no load. If the load is variable, then we have a problem.

What's the application?
 
Last edited:
I had assumed (probably wrongly) that it was a current based thing, meaning, at the 'reciever' end, the input would have a resistor to ground, effectively creating a voltage divider between the resistor on the switch, and the resistor in the reciever. Granted, a bit of weird way of doing it, unless line noise is a problem (how long is this transmission line?).

Really, its a basic problem, 4-way switch, two wires (you NEED a return path) and a box with 4 outputs. Simple enough with discrete voltage levels and a few comparators, maybe some basic logic to decode.

I get the impression the OP really is a beginner, which means any info we provide he/she would have to research - unless myself or someone spoonfeeds a nice schematic and the OP jst builds - which is fair enough, the problem still gets solved.
 
I knew it can be somehow calculated... made and formula

V1 and V2 is known
you set just R2

Voltage between R1 and R2 = V1 and voltage between R2 and R3 = V2

R1 = (R2+R3)*(V/V1-1)
R3 = R2*( (V/V1) / (V/V2-V/V1) )

took me some minutes, but made it :) i mean the formula....

transmission line is few centimeters at one application and 3meters at the other one...
I checked the switch and it switch to the ground via resistor... I connected another fixed resistor (500ohm) from positive to the switch output and it gives me 0,14V, 2,9V, 6,23V and 9,39V so there will be 4 ranges

0,01V - 1,0V (calculated values R1=1 111 111Ω R2=100 000Ω R3=1 010Ω)
1,9V - 3,9V (calculated values R1=8 100Ω R2=2 000Ω R3=1 900Ω)
5,15V - 7,15V (calculated values R1=4 850Ω R2=2 100Ω R3=5 150Ω)
8,40V - 10,40V (calculated values R1=1 600Ω R2=2 100Ω R3=8 400Ω)

Just to put to E24 values and try it, hope tomorrow have enough time to try it :) Thanks a lot for helping me out :)
 
I tried yesterday following setup:
- R1=8K2, R2=2K, R3=2K (range 1,97V - 3,93V) (input1 - 2)
- R1=1K6, R2=2K, R3=2K4 (range 8,34V - 10,37V) (input3 - 4)

Output voltage of the switch:
1. position - 0,14V
2. position - 2,91V
3. position - 6,23V
4. position - 9,39V
Not Switched - 12V

On the OUT1+2 I putted transistor (as switch) via resistor 1K and try to connect LED. Dont know what is RL good for on the shema of the window voltage detector, so I tried to connect it with 1K resistor from positive to output 1+2. LED1 was glowing, some current passed thru. I switched the RL to higher value 1M and it worked... LED completly off when not switched, and on as I switch to 2.position.

Now I tried to connect the INPUT3+4. Tried it, and worked. As I switched 4. position, the LED2 was on. (same value for the RL = 1M). But, as I tried the 2. position (LED1 light up - normaly) the otherLED (LED2) lightly blink. Just for some miliseconds.

What can be wrong?
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top