Hi everyone (hope, I'm in the right section for this..)
Is this connection of two inputs (w internal pullup) and three switches as in the attached picture a valid connection?
What I'm trying to achieve is a detection of one input (yellow) to GND (represented by S2) and one input to another (represented by S2 to the base of the transistor).
So, if S1 is closed => D3 is LOW.
S2 is closed => D7 is LOW.
S3 is closed => both D3 and D7 are LOW.
Is this a valid approach? Should I add something (base resistor) for protecting my Arduino?
And D7 and D3 need to be set to mode INPUT_PULLUP, not OUTPUT
[ or as INPUT and add some external pull-up resistors - might be needed if the switches
are remote and noise is an issue, the internal pull-ups are quite weak, external 2k2 pullups
would cope much better ]
Jiggy-Ninja:
When S2 and S3 are closed, D3 will be HIGH. Is that acceptable?
I leave it as an exercise to you to understand why it happens.
Is there some reason you can't just use 3 digital inputs and do this logic in code?
That is indeed acceptable. I haven't realised this before, thank you for pointing that out. But this is no problem, since S3 should have the higher prority in the final program.
The reason for this type of reading inputs is: I'm building a buzz-wire game, and the wire has to be GND. The ring would be Input X und a target contact Input Y (the base of the transistor). So S2 would represent the contact between ring and wire. And S3 would stop the game, when the ring touches the metal target contact. S1 has no relevant function yet..
I know, there are easier ways to realize this (make the Ring GND), but I'm bound to the wire being GND.
So is it ok to keep the base of the transistor "floating"? Someone could touch it, but this shouldn't affect my readings of D3, could it?
A floating base can pick up mains hum and start conducting every half-cycle - the cure is some
suitable resistance between base and emitter to reduce the input impedance.
For a large buzz wire you may be picking up interference unless you lower the impedance of
everything (use physical pull-up resistors of 1k perhaps).
derGeppi:
That is indeed acceptable..... But this is no problem, since S3 should have the higher prority in the final program.
These two sentences make no sense. You say S3 should have higher priority, but with the way you've wired things it doesn't. If S2 and S3 are both closed, the D3 input will not be pulled LOW. It will be left HIGH. Your software can't change the wiring of an external circuit. Right now there's no way to distinguish between only S2 pressed and S2+S3 being pressed.
I know, there are easier ways to realize this (make the Ring GND), but I'm bound to the wire being GND.
I can speculate just as well as you can about what reasons derGuppi might have, but that's pointless. The only way to know is the ask the person in question.
Jiggy-Ninja:
These two sentences make no sense. You say S3 should have higher priority ...
Oops.. forgive my typo.. You're totally right. It should be S2 with "touching the wire" is more important to be detected. Once D3 is pulled low there will be no more readings from these inputs.
And MarkT is correct: the wire is part of the metal housing, which is grounded as well
"Grounding" has two meaning in electrical circuits, which is why I hate it so much. It refers to either the 0V common node or the earth safety connection.
I believe that chassis grounding is only necessary when mains voltage is brought into the device. If you are being powered by an isolated power brick (like a USB phone charger), the voltages are low enough to be safe even if exposed metal is "live". An isolated supply often won't even have an earth terminal on the plug, so it doesn't matter whether anything is connected to the + or - terminal.