In this illustration we will going to wire the NPN Inductive Proximity Sensor to detect metal or any metal objects, this device also can be used as a metal detector screening when people walking through the entrance to find metal objects.

This metal sensor are inductive sensors. Which means that it induces current when metal is near to it. This sensor is a non-contact electronic sensor that is used detect positions of a metal objects. The sensing sensing range depend on the type of metal being detected. Ferrous Metal, such as iron and steel, allow for a longer sensing range, while nonferrous metal objects such as aluminum, copper, can reduce the sensing range by 60 percent. Since the output of an induction sensor has two possible states, an inductive sensor sometimes referred to as an inductive proximity switch.

This sensor consist an induction loop, electric current generates a magnetic field, which collapses generating a current that falls toward zero from its initial trans when the input electricity stops.

The inductance of the loop changes according to the material inside it and since metals are much more effective conductors that other materials the presence of metal increases the current flowing through the loop. This change can be detected by sensing circuitry which signal pass true to some other device whenever metal is detected.

This device is commonly used in traffic lights, car washes, manufacturing machinery, automated industrial machinery, elevators and building automatons this device is mostly used because can adopt in a rugged and dirt environment.

In this example we will going to used PNP NO 3-WIRE Cylindrical Inductive Proximity Sensor

Inductive-proximity-sensor

Detecting Distance: 4mm
Supply Voltage: DC6-36V
Current Output: 300 mA
Response Frequency: 100Hz
Detect Object: Metal
Column Sensor Dia.12mm

Wiring Guide with Arduino MCU

Proximity-Sensor-With-Arduin-Metal-Sensor-Dectector-001

The metal proximity sensor will have three color wire. The blue should be in the ground, brown is on +VCC which should be giving to Arduino + 5v VCC and when you take metal near tot the sensor it induces more current which results in higher voltage. In this case you need to open your serial monitor to see the incoming signal from the analog pin then make a threshold to determine if metal is detected or not.

Generally speaking the Iron/Copper or Metal with good magnetic properties will induce more that 1v when brought nearer to the sensor you need to touch the surface it will start detecting from a distance about 3CM.

Arduino Sketch

 

Wiring a Metal Detector with NPN Proximity Sensor on Arduino
Facebooktwitterredditpinterestmail
Tagged on:         

JLCPCBPCBgogoPCBway4pcb

