Every once in a while, somebody starts emailing me about a technical question and after a couple of emails, a solution is created, and all the information disappears into the ether. Maybe others could use this information, but I rarely take the time to put the solution out for others to benefit. Well, since I’m still waiting for my Arduino nano boards, I will take this time to bring up one of those small projects.
A couple months ago a user wrote the following: “Because of the half scale of my pin, the ball is too light to press a mechanical switch, I use in some instances IR detectors and induction (proximity sensor) switches but induction sensors are 12v (6v to 36v to be precise but I have a 12v psu already). Is there a simple way to connect it to the processor board without damaging it?” Originally he proposed using an opto-coupler board as a solution (approx $6.68 for 4 bits + $3 shipping), but suddenly my inherent cheapness caught the better of me. Could I do it for a much lower cost?
So the basic issue is a 12v input needs to be attached to a processor pin which can only support up to 5v (in the case of the PSOC). While using an opto-couple board would work wonderfully well, it is just a little too expensive in my opinion for what is needed. Why not use an incandescent board flipped 180 degrees from how it is normally used?
Could a BS170 transistor make it work? If the signal goes between 0 and 12V when the IR signal is blocked or not blocked, you could use that as the gate of the transistor. The drain of the transistor is hooked to the processor input, and the source of the transistor is hooked to the ground of the processor.
Here is a link to the BS170 datasheet: https://www.onsemi.com/pub/Collateral/BS170-D.PDF
The gate threshold in the On characteristics section of the datasheet says, anything on the gate < 0.8V (the minimum), the transistor is off, so the processor will read high since the input bits are pulled up to 5V internally. If the gate voltage rises above 3V (the maximum), the transistor will turn on, and the input will be pulled to ground. BS170 are about 12 cents each if you buy about 100.
The only issue that I can think of off the top of my head is that the sense of the input will be backwards. Normally a closed switch is read as low. If it is like an IR sensor, when the sensor is blocked it actually gives low voltage, so that would read high at the processor. If the IR sensor is not blocked, it gives a high voltage so it would read low at the processor. If using MPF (Mission Pinball Framework), the input bit can be configured as active high, so it should not be a problem.
On the incandescent wing, the connections that normally attach to the processor go to the gate signals of the BS170s and are attached to the output of the inductor sensor. Attach the inputs from the processors to what is normally attached to the incandescent bulbs. (Don’t populate the pullups). At that point you have 8 of the circuits in a nice little package without having to proto board anything. The gate of a BS170 can handle up to 20V, so your induction sensor at 0-12V should be fine. The BS170 acts as a voltage translator, so that high voltage never touches the processor pins. You will have to tie the logic ground from the processor and the ground of the voltage source for the induction sensor together.
The induction sensor turns on and off the transistor. (turns on and off the switch). The source of the transistor is connected to logic ground. The drain of the transistor is connected to input of the processor. When the inductor sensor sends a high voltage, the transistor or switch closes, so the input is grounded. When the inductor sensor sends a low voltage, the transistor or switch opens, and so the input is floating, but there is an internal pullup resistor in the processor so it reads a high voltage.
Here is an attached picture that he sent me to be a little more clear:
In other news, I moved the firmware from 0.3.0.1 to 188.8.131.52 after re-running all the regression tests and adding a new test for the CAN_CANCEL. That feature was added a couple weeks back so that the initial kick of a solenoid could be canceled so things like tap passing is supported by the OPP hardware. (Thanks to Jan for adding the necessary code in MPF to make that happen on their side).