Is this a safe design for an input at a 74HCT165
I'll start with getting your circuit to function, then go on to make some suggested changes. 







simulate this circuit &ndash; Schematic created using CircuitLab

Part numbers refer to my schematic. 

I've increased R5 to 10K from 1K because that much base current is not required. Your 1K would work (it's not wrong), and might be desirable for switch reliability in some cases. 

I've decreased R6 from 100K to 10K because with 10K there is still plenty of base current and 60uA will better deal with pickup than 6uA. If R5 was 1K, I might go to 4.7K for R6 or even 1K. A diode (see below schematic) across R6 would also be good in either case, but I didn't want to change your schematic too much. 

R4 is necessary to limit the base current of Q2. I've picked it roughly to ensure enough base current that Q2 saturates with about 20mA for the LED and a bit more for R3. R1 just deals with leakage of Q1, especially at high temperatures. It's typically not needed at room temperature, but you should put it in there anyway. Less than 1uA through Q1 is enough to create the wrong logic level at the output. 

R2 determines LED current, and I've left it as is. 

R3 is necessary because the LED does not conduct much current at low voltages and we want the input to be pulled down to ground when Q2 is off, not to float around at a volt or two. 

The below circuit would work and would be simpler, though it does not have exactly the same function- the logic is reversed, which could easily be inverted in your firmware. Note I've added D2 to prevent reverse breakdown of Q1's base in case a large negative transient voltage appears on the long wire. 







simulate this circuit

Finally, and especially if the wire goes outdoors, you should consider using a completely separate 12V supply (grounds not even connected together) and optoisolators rather than transistors. That's outside the scope of your question, so I won't go into too many details, but it's almost as simple as replacing Q1 in your original circuit with the optoisolator.