Inductive Proximity Switch/Limit Switch not working as expected with Arduino

I am using a 10-30V, PNP, NC proximity switch /limit switch a with cartesian robot and Arduino Nano. The objective is when the extreme limit is reached, I can get a signal so that I could know and use it. The sensors' works fine, so when the object is in its proximity the LED on it turns off and turns on when it is away. However, the output (in form of 0 and 1) I am getting is quite random and not according to the sensors' LED.

The value I am expecting is Low/High when LED is on and opposite is when it is off. However, I am not getting this. I am New to Arduino BTW.

Circuit: I am directly using sensors' signal to Arduino Pin without any circuit elemet.

I am using the following code:

#include <SPI.h>
int inPin = 2;
int val = 0;
void setup() {
  Serial.begin(9600);
  pinMode(inPin,  INPUT_PULLUP);
}
void loop() {
  val = digitalRead(inPin);
  Serial.println(val);
  delay(1000);
}

Have the two circuits got a common GND connection ?

1 Like

No, the circuit looks like this. (Sorry for poorly drawing)

How should I use a common ground?

Hi,
This is the configuration of your sensor.
image
image

What are you using to power the sensor?
What model Arduino are you using?

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

1 Like

I have designed the circuit as shown in Post#3.

What are you using to power the sensor?
A 30V/10A DC Power Supply
What model Arduino are you using?
Arduino Nano

Then they should have. Without a common GND connection the two devices have no common point of reference when it comes to measuring the signal level

Hi,
Thanks for the info;


You have to connect the Nano Gnd and Sensor power supply Gnd together so the Nano has a reference to the sensor output.

R1 and R2 form a potential divider to drop the 30V output of the sensor to 5V, that is the max input voltage that a Nano is rated at.

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

1 Like

Thank You very much for detailed guidance. It worked.

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