To connect a standard industrial 12V/24V NPN inductive proximity sensor to a 5V Arduino Nano, wire the Brown wire to your 12V supply, the Blue wire to common Ground, and route the Black signal wire through a 10kΩ/4.7kΩ voltage divider into digital pin D2. Never wire the Black signal wire directly to a 5V Arduino GPIO pin; the 12V high-state will instantly destroy the ATmega328P microcontroller. Because NPN sensors are open-collector and sink to ground when triggered, the Arduino will read a LOW signal when metal is detected and a HIGH signal when the field is clear.

Project Spec Sheet & Parts List

This build targets the Arduino Nano V3.0 (ATmega328P, 5V logic). While industrial PLCs typically handle 24V sensor logic natively, microcontrollers require signal conditioning. The parts below reflect standard 2026 bench pricing for hobbyist and prototyping setups.

Component Exact Variant / Model Role in Circuit Est. Price (2026)
Microcontroller Arduino Nano V3.0 (ATmega328P) 5V Logic processing and debounce $6 (Clone) / $24 (Genuine)
Proximity Sensor LJ18A3-8-Z/BX (NPN, NO) Inductive metal detection (8mm range) $8 - $11
Power Supply 12V DC 2A Switching PSU Powers the sensor (6-36VDC range) $7
Resistor 1 (R1) 10kΩ 1/4W Carbon Film High-side voltage divider leg $0.02
Resistor 2 (R2) 4.7kΩ 1/4W Carbon Film Low-side voltage divider leg $0.02
Safety & Hardware Warning: The LJ18A3-8-Z/BX is an NPN Normally Open (NO) sensor. If you accidentally purchase the PNP variant (often denoted with a different suffix, like -C), the output will source 12V directly when triggered, which will bypass the voltage divider's intended logic if wired incorrectly and fry your board. Always verify the datasheet schematic printed on the sensor barrel before applying power.

Pin Mapping and Voltage Divider Wiring

Industrial sensors operate at higher voltages than microcontrollers. To safely step the 12V signal down to a logic HIGH that the ATmega328P recognizes (which requires a minimum of 3.0V for VIH, and an absolute maximum of 5.5V), we use a passive voltage divider.

The Math: Vout = Vin × (R2 / (R1 + R2))
Vout = 12V × (4.7k / (10k + 4.7k)) = 3.83V.
3.83V is perfectly safe for a 5V Arduino pin and registers reliably as a logic HIGH. When the sensor triggers, the internal NPN transistor saturates, pulling the output to ~0.3V. 0.3V × (4.7 / 14.7) = 0.09V, which registers as a solid logic LOW.

Sensor Wire Color Function Connection Destination
Brown VCC (+) 12V PSU Positive Terminal
Blue GND (-) 12V PSU Negative / Arduino GND (Common Ground)
Black Signal Out Resistor R1 (10kΩ) -> Junction -> Arduino Pin D2
N/A (Junction) Divider Tap Resistor R2 (4.7kΩ) connected from Junction to GND

Numbered Wiring Steps

  1. Establish Common Ground: Connect the 12V PSU negative terminal to the Arduino Nano GND pin. Without a shared ground reference, the voltage divider has no return path and the signal will float.
  2. Build the Divider: Insert R1 (10kΩ) and R2 (4.7kΩ) into the breadboard so they share a common node (the junction).
  3. Wire the Signal: Connect the sensor's Black wire to the free leg of R1. Connect the junction node to Arduino Digital Pin D2.
  4. Ground the Divider: Connect the free leg of R2 to the common ground rail.
  5. Apply Sensor Power: Connect Brown to 12V and Blue to the common ground rail. Do not power the Arduino via the 12V PSU's VIN pin unless your Nano's onboard regulator is adequately heatsinked; use USB for the Nano during bench testing.

Arduino Nano Code: Debounce and State Machine

