Inductive Proximity Sensors Troubleshooting

I am programming an automated table saw using a stepper motor and two NPN NO inductive sensors. Originally I had used E18-D80NK (IR) sensors and had the code working. Then I bought LJ12A3-4-Z/BX (NPN NO) inductive sensors to work better in a dusty environment. These sensors only require a 5v supply voltage so I wired them directly to 5V and GND on the Arduino Mega I am using. I have tried powering the board with the 9V "barrel jack" and the USB jack. Below is the code I am using. Right now I can get the LEDs on the sensors to respond while the Arduino is powered, but when I press the cycle start button the stepper will run and the sensors do not respond (no LED action). My best guess is that I need a larger power supply and a protected circuit to not damage the Arduino, but I was hoping to avoid that by using 5v sensors. Any help with code errors or troubleshooting methods would be greatly appreciated!

#include <AccelStepper.h>
#include <Bounce2.h>

#define STEPPER_WIRE_A 11 //first stepper pin
#define STEPPER_WIRE_B 10 //second stepper pin
#define CYCLESTART 7 //cycle start button digital pin
#define END_PROX 2 //end prox sensor digital pin
#define HOME_PROX 1 //start+home prox sensor digital pin
#define SAW_POWER 15 //saw start digital pin

#define jogSpeed 30000
#define jogAccel 5000

AccelStepper stepper(AccelStepper::FULL2WIRE, STEPPER_WIRE_A, STEPPER_WIRE_B);  //Instantiate 2 wire stepper object

Bounce cycleStart = Bounce();
Bounce endProx = Bounce();
Bounce homeProx = Bounce();

int cStartStatus = HIGH;
int eProxStatus = HIGH;
int hProxStatus = HIGH;


void setup() {

  pinMode(CYCLESTART, INPUT_PULLUP);
  cycleStart.attach(CYCLESTART);
  cycleStart.interval(50);

  pinMode(END_PROX, INPUT_PULLUP);
  endProx.attach(END_PROX);
  endProx.interval(50);

  pinMode(HOME_PROX, INPUT_PULLUP);
  homeProx.attach(HOME_PROX);
  homeProx.interval(50);

  stepper.setMaxSpeed(jogSpeed);
  stepper.setAcceleration(jogAccel);

  Serial.begin(9600);

  delay(500);
}

void loop() {

  cycleStart.update();
  cStartStatus = cycleStart.read();

  endProx.update();
  eProxStatus = endProx.read();

  homeProx.update();
  hProxStatus = homeProx.read();

  if (cStartStatus == LOW) {
    digitalWrite(SAW_POWER, HIGH);
    delay(500);
    while (eProxStatus == HIGH) {
      endProx.update();
      eProxStatus = endProx.read();
      stepper.setSpeed(-jogSpeed);
      stepper.run();
    }
    stepper.stop();
  }
  while (hProxStatus == HIGH) {
    homeProx.update();
    hProxStatus = homeProx.read();
    stepper.setSpeed(jogSpeed);
    stepper.run();
  }
  digitalWrite(SAW_POWER, LOW);
  stepper.stop();
}

6V minimum for the LJ12A3-4-Z/BX: https://datasheetspdf.com/pdf/1096182/ETT/LJ12A3-4-Z/1

Hi, If you are using High Voltage Digital inputs, you can achieve it with an opto-coupler. I have wrote a blog on how to use Inductive proximity sensor with arduino using opto-coupler. In the circuit I used IR Sensor for reference. But you can connect Inductive proximity there. I tested it and it is working. You can check out the blog here.

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