digitalRead() function of Arduino doesn't read Input value sent by sensor after detecting the object I'm trying to turn ON the LED(inbuilt/PIN13) when photoelectric proximity sensor(12v) senses any object. Sensor is connected on pin 2. Assigned pin 2 as INPUT, I've got a 12v spdt relay for switching. 12v output from sensor is fed to coil, on the other end 5v supplied to COM pin and &quot;Normally Open&quot;(NO) pin to Arduino (with pull-down resistor). When 'NO' connected to loose LED it works properly (shows 5V on voltmeter when object is detected). But when connected to Arduino digitalRead(), it always returns LOW/0.
//code
int a=0;
void setup() {
  pinMode(2,INPUT);
  pinMode(13,OUTPUT);
  Serial.begin(9600);
}

void loop() {
  a ==  digitalRead(2);
  Serial.println(a);
  if(a==HIGH){
    Serial.println(&quot;Object Detected&quot;);
    digitalWrite(13,HIGH);  
  }else{
    Serial.println(&quot;There's no object&quot;);  
    digitalWrite(13,LOW);  
  }
  delay(1000);
}
a == digitalRead(2) must be a = digitalRead(2). You also better change the if clause to if(a) to avoid true/HIGH/1 confusions.
If you had formatted the code properly, you'd have safed some time (you just need to select the code and press the {} button).
You also better replace the relay with a voltage divider (as I mentioned in my comment), because as long as you don't have a datasheet for the sensor you can't be sure that the sensor is designed to source that much current. If the sensor is supposed to drive a TTL logic, it will eventually fail, just like you don't drive relays with GPIOs directly. And beside that you need a freewheeling diode across the relay coil to deal with back EMF which will also harm the sensor.