Inductive sensors don't suffer from mechanical contact bounce like tactile switches, but they do suffer from electromagnetic interference (EMI) and comparator hysteresis when detecting irregular metal edges (like gear teeth). This code implements a non-blocking millis() debounce filter to prevent false triggers. This code specifically targets the Arduino Nano V3.0 (ATmega328P).

// Target Board: Arduino Nano V3.0 (ATmega328P, 5V Logic)
// Sensor: LJ18A3-8-Z/BX (NPN Normally Open)

#define SENSOR_PIN 2
#define STATUS_LED 13
#define DEBOUNCE_DELAY 50 // milliseconds

bool lastSensorState = HIGH;
bool currentSensorState = HIGH;
unsigned long lastDebounceTime = 0;

void setup() {
  Serial.begin(115200);
  
  // NPN sensors pull LOW when triggered, and float when off.
  // INPUT_PULLUP activates the internal 20k-50k resistor to prevent
  // floating states if the external voltage divider fails or is disconnected.
  pinMode(SENSOR_PIN, INPUT_PULLUP);
  pinMode(STATUS_LED, OUTPUT);
  
  Serial.println("[PROXIMITY] System Initialized. Awaiting metal...");
}

void loop() {
  bool reading = digitalRead(SENSOR_PIN);

  // Check for state change and reset debounce timer
  if (reading != lastSensorState) {
    lastDebounceTime = millis();
  }

  // If the state has been stable longer than the debounce delay
  if ((millis() - lastDebounceTime) > DEBOUNCE_DELAY) {
    // If the reading has actually changed from the confirmed state
    if (reading != currentSensorState) {
      currentSensorState = reading;
      
      // NPN Logic: LOW = Metal Detected, HIGH = Clear
      if (currentSensorState == LOW) {
        digitalWrite(STATUS_LED, HIGH);
        Serial.println("[PROXIMITY] Metal Detected: 1");
      } else {
        digitalWrite(STATUS_LED, LOW);
        Serial.println("[PROXIMITY] Metal Detected: 0");
      }
    }
  }

  lastSensorState = reading;
  
  // Add a small yield to prevent watchdog issues on some clone boards
  delay(1); 
}

Debugging: First Three Things to Check When It Fails

When integrating industrial sensors with hobbyist microcontrollers, failures usually stem from logic-level misunderstandings or grounding faults. Here is the diagnostic decision tree for the most common bench errors.

1. Symptom: Serial monitor spamming [PROXIMITY] Metal Detected: 1 with no metal nearby

  • Most Likely Cause: Floating input pin or missing common ground. The NPN sensor is open-collector; it requires a pull-up resistor to register a HIGH state when inactive. If your voltage divider R2 is disconnected from ground, the pin floats and picks up 60Hz mains noise.
  • Secondary Cause: You are using a PNP sensor instead of an NPN sensor. A PNP sensor sources voltage when inactive, which might be misinterpreted by the divider network.
  • The Fix: Verify the 12V PSU ground is physically jumpered to the Arduino Nano GND. Ensure pinMode(SENSOR_PIN, INPUT_PULLUP); is in your setup block as a failsafe. Check the sensor barrel diagram to confirm the internal transistor symbol points inward (NPN).

2. Symptom: Sensor barrel LED turns on near metal, but Serial reads [PROXIMITY] Metal Detected: 0

  • Most Likely Cause: Voltage divider ratio is dropping the HIGH state below the ATmega328P's VIH threshold (3.0V), or the logic inversion in the code is backwards.
  • Secondary Cause: You are measuring the voltage divider output with a multimeter while the Arduino pin is disconnected, but when connected, the pin's internal protection diodes are clamping the voltage.
  • The Fix: Measure the voltage at the junction node with a multimeter while the sensor is inactive. It must read between 3.0V and 5.0V. If it reads ~1.5V, your R1 and R2 values are swapped. Swap the 10kΩ and 4.7kΩ resistors. Remember: NPN pulls to ground on trigger, so trigger = LOW.

