Proximity with not working

I'm using 6 prox. sensors(LJ12A3-4-Z/BX) off amazon and seem to be having problems with making 3 of them be seen by the Arduino Due. I have wired all six the same way and used the onboard Pullup resistor for each of them. I have powered them with a 12V power supply. 3 of them work perfectly fine but I can't seem to get the other three to register with the MCU for some reason.

I can plug the offending prox. switches into the wires of the working Prox. switches and they work fine, I have double check my wires for the non working Prox. switches and I have continuity all the way to the MCU and power supply, the Prox. has an LED on the back side that will light up when it is near metal and go off when the metal is taken away so it seems to be working properly but still doesn't register with the MCU.
I also tried just connecting the prox. directly to the power supply and MCU(breadboard style connections)and still no help.

Any help is appreciated.

//COUNTER
int staplercounter = 0;
int staplercountercurrentState = 0;
int staplercounterpreviousState = 0;
int staplerSensorcounter = 48;

unsigned long previousMillis = 0;
const long interval = 25;


void setup() {
  pinMode(staplerSensorcounter, INPUT_PULLUP);

  Serial.begin(115200);
}

void loop() {

  Counter();
}

void Counter() {
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;
    staplercountercurrentState = digitalRead(staplerSensorcounter);     //used to time all events
  }
  if (staplercountercurrentState != staplercounterpreviousState) {    //check the count and add 1
    if (staplercountercurrentState == 1) {
      staplercounter = staplercounter + 1;
      Serial.println(staplercounter);
    }
  }
  staplercounterpreviousState = staplercountercurrentState;
}

If you hooked the output signal directly to the Due's input pins and didn't use a voltage divider, congratulations, you've applied 12V to the Due. It's time to buy a new board.

Read this:
https://electropeak.com/learn/interfacing-inductive-proximity-sensor-lj12a3-4-z-bx-with-arduino/

If the sensor is NPN, open collector, the using the internal pullup on the output pin will not destroy the sensor or the DUE.
That is the reason for open collector NPN outputs, so you can easily interface with different voltage logic circuits.

All at the same time, you code only uses one input.

Do you have a DMM?
Is the 12V supply gnd for the sensors connected to the gnd of the DUE?

Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

I'm seeing that as I look further (I saw the same link that @JCA34F referenced and figured that was game over). Once again I've been slapped about the face with the wet haddock of reality: "do not believe everything you read on the web". I'm still trying to find an actual datasheet to prove to myself that the output is open collector.

Edit: the closest I've been able to find to a datasheet is inconclusive. It gives an output current sink rating, which makes it sound like it's open collector. But then down at the bottom it shows this diagram which makes it look like it's not.

Likewise, @1ribbonman may need to do some basic experiments without the controller to check exactly what unit he has.

Tom... :smiley: :+1: :coffee: :australia:

1 Like

Same here......??

Do you have a volt meter and some resistors (1k ~ 10k) to test the switches?

1 Like

How about a schematic, or a well-lit photo, of what you have in front of you.

Hi @TomGeorge,
The prox. is NPN NO switch which is why I bought them as I used Hall sensor on a previous project that were NPN and went with something I knew how to wire( I thought).

I was using the code to test each one to make sure they work that is why it only uses one.The code for the project is rather lengthy and this was much easier for everyone to see what I'm trying to do without the rest of the code.

I have been using 3 of the Prox. switches for a while now trying to get everything up and running and decided to add a few more for better control, the first 3 have run flawlessly during that time and just don't understand what I've done wrong with the added 3, when I ask a question someone usually asks me a question that helps me get to the solution.

The 12V ground isn't connected to the Due but the shielded cable drain is connected back to the Due.

I will work on a better wiring diagram.

Photo from supplier for wiring.
BN is 12V
BK GND
Blue Signal

That's wrong!

BN is 12V+
BK Signal
Blue 12V - (GND)

Signal appears between BK & Blue.

Hi,
Have you swapped the good 3 with the suspect 3?

Tom.. :smiley: :+1: :coffee: :australia:

@TomGeorge I have swapped them and they do work.

I tried using external pullup resistors going from 1K to 10K and still no luck, I also moved one of the working prox. to another digital pin on the MCU that the messed up ones are using and it worked just fine so I guess I will have to check my wire connection to see if I haven't soldered them properly on the bad prox. connections, but since they check out for continuity from prox. to MCU and power connections I'm not sure what to look for.

As a side note when I was moving things around from one digital pin to another I forgot to add the internal or external pullup this morning and the good prox. still was seen by the MCU when I tried it.

The sketch provided only uses one pin, #48. What are you swapping?

Does the real setup/code work if you swap in pushbuttons in place of the sensors?

@DaveX
I have 3 Prox. switches currently working so I took one of them and connected it to the digital pins that the non working Prox.'s are using to verify the pins are in fact working to rule that out as a problem.

I don't have a push button to verify your second question.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.