Welcome to Our Community

Some features disabled for guests. Register Today.

Prox Sensor Wiring for Limit/Homing Switches

Discussion in 'General Electronics' started by Metalguru, Dec 28, 2016.

  1. Metalguru

    Metalguru Master
    Builder

    Joined:
    Dec 29, 2015
    Messages:
    423
    Likes Received:
    250
    Hey All:

    This topic was brought up in the Big Ox Heavy Duty thread, and a few people asked about wiring using the small proximity switches for limits or homing switches on these machines.

    Since I thought this might be a useful topic, I moved over here and created a new one to discuss this.

    I have been using the small electronic proximity sensors for homing switches on machines that I build for quite some time. They are economical, reliable, and work pretty well. They are available from many sources on eBay, Amazon, and others for almost less than what it costs for a micro switch type limit. They do require a bit more wiring than limits, simply because they require a power source to function. Let's take a look:

    20161228_142506.jpg

    This is one of the more common units available, Chinese made and branded Fotek. It has a sensing distance of about 5mm for steel (hence the -05 in the part number), and a 3 wire connection. This unit is an NPN transistor output, which means it has an NPN transistor which pulls the output line to ground when the sensor is activated. These are available in PNP output as well, which has a PNP transistor which pulls the output to VCC when the output is active. This type is not really useful for our application. The -N suffix on the part number shown on the unit indicates that this is an NPN output type. The PL prefix in the part number indicates that this is a long body type sensor, there are long and short bodied sensors. There is actually only a couple of millimeters difference in length so this is not really important.

    These sensors require a power input of 10-30 VDC to operate. Since the Arduino typically on a CNC machine is 5V, it is not capable of operating these sensors. You might think that you could just hook it up to your 24V motor supply, but there are a couple of problems with this. Typically, stepper driver modules have optically isolated control inputs to maintain isolation from the machine motor power supply and the Arduino. This is a Good Thing, as MS would say. If you used the motor power to run the sensors, you would be compromising this isolation since the ground from the sensors and the ground on the Arduino would have to be connected together. In addition, it may cause noise and ground loop problems if you tied motor ground and Arduino ground together. I don't recommend doing this no matter how convenient it may seem.

    I usually just use a separate 12V wall wart power supply to run the sensors. You can connect the ground from this supply to the Arduino without problems since it is an isolated supply. I have done up a diagram shown below:

    prox wiring.JPG

    There is a lot more going on in the diagram than has been discussed yet. We are about to remedy that. As you can see, the prox sensors just have their power and ground wires tied together to the incoming 12v supply + and -. This is pretty self explanatory. Note that the ground from the power supply/sensors is tied to the Arduino board as well.

    Now we get into the purpose of the components shown on the diagram associated with the prox sensor outputs. The arduino board digital inputs D9, D10, and D12 have internal pullup resistors to 5v inside the PIC chip. Unfortunately, these are very high value resistors and make weak pullups. This means that it is quite easy to induce noise onto these signal lines which can cause false triggering of the digital inputs, and hence either false limit switch alarms or false homing signals. This can be a real pain in a machine, because limit switch alarms cause you to have to reset the processor and then reset the alarm. In the case of the homing switches, it can cause problems with the homing cycle. Since this is not a Good Thing, (thanks Martha) we need to take steps to avoid problems.

    It seems for some reason that the Arduino Uno is a bit more immune to this noise than the Arduino Nano. I have increasingly been using Nano's since they are much smaller, have a cool little screw terminal wiring board that makes wiring a snap, and don't require enclosures or shields. In either case, I find it prudent to at least put a 0.1uF capacitor from each digital in terminal to ground. This bypasses noise coupling into the digital inputs and vastly improves the noise immunity of the input. You don't need much of a capacitance to make a drastic improvement. I highly recommend this mod, especially with Nanos. Just solder the caps onto the back of the board and tie the common terminals to ground.

    If this does not do the trick, you need to take more drastic measures. This is where the external pullup resistors come in. They are kind of optional, if the caps do the trick for you, you may not need them. If you are still getting false limit alarms, you may have to add additional pullup resistors. I usually use either 4.7K ohm or 2.7K ohm resistors. Smaller value resistors will be more effective, but don't go lower than 1K or so.

    Note that these modifications are just as relevant with plain old microswitch limit switches as they are with the proximity types. Noise can haunt your limit switches just as easily as your prox sensors.

    Now we get to the diodes. These are necessary with the prox sensors that I have seen because of a problem with the output NPN transistor in the unit. Normally, this should not be pulled up inside the prox sensor because this means that the NPN output will float at the power supply voltage, which in this case is 12V. Obviously, it is not good for your 5V Arduino to have 12V on it's digital input pins, this could destroy the inputs, making the arduino a paperweight. The manufacturer should not have put these pullups into the device, but they did anyway. It would have worked properly if they had not included this pullup. To avoid problems, it is necessary to add a diode to each input in series with the line from the prox sensor. The diode cathode (the end of the diode with the paint stripe on it) should be towards the sensor. This prevents 12v from the sensor from reaching the Arduino input, but allows the NPN transistor to pull the input low when active. I usually just solder these diodes in series with the lead from the sensor where it goes into the screw terminal on the arduino. Be sure to put a bit of heat shrink over the diode to prevent shorts.

    Just about any diode will work. A 1N400X, where x=1-7, is about the most common. This is just a standard 1A rectifier diode, with a forward drop of about 0.7v. A 1N5819 or equivalent Schottky diode would be better, Schottky's only have a forward voltage drop of about 0.4V, which would help in this circuit. Since the diode only conducts a few mA, a small signal diode like a 1N914 would also work.

    On to mounting. For homing switch applications, I usually try to standardize mounting of the prox sensors. The Z axis prox is usually mounted on one of the X axis wheel screws, or sometimes on the top of the carriage gantry plate. A screw and tee nut on the Z axis v-slot is usually sufficient for a target. You can see a mounting example here on a Big Ox HD Z axis. I mounted a 2 hole angle bracket on the wheel screw, and then used a limit switch mounting plate from the OB store to mount the prox sensor. Conveniently, the hole pattern on a microswitch is the same distance apart as the mounting holes on the prox senor, so the limit switch plate is a convenient way to mount the prox sensor.

    20161228_142456.jpg

    Note that these proximity sensors, although they say they have a sensing distance of 5mm, this applies only to steel targets. If you use aluminum targets, their sensing distance is only about 2mm. This is not a big deal, they will still reliably detect an aluminum object, the just have to be mounted closer.

    Below is shown a mounting for the X axis. You can see I put an 2 hole angle bracket on one of the screws on the side of the gantry plate, and then put a 1/8" aluminum spacer to lift up the prox senor to clear the top of the gantry plate. I also bent the limit switch mount a bit to angle the sensor down. It just picks up the edge of the X axis plate when it gets close to the end of its travel at X- or the left side of the gantry. This shows the switch mounting, and the first picture in this thread shows the gantry being detected.

    20161228_142216.jpg



    For the Y axis, I again put an angle bracket on the front wheel screw on the gantry plate. The prox sensor goes on a limit switch mount, and faces forward. I then put another angle bracket on the side of the 20x80 rail to act as a target. Spacers are used to get everything to line up. Couple of notes here, if you want a bit more sensing distance, you can put a screw and tee nut in the target angle bracket, the steel will increase distance. I also like to put a piece of heat shrink over the angle bracket target, its a real ripper if you accidentally scrape your arm or hand on the sharp edge sticking out.

    20161228_142503.jpg

    Well, that's about all I can think of for now. Oh, and of course if you want the full limit switch package, You would need 3 more sensors for the opposing ends of each axis. Just wire the opposing sensors for each axis in parallel with these homing switches. You would really only need one diode for each pair of sensors.

    Ask questions or come up with your own mounting arrangements, and share them with us.

    MG
     
    #1 Metalguru, Dec 28, 2016
    Last edited: Dec 31, 2016
  2. mybuild14

    mybuild14 Well-Known
    Builder

    Joined:
    Mar 20, 2014
    Messages:
    23
    Likes Received:
    5
    MetalGuru, Thanks for the diagram and the short tutorial on proximity sensors. I just ordered the same proximity sensors you are using (EBay 10 for less than $22).
    My question is in reference to the use of diodes to prevent 12 volts from reaching the Arduino or in my case the Protoneer Hat 2.58. What value and type of diode should I use?
     
    #2 mybuild14, Dec 30, 2016
    Last edited: Dec 31, 2016
  3. Metalguru

    Metalguru Master
    Builder

    Joined:
    Dec 29, 2015
    Messages:
    423
    Likes Received:
    250
    Yeah, I forgot to put that in the tutorial. Just about any diode will work. A 1N400X, where x=1-7, is about the most common. This is just a standard 1A rectifier diode, with a forward drop of about 0.7v. A 1N5819 or equivalent Schottky diode would be better, Schottky's only have a forward voltage drop of about 0.4V, which would help in this circuit. Since the diode only conducts a few mA, a small signal diode like a 1N914 would also work.

    These are all available at the usual suspects such as Mouser, Digikey, Allied, Element 14, etc.

    MG
     
    #3 Metalguru, Dec 30, 2016
    Last edited: Dec 31, 2016
    mybuild14 likes this.

Share This Page