Introduction: 3 Wire Inductive Sensor and LeoStick

About: In a continuous learning process.

3 wire inductive metal sensor used with LeoStick. On Serial Monitor or Serial Plotter you will get indication if sensor is activated (close) or inactive (open).

Step 1: Parts List

Parts list:

- Arduino (or any compatible board; I am using an LeoStick for this project)

- 3 wire inductive metal sensor (I am using an Contrinex DW-AD-403-M5E 10-30 VDC 200mA PNP)

- External power supply 10-30 V for sensor (NOT SHOWN IN THIS PICTURES)

- LED (optional; I am using only for extra indication that sensor is working when activated)

- Voltage divider from 12V to 5V (made from one 15k and one 10k resistors)

- Wires

Step 2: ​Prepare Voltage Divider As Follow

- Solder 15k and 10k resistors together.

- Solder an wire same place where you solder the two resistors

Usage: 15k resistor free end will be input from sensor, 10k resistor free end will be ground connected to Arduino GND pin and external power supply GND; middle wire will be output to Arduino digital input pin (D2 in my case)

Step 3: Connect Sensor to Voltage Divider and Power Supply

- Connect sensor positive cable (brown in my case) to 10-30 V power supply

- Connect sensor negative cable (blue in my case) to power supply ground

- Connect sensor data cable (black in my case) to 15k free end of voltage divider.

Step 4: Connect LED (optional)

- Connect LED positive terminal to middle voltage divider wire

- Connect negative terminal to ground

In my case I've been using same external power supply for this LED due to extra 5V output.

Step 5: Upload Code to Arduino

- Upload code to Arduino

/* DigitalReadSerial Reads a digital input on pin 2, prints the result to the serial monitor/serial plotter

This example code is in the public domain.

*/

// digital pin 2 has a PNP sensor attached to it.

int metalSensor = 2;

// the setup routine runs once when you press reset:

void setup()

{

// initialize serial communication at 9600 bits per second:

Serial.begin(9600);

// make the sensor's pin an input:

pinMode(metalSensor, INPUT);

}

// the loop routine runs over and over again forever:

void loop()

{

// read the input pin:

int sensorState = digitalRead(metalSensor);

// print out the state of the sensor:

Serial.println(sensorState);

delay(1000);

// delay in between reads for stability

}