In this tutorial, you’ll learn how to build a do-it-yourself (DIY) metal detector using a proximity sensor with Arduino. Many similar projects use a coil and transistor, but it’s possible to use a proximity sensor instead of a coil. You’ll simply notice a difference in the range and power consumption.
The range of proximity sensor is, typically, much shorter than coil (think millimeters versus a few centimeters — though a coil’s range depends on its diameter). In terms of power, a proximity sensor consumes less power than a coil. After all, a greater range requires greater power.
Both sensors use a coil to detect objects (metal, plastic, ferrous, etc.). A standalone coil, however, requires manual calculations for the sensitivity, components (including capacitance, inductance, and resistance), and the achievable range. This is a time-consuming task that requires in-depth knowledge of electronics and physics.
Proximity sensors are available in three main types: inductive, capacitive, and photoelectric.
- Inductive and capacitive proximity sensors use an electric and magnetic field to detect an object. With inductive sensors, an external object increases the voltage whenever it’s within the range of the sensor’s electromagnetic field. This object must be metal, however, so it can be magnetized.
- A capacitive sensor can detect the presence or absence of virtually any object, regardless of material. Essentially, the sensor and the object act like a capacitor, storing charge, and this charge is what the sensor uses to denote the object.
- A photoelectric proximity sensor is similar to Arduino’s ultrasonic kit. Ultrasonic waves or a laser are used to detect an object based on reflection.
Now, let’s build a metal detector using a proximity sensor that can sense ferrous and non-ferrous objects by using both inductive and capacitive proximity sensors.
Circuit diagram
The inductive sensor is connected to Arduino UNO’s digital pin#8. This sensor’s output is a fixed voltage signal.
The capacitive sensor’s output is connected to Arduino UNO’s analog pin#A0. This sensor has a knob that can be rotated (using a small screw), which sets its sensitivity level.
When the sensor’s sensitivity is combined with an object of non-conductive material, it builds capacitance. The difference in the capacitance between the sensor and that of the object is reflected in the output. So, the analog pin is used to distinguish the two objects.
A small 5-volt buzzer is also required for this project. It’s connected with Arduino’s digital pin#5 using a transistor in between to limit the current flow. We used the digital pin as a pulse width modulated (PWM) pin.
As a result, the buzzer noise level now depends on the PWM’s duty cycle and frequency. This is done so as to properly distinguish the sound of the object.
Project code
First, define the inductive sensor and the buzzer pin. (The Arduino analog pins can be used without the need to define them.) In the set-up function, the inductive sensor pin should be declared as the input and the buzzer pin as the output. Arduino’s serial monitor is setup at 9600bps.
In the loop function, if the inductive sensor “finds” an object, the buzzer’s alarm will trigger with a high-pitched sound.
The capacitance value is read and, if greater than 50, the buzzer’s alarm will sound.
The “greater than 50” is just an example. From the data sheet, it’s possible to read the capacitive of the proximity sensor and an object and include it as part of the Arduino code.
The analog write function divides the capacitance value by four because the analog write function accepts values of no greater than 255. Arduino’s analog pin can read a maximum of 1023(10-bit ADC). So, the capacitance variable value never exceeds 1023 (1023/4 = 255).
A visual depiction of how to identify the object/medium by using a capacitive sensor is below. (Source: Data sheet.)
Now, let’s DIY! Where to buy the parts?
You may also like:
Filed Under: Microcontroller Projects
Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.