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 Veteran
    Builder

    Joined:
    Dec 29, 2015
    Messages:
    752
    Likes Received:
    547
    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 New
    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 Veteran
    Builder

    Joined:
    Dec 29, 2015
    Messages:
    752
    Likes Received:
    547
    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.
  4. Mouldy

    Mouldy New
    Builder

    Joined:
    Aug 23, 2017
    Messages:
    31
    Likes Received:
    2
    Very useful article. I've ordered a set of these and some stranded twisted pair sheilded cable. Hopefull will all go together ready when I extend my CBEAM XL and hopefully do a "proper" neat wiring job. Do you think it would be good to mount the caps, resisters and diodes on a small Vero board? Would be neater and compact but can that introduce any noise issues?

    So I end up with :-
    o - Twisted pair sensor cables
    o - Shielded sensor cables grounded at one end to the frame
    o - Frame grounded to mains earth (NOT controller ground)
    o - caps and resister pair noise filter

    Hopefully doing all the above will cover all the noise bases.
     
  5. Metalguru

    Metalguru Veteran
    Builder

    Joined:
    Dec 29, 2015
    Messages:
    752
    Likes Received:
    547
    Sounds like you are on the right track. Yes, a small vero board to mount all the components on should work OK. Just keep it close to the controller. Theres been some mention on another thread about using those little clip on ferrites or ferrite rings on your wiring. Can't hurt.

    I try to run my wiring from the sensors buried in a v-slot as much as possible, with a piece of slot cover to hold it in. Also, on the Ox build, you can run wires through the center hole in the X axis brace to keep them out of sight and sort of shielded.

    MG
     
  6. Mouldy

    Mouldy New
    Builder

    Joined:
    Aug 23, 2017
    Messages:
    31
    Likes Received:
    2
    Yes good idea and could fasten in with some copper tape to complete the 4th side.
    Embarrassing admission is that I have now found my false limit trigger was actuall a wire that had got under tge base and pressed on the micro switch !! Need better cable management
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice