Imade a metal detector using Arduino for my college project. Our metal detector is detecting the metal. Our professor told us to implement a counter to count every time the metal is detected.We implemented the count. But the problem is every time our led flickers the count goes up.
I do not know how to rectify it.
Here's the code:
The operation of the circuit is as follows. A square wave, generated by Arduino pin A4, goes to the LR high-pass filter. Due to this, very short peaks (about 0.5 microseconds) are generated each time by the coil, corresponding to as many pulses. The pulse length of the peaks thus generated is proportional to the inductance of the coil. So, with the help of the peaks of these pulses, we can in principle measure the inductance of the coil, however the peaks are too short.
Inductance changes, due to the coupling of the coil with the metal being detected, changes the sizes of the pulses that are integrated in the capacitor and read by the ADC. The Arduino empties the capacitor on A5, switches pinMode, sends a number of pulses on A4, and checks the integration on A5. Pretty cool if it works.
Try searching for beginner-friendly tutorials on websites like Arduino Project Hub or YouTube. Look for well-reviewed tutorials and consider starting with a simple design before adding more advanced features so that you gain confidence. It's common to find conflicting information online, so choose a tutorial with positive feedback to increase your chances of success. Or use AI softwares for this research.
Wish you good luck for your project.
With an Arduino, 10m of wire and a 100 Ohm resistor you can build a metal detector in 10 minutes! It is based on sound physics and works for a large range of coil sizes and shapes. The sensitivity is not enough for treasure-hunting, but it can be made into a small hand-held device that is very useful indoors to check for the presence of metals. It will help you find nails inside wood or heating pipes in the wall, and to check the composition of tools and furniture. The method can also be used as a proximity sensor for metals as part of another project.
You will need a coil of at least 20 windings but it works better with 50 or more windings. The detector is sensitive to items that are larger than about one tenth of the coil diameter, so smaller coils are better. Finally, make sure that the resistance is less than 10 Ohm. Here I describe the coil I made, but anything will go, even a 10m roll of breadboard wire.
Upload the attached sketch to an Arduino Uno or Nano. Connect the coil between pin 8 and pin 10 and a 100 Ohm resistor between ground and pin 8. To get sound, connect a passive buzzer in series with a 10microfarad electrolytic capacitor between ground and pin 12. Calibration can be implemented with a dangling jumper cable on ground. Connect it to pin A0 to force a recalibration.
The challenge is that this delay is very short: the characteristic time of an RL circuit is tau=L/R, with L in Henry and R in Ohm. The inductance of the coil we use is circa 300 microHenries, so for R=100 Ohm, tau=3microseconds. We are looking for variations in the inductance of 1 in 5000, so the time needs to be measured with a precision of better than 1 nanosecond.
The Arduino has a clock speed of 16 MHz, and the input capture feature of timer1 can provide a timestamp of a pin change with the accuracy of 1 clock cycle. One such measurement is not precise enough, but by combining a large number of measurements the precision can be improved.
Simply repeating the measurement is not enough because the quantisation error is always the same: if the delay changes from say 3.03 to 3.02 microseconds, the delay is always 48 clock cycles. To overcome this, we measure the timing of the falling edge of a short pulse, and scan this pulse length between 3 and 5 times the value of the delay found originally.
The code aims to measure the inductance 100 times per second, so that the response is quick. For a pulse delay of 25 clock cycles, timer one gets set to a repetition every 215 clock cycles, so in 10ms, a full scan of 50 pulse lengths can be repeated 15 times, and the summed delay of 750 pulses provides the measurement, providing a resolution of order 10^-4 on the delay time.
Slow drifts are compensated for by incrementing or decrementing the reference value by 1 if the threshold is not exceeded. In case the reference is not good, it can be quickly zero-ed by momentarily connecting the pin A0 to ground.
To make a practical device, the detector needs to run on batteries and have a suitable housing. A large-size tic-tac box has ample space for a 9V battery, and Arduino Nano, cabling and buttons. It can be put together in an hour or two.
With the tweezers, punch holes in the lid of the tic-tac box for the leads of the on/off button, the push-button, the buzzer and the coil leads feedthrough. Apply little solder blobs on all leads. Prepare 7 pieces of stranded wire, 8cm each, strip the ends en pre-tin them.
Solder all the connections according to the provided schematic. Best is to start with the wires of the components on the lid of the box, since space is confined there. Once all is connected, the Nano and battery can be squeezed in the box.
To fix the coil, I hot-glued skewer sticks to the tic-tac box, making sure that the lid can come off to replace the battery or reprogram the Nano. Then the search coil is fixed to the skewers with ordinary scotch.
Upload the code and you are ready to go. I noticed that once soldered and powered from a battery, the stability was much better and I could change the value of the sensitivity in the code from 1000 to 5000.
There are a lot of forests in Lithuania which I like exploring on my bike. In the past a lot of Lithuanian resistance troops resided in those forests, so there is a big probability to stumble upon a stash of some kind. However that stash might as well be a grenade or a bomb of some kind, but nevertheless I always wanted to combine my motorcycle riding through the woods with treasure hunting and some time ago I decided to build a simple metal detector. Granted there are lots of metal detector designs, like BFO, VLFD, PI and so on (I'll briefly cover some of them in the theory section). Some of them I've tried in the past with various results and then during one boring evening of browsing the internet I stumbled upon this blog and decided to build this type of metal detector. The design is really simple - there is a simple oscillator circuit and a frequency counter. When the coil passes over or near various ferromagnetic or paramagnetic materials the frequency of the oscillator changes and based on this change you can decide where to dig. Moreover since the frequency counter can be implemented on any microcontroller you can analyse the frequency change in many different ways potentially enabling metal differentiation and even filter out frequency drift, that plagues other types of detectors.
Beat Frequency Oscillator is the most simple and easy to build and operate metal detector. It consists of two oscillators running at the same frequency and the main coil of one of the oscillators is exposed, i.e. being the search coil. When there is no metal object near the coil, two oscillators are tuned to be of the same frequency. The signals from these oscillators are summed together and they generally either cancel out or produce a single tone, which is filtered out. This tone is of higher frequency than the human can hear or the headphones can reproduce, so this silence is regarded as "no object". However when a metal object is introduced near the search coil, the oscillator resonance frequency changes and consequently after being mixed with the fixed frequency oscillator starts to give off non-zero frequency which can be heard. And depending on the pitch of that tone one can gauge how close or how big the metal object is. It is fair to note, that not only metal can induce said tone. Anything, that changes either capacitance or inductance of the oscillator resonant circuit will change the resulting pitch of the tone. So if one wishes to build such a metal detector must properly isolate the coil and the two oscillators from environment in such a way, that only search coil inductance would be affected.
Very Low-Frequency Detector is quite popular type of metal detectors. It consists of two electrically tuned coils, usually arranged in D shapes forming a circle. One coil acts as a transmitter, while another as a receiver. Metal object introduced in the alternating induced magnetic field changes the phase of the received signal. Depending on the received signal phase depth and roughly type of metal can be determined. Also frequency of the transmitted signal can be changed which adds another dimension to the phase response analysis.
Pulse Induction is another way to measure presence of metallic objects near search coil. The operation is as follows: transmitting coil is being pulsed with short pulses of current. That in turn induces pulsed magnetic field around the coil. Presence of any metallic objects changes the shape and dynamics of this pulsed electromagnetic field as in the previous examples, however in this case during current off stage of the pulse back-emf of the coil is being measured. Or more precisely the time it takes for the induced magnetic field to collapse.
This type of metal detection is rather complicated and involves a very interesting phenomena - magnetostriction. In simple words, when a metallic object is placed in alternating magnetic field it starts to vibrate. Conversely if a metallic object is placed inside a constant magnetic field and is being vibrated (e.g. by ultrasound) it starts to generate alternating electromagnetic field (anti-shoplifting security tags rely on the same effect). Very interesting result of magnetostriction based metal detection is ability to discriminate between different materials, as every metal produces quite a different signal.
3a8082e126