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);
}