3. Symptom: avrdude: stk500_getsync() response: 0x00 when uploading code

  • Most Likely Cause: 12V backfeeding into the Arduino's 5V rail, causing a brownout on the USB interface chip (CH340 or FT232RL), or D0/D1 (TX/RX) pins are shorted to the sensor circuit.
  • The Fix: Disconnect the 12V PSU entirely before uploading code via USB. Ensure the sensor signal is strictly on D2, not D0 or D1. If you accidentally fed 12V into a 5V pin, the ATmega328P or the USB-UART bridge is likely permanently damaged and the board must be replaced.

How to Extend or Simplify the Build

Depending on your end application, you may need to scale this circuit for industrial noise or simplify it for a quick weekend prototype.

To Simplify (Hobby/Robotics): Ditch the 12V inductive sensor and the voltage divider entirely. Use an RCWL-0516 Microwave Radar Sensor ($2) or an IR Obstacle Avoidance Sensor ($1.50). These operate natively at 5V/3.3V and output a clean digital HIGH/LOW without requiring signal conditioning. They lack the ruggedness of an inductive barrel sensor but are perfect for 3D-printed enclosures and indoor robotics.

To Extend (Industrial/Noisy Environments): If you are mounting this sensor near a Variable Frequency Drive (VFD), a large contactor, or an arc welder, the EMI will induce voltage spikes on the sensor cable that can exceed the Arduino's absolute maximum ratings, even through a voltage divider. Replace the voltage divider with a PC817 Optocoupler. Wire the sensor's Black output through a 1kΩ current-limiting resistor to the optocoupler's internal LED anode, and the cathode to 12V ground. On the Arduino side, pull the optocoupler's phototransistor collector up to 5V and wire the emitter to ground. This provides 100% galvanic isolation, meaning a 1000V spike on the sensor side cannot physically reach your microcontroller.

Proximity Sensor Arduino FAQ

Can I wire a 3-wire PNP proximity sensor to an Arduino?

Yes, but the wiring and logic are inverted. A PNP sensor sources the supply voltage (12V) when metal is detected, and outputs 0V when clear. You still require a voltage divider to step the 12V HIGH state down to ~3.8V. However, in your Arduino code, a HIGH digital read will mean metal is present, and a LOW read will mean the field is clear. Always check the schematic printed on the sensor barrel to confirm PNP vs NPN before wiring.

Why does my proximity sensor Arduino project trigger from my hand?

Inductive sensors generate a high-frequency electromagnetic field (typically 1-5 MHz) designed to detect conductive metals via eddy currents. If your sensor triggers from a human hand, you likely have a capacitive proximity sensor (often designated with an 'E' or 'C' in the part number, like an M18 capacitive barrel), not an inductive one. Capacitive sensors detect changes in dielectric constant, meaning they will trigger on water, plastic, wood, and human tissue. Swap it for an inductive model (like the LJ18A3 series) if you only want to detect metal.

What is the difference between NO and NC proximity sensors?

NO stands for Normally Open, meaning the internal transistor does not conduct (the circuit is open) until metal enters the sensing field. NC stands for Normally Closed, meaning the transistor conducts continuously, and stops conducting when metal is detected. For microcontroller projects, NO is heavily preferred because it draws near-zero current when idle, saving power and reducing heat. NC sensors are typically reserved for safety-critical hardwired PLC loops (like emergency stops) where a severed wire must trigger a fault state.

How do I measure the exact sensing distance on my bench?

The 8mm rating on the LJ18A3-8-Z/BX is based on a standard target: a 1mm thick piece of mild steel (Fe 360) measuring 18x18mm (the diameter of the sensor face). If you are detecting aluminum, copper, or brass, the sensing distance drops by 30% to 60% due to lower conductivity and magnetic permeability. To calibrate, mount the sensor on a fixed bracket, place your specific target metal on a digital caliper, and slowly back the caliper away until the Arduino serial monitor registers a state change. For reliable operation in production, set your physical mounting distance to 70% of the measured maximum bench distance to account for temperature drift and voltage sag.