Inductive sensor

Submitted by Bert on Wed, 06/24/2020 - 20:22

An inductive sensor uses a magnetic field to detect metallic objects. The magnetic field is created by a coil that conducts an electric current. By putting a metallic object in the magnetic field, the magnetic field is influenced which can be detected by measuring the change in induction of the coil.

Inductive sensors need metal in the object you are trying to detect otherwise the magnetic field in the coil is not influenced. So detecting glass, ceramics, plastic, wood or smilar is not possible. On the other hand, the non conductive material is not influencing the sensor which makes it usable in moist and dusty situations.

Component information

Merk : LEFIRCKO

Product Nr : LJ12A3-4-Z/BX

Specifications

  • Measures the object at a distance of 4mm +10%
  • Input voltage : 6V - 36V
  • Output type : NPN, NO
  • Connection : 3 wire

Typical application for Arduino

The sensor is connected to the connector J1. The Arduino label is connectoed to an Arduino digital input pin.

R1 is a pull up resistor making sure that the signal is pulled up to 5V when the sensor is not detecting any metallic object. When sensor detects a metallic object, the output pin is pulled to ground.

R2 is added to limit the currect running from the sensor to the Arduino.

Arduino sample code

  1. //Declare pin assignment
  2. //Induction sensor uses pin 6 as input
  3. #define INDSENSORPIN 6
  4.  
  5. void setup() {
  6. //Initialize serial port
  7. Serial.begin(9600);
  8. //Set input or output modes for the used ports.
  9. //LED_BUILTIN is a standard pin assignmet for Arduino for the LED on the board. It uses pin 13. This pin is set to output
  10. pinMode(LED_BUILTIN, OUTPUT);
  11. //The sensor pin is set to input as we need to read the value of the pin.
  12. pinMode(INDSENSORPIN, INPUT);
  13. //Let the user know setup is done through the serial port
  14. Serial.println("Setup done");
  15. }
  16.  
  17. void loop() {
  18. //Input is low = active so we need to check if the port is equal to zero.
  19. if (digitalRead(INDSENSORPIN) == 0) {
  20. //The input is low so metal is detected
  21. //Let the user know we detected it through the serial port
  22. Serial.println("detection = 1");
  23. //Swith the LED on the Arduino board on
  24. digitalWrite(LED_BUILTIN, HIGH);
  25. } else {
  26. //Let the user know no cap is detected through the serial port
  27. Serial.println("detection = 0");
  28. //Switch the LED on the Arduino board off
  29. digitalWrite(LED_BUILTIN, LOW);
  30. }
  31. }