Using SPDT on-off-on Rocker Switch

Paul__B:
So you do not need to sense both sides of the switch, only one. If it is not one, it must be the other. There is no other option!

Thanks! I put that in just for aesthetics. :slight_smile: I may put it in anyway for another purpose (was thinking of a master reset or speed switch, but I am not sure yet).

Paul__B:
The second problem is that you have no pull-down resistors to pull the “sense” line (that only one) down when it is not pulled up by the switch, so you are quite likely (very likely I suspect) for it to read HIGH even when the switch is in the other position. What you need - most simply - is a 4k7 resistor in the “R1” position, and a 47k pulldown from that input pin - PB5- to ground. The 4k7 will prevent the port input from being pulled higher than Vcc.

I did discover that in my little test. I brought all the wires out of the case to connect to my breadboard. When I put in the code to “sense” the position, I saw that either way did not set the pin and that was when I realized that it was not going to ground.

My updated circuit is like this:

Paul__B:
I am having a grand semantic leg-pull with steinie44 here, as he has (apparently?) not realised the consequence of the fact that the centre position is in fact, OFF. With no power to the circuit, if you had resistors connected to both sides of the switch, then in the centre position, both sides of the switch would literally be pulled to a logic HIGH because with no power to the logic, logic HIGH = logic LOW anyway! XD

LOL But with no power none of my code is executed anyway, but that condition did give me an idea for a “special” test mode when I apply power through a jumper. Although I did see that condition when I had the switch off while I was programming my Arduino to test my new code when I connected the USB. I do not think that will be a problem when I finally program the ATTiny85.

Thanks so much for all the help! I will post pics of my creation when I finish it! :smiley:

@Paul__B With pin 2 of the switch, +5v, in the center position, as shown, how are the inputs pulled high? There is no connection at all to pin 1 and pin 3 of the switch. Dream on, learn by doing, not dreaming.

Oh dear! You are still not getting it!

With the switch in the centre position, OFF, the inputs are necessarily at the same voltage as Vcc on the chip which is by definition, the logic “HIGH” level.

And also the LOW level, as it happens in this circumstance since Vcc = GND.

In mathematics and logic, this is referred to as a degenerate case.

With the switch in the centre position, OFF, the inputs are necessarily at the same voltage as Vcc on the chip which is by definition, the logic "HIGH" level.

NO, you don't get it! The center, pin 2, IS THE Vcc SOURCE! How do you think Vcc gets to the chip? Does it just go from the battery through thin air?

steinie44: NO, you don't get it! The center, pin 2, IS THE Vcc SOURCE!

When the switch is in the centre no power is connected to the chip so all the chip pins must be at 0v.

Would it work if wired like this?

------>|------------------------- VCC | ------>|------- I/O pin | | V+ ------/ -----VVVVV-----GND

|--------------------------------VCC

I am guessing it would be a good idea to have two diodes to maintain the some voltage on the I/O pin as VCC

...R

I am guessing it would be a good idea to have two diodes to maintain the some voltage on the I/O pin as VCC

Don't see why not. Only need one input.

steinie44:
How do you think Vcc gets to the chip? Does it just go from the battery through thin air?

If the switch is in the centre position that would indeed be the only way.

Robin “gets” it. :smiley:

Robin2:
Would it work if wired like this?
I am guessing it would be a good idea to have two diodes to maintain the some voltage on the I/O pin as VCC

Pretty good, though the I/O pin would still have slightly higher voltage on it as the diode supplying current to Vcc would have a greater voltage drop. I doubt it would be a problem, but that is essentially why I suggested the 4k7 and 47k resistors instead which drop 0.5V and (in conjunction with the diode) severely limit any current which might be fed into the I/O pin to 100 µA.

@Paul__B Well, I guess the lights finally came on........

Although I am not totally sure how to interpret that .... :astonished: