LJ12A3-4-Z/BX NPN 24V Approach Sensor Inductive Proximity Switch Documentation
The LJ12A3-4-Z/BX is a high-sensitivity, NPN-type inductive proximity switch designed for detecting the presence or absence of metallic objects. It operates on a 24V supply and offers a reliable and efficient sensing solution for a wide range of applications.
| Pin | Description |
| --- | --- |
| VCC | Power supply (24V) |
| GND | Ground |
| OUT | Output signal (NPN Open Collector) |
Operating voltage: 24V DC
Detection distance: 4mm
Response time: 10ms
Output type: NPN Open Collector
Operating temperature: -25C to 70C
### Example 1: Basic Object Detection using Arduino
This example demonstrates how to use the LJ12A3-4-Z/BX proximity switch to detect the presence of a metallic object using an Arduino board.
```c
const int sensorPin = 2; // Connect the sensor output to digital pin 2
const int ledPin = 13; // Connect an LED to digital pin 13 (optional)
void setup() {
pinMode(sensorPin, INPUT);
pinMode(ledPin, OUTPUT);
}
void loop() {
int sensorState = digitalRead(sensorPin);
if (sensorState == LOW) {
// Object detected, turn on the LED
digitalWrite(ledPin, HIGH);
} else {
// No object detected, turn off the LED
digitalWrite(ledPin, LOW);
}
delay(50);
}
```
### Example 2: Distance Measurement using Raspberry Pi (Python)
This example demonstrates how to use the LJ12A3-4-Z/BX proximity switch to measure the distance between the sensor and a metallic object using a Raspberry Pi and Python.
```python
import RPi.GPIO as GPIO
import time
# Set up GPIO mode
GPIO.setmode(GPIO.BCM)
# Define sensor pin and output pin
sensor_pin = 17
output_pin = 18
# Set up sensor pin as input and output pin as output
GPIO.setup(sensor_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(output_pin, GPIO.OUT)
try:
while True:
# Read sensor state
sensor_state = GPIO.input(sensor_pin)
if sensor_state == False:
# Object detected, toggle output pin
GPIO.output(output_pin, not GPIO.input(output_pin))
print("Object detected!")
else:
print("No object detected.")
time.sleep(0.1)
except KeyboardInterrupt:
GPIO.cleanup()
```
Note: In both examples, make sure to connect the sensor output to a suitable input pin on your microcontroller or single-board computer, and ensure that the power supply and ground connections are made according to the datasheet.