22 thoughts on “Wiring a Metal Detector with NPN Proximity Sensor on Arduino

  • at
    Permalink

    Hi ,
    Thanks for the article, i wanna ask you , this sensor, what is it detects range ?

    Reply
  • at
    Permalink

    Do you have a full spec sheet for the sensor?

    Reply
    • at
      Permalink

      The unshielded M18 inductive sensor has a sensing distance of ~10 mm. This sensor has NPN-style, NO+NC contact type output. Widely applied in measuring, Counting, Rpm measuring in mechanism, chemical, paper manufacture light industry, etc.

      Specifications:
      Rated Operational Voltage: 24 VDC
      Supply Voltage: 10 to 30 VDC
      Voltage drop: ≤ 2.0 V
      Rated insulation voltage: ≥ 20 MΩ
      Load current capacity(DC/AC): 200 mA
      Off-state current(NPN/PNP): ≤ 15 mA
      Leak current: ≤ 20 µA
      Protection against polarity reversal: YES
      Short circuit protected: YES
      Load capacity: ≤ 1 µF
      Repeated accuracy: ≤ 5%
      Ambient temperature range: -15…+60°C
      Frequency(DC 3/2 wires/AC 2 wires): 800 Hz/ 400 Hz
      Function indication: Red LED Indicator
      IP ratings: IP67
      Housing material: Nickle plated brass
      Material of sensing face: ABS
      Connection: Fly Leads
      No. of wires x gauge: 12 x 0.16 mm
      Standard lenth of cable: 2 m
      Detection distance: 10 mm
      Approvals: CE

      Reply
  • at
    Permalink

    Great i have done with this, thank you :)
    Anyway, Can I know, where 1024 and 100 from? what formula do you use?

    Reply
    • at
      Permalink

      The ADC on the Arduino is a 10-bit ADC meaning it has the ability to detect 1,024 (210) discrete analog levels, so anlogRead at PinA0~A5 multiply by 100 divided by 1024. (adc*100)/1024 to get the percentage value. :)

      Reply
  • at
    Permalink

    why do u use 250 for monitoring ? is it standard?

    Reply
  • at
    Permalink

    It is up to you what range value to read from the sensor, in my case
    i get the range greater than > 250, so if the sensor value above 250 then print {myOutput}
    Please refer to link below further info about analogRead>

    https://www.arduino.cc/en/Reference/AnalogRead
    https://www.arduino.cc/en/Reference/AnalogReference
    https://www.arduino.cc/en/Tutorial/AnalogInputPins
    https://www.arduino.cc/en/Reference/AnalogReadResolution
    https://www.arduino.cc/en/Tutorial/AnalogInputPins

    Reply
  • at
    Permalink

    Hi, can I use external power for proximity? because I use 5V for 2 servos and ultrasonic sensor, so I think the less voltage is causing my inductive sensor value is lowest than 250, what do u think?

    Reply
    • at
      Permalink

      Yes of-course even you can wired with i2C/SPI/., Here’s how you going todo, > Sensor Ground to -5V(Gnd) / Sensor VCC to your External 5v Power Supply / Sensor Data to your Microcontroller / Microcontroller Ground to your Sensor Gound.

      Reply
  • at
    Permalink

    in this project used pnp proximity? if yes? can i use thn npn proximity? and what the source code use for npn prox?

    Reply
    • at
      Permalink

      This project uses positive logic, you can use npn for the code above. if your using PLC verify your RLL/Logic’s.

      Reply
  • at
    Permalink

    Hi,I’ve connected the output to D8 and I want to count the no. of times the sensor is triggered. How to do it?

    Reply
    • at
      Permalink

      just create a variable = count_detection and condition on every detection count 1 +++ >> see the example below.

      float metalDetected;
      int monitoring;
      int metalDetection = 1;
      int countRaw = 0;

      void setup(){
      Serial.begin(9600);
      }

      void loop(){
      monitoring = analogRead(metalDetection);
      metalDetected = (float) monitoring*100/1024.0;
      Serial.print(“14CORE METAL DETECTOR TEST”);
      delay(500);
      Serial.print(“Initializing Proximity Sensor”);
      delay(500);
      Serial.print(“Please wait…”);
      delay(1000);
      Serial.print(“Metal is Proximited = “);
      Serial.print(metalDetected);
      Serial.println(“%”);
      if (monitoring > 250)
      countRaw ++;
      Serial.println(“Metal is Detected”);
      Serial.print(“Number of Detection > “);
      Serial.println(countRaw);
      delay(1000);
      }

      Reply
  • at
    Permalink

    Does it work good with digital code on arduino instead of the analog one?

    Reply
  • at
    Permalink

    hello sir good afternoon I have used this code on my npn the problem is the Serial Monitor always gives an output of “Metal is Detected” even without making contact of metals ..

    Thank you pls reply :)

    Reply
    • at
      Permalink

      Check your pin or perhaps you need to adjust the sensitivity you can see a trimmer the back of the sensor.

      Reply
  • at
    Permalink

    Is it possible to connect this sensor on a raspberry pi 3 b+ ?
    if yes how ?

    Reply
    • at
      Permalink

      Yes! here the code..

      #!/usr/bin/env python
      import RPi.GPIO as GPIO # Import Raspberry Pi GPIO library
      import urllib2
      import datetime
      # = GPIO 4 =
      TrackingPin = 7

      def button_callback(channel):
      datetime.datetime.now().strftime(“%a, %d %B %Y %H:%M:%S”)
      print(datetime.datetime.now())
      print(“1L of water is used”)
      url = “http://homeseer-ip:port/JSON?request=runevent&group=Energy&name=Watercounter”
      f = urllib2.urlopen(url)
      print f.read()
      GPIO.setwarnings(False) # Ignore warning for now
      GPIO.setmode(GPIO.BOARD) # Use physical pin numbering
      GPIO.setup(TrackingPin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # Set pin TrackingPin to be an input pin and set initial value to be pulled low (off)
      GPIO.add_event_detect(TrackingPin,GPIO.RISING,callback=button_callback) # Setup event on pin TrackingPin rising edge
      message = input(“Script started. Press enter to quit\n\n”) # Run until someone presses enter
      GPIO.cleanup() # Clean up

      Reply
  • at
    Permalink

    Hey maan, I used 5vdc inductive proximity sensor with detection range 2mm. How about it ? What i should change ?

    Reply
  • at
    Permalink

    my inductive proximity sensor is giving me a constant reading values either detected metal or not
    I want to see two different values here to use the turn on and off an led

    Reply
  • at
    Permalink

    Hey Can you please give me the link to download the Sensor Library for the above-used Proximity sensor in Proteus Software

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *