Adafruit CLUE Metal Detector User Manual

CLUE Metal Detector in CircuitPython
Created by Kevin Walters
Last updated on 2021-02-08 06:48:17 PM EST
2 4
4
4 4 5 5
7
7 8
8
8 10 10 11
13
16
17 19 21
22
24 24 26
26 26
28
41 42 43 43 44 45
47
52
Guide Contents
Guide Contents Overview
Parts
CLUE version Circuit Playground Bluefruit with TFT Gizmo version Circuit Playground Bluefruit only version Common
Design
Inductance and Permeability Metal Detection
Beat Frequency From An Oscillator Pair RLC Filters Charging a Capacitor with RLD Continuous Charge/Discharge with RLD Two Coil Systems
CLUE Metal Detector
Microcontrollers vs Inductors
Microcontrollers vs Inductors GPIO Protection Larger Coil Currents
Circuit
Components Coil Construction Circuit Construction
CLUE board Circuit Playground Bluefruit with TFT Gizmo Circuit Playground Bluefruit board only
CircuitPython on CLUE
Set up CircuitPython Quick Start!
CircuitPython on Circuit Playground Bluefruit Install or Update CircuitPython CircuitPython
Libraries
Libraries for Metal Detector for CLUE Libraries for Metal Detector for Circuit Playground Bluefruit with TFT Gizmo
Development Testing
Metal Detector
Example Video Troubleshooting Operation Code Code Discussion
Voltage from ADC Values Using Global Variables in Python Positional Arguments Practical Issues with displayio Graphics Filters with and without ulab Library Magnetometer Baseline and Code Reviews
ADC Analysis
Voltage across Capacitor in the Metal Detector
Going Further
Ideas for Areas to Explore Related Projects Further Reading
© Adafruit Industries https://learn.adafruit.com/clue-metal-detector-circuitpython Page 2 of 54
© Adafruit Industries https://learn.adafruit.com/clue-metal-detector-circuitpython Page 3 of 54
Overview
This project creates a metal detector using an Adafruit CLUE with a few common components and an
easy-to-make coil.
The program is written in CircuitPython for version 5.1.0 or later. The code also runs on the Circuit
Playground Bluefruit (CPB) with the TFT Gizmo screen. The program can be used without a screen on the
CPB in audio/light mode only.
Alligator clips to male jumpers can be used with or without the Adafruit Dragontail to connect the CLUE
and the coil to the breadboard. The pictures feature alternate products.
This project was inspired by an old Ray Marston book featuring a metal detector project and the
Detectorists (https://adafru.it/L7d) BBC TV series.
Parts
CLUE version
1 x Adafruit CLUE
Adafruit CLUE - nRF52840 Express with Bluetooth LE
1 x Adafruit DragonTail
Adafruit DragonTail for micro:bit - Fully Assembled (or use 3 Alligator Clip to Male Jumper Wires)
1 x 1k Resistor
Through-Hole Resistors - 1.0K ohm 5% 1/4W - Pack of 25 (1 needed)
Circuit Playground Bluefruit with TFT Gizmo version
Add to Cart
Out of
Stock
Out of
Stock
© Adafruit Industries https://learn.adafruit.com/clue-metal-detector-circuitpython Page 4 of 54
1 x Circuit Playground Bluefruit (CPB)
Circuit Playground Bluefruit - Bluetooth Low Energy
1 x Circuit Playground TFT Gizmo (LCD Screen)
Circuit Playground TFT Gizmo - Bolt-on Display + Audio Amplifier
2 x STEMMA 3-Pin to Male Header Cable
STEMMA JST PH 3-Pin to Male Header Cable - 200mm
Circuit Playground Bluefruit only version
1 x Circuit Playground Bluefruit (CPB)
Circuit Playground Bluefruit - Bluetooth Low Energy
1 x 1k Resistor
Through-Hole Resistors - 1.0K ohm 5% 1/4W - Pack of 25 (1 needed)
Common
1 x USB 1m cable - A to Micro-B
USB cable - USB A to Micro-B - 3 foot long
1 x Half-size breadboard
Half-size breadboard
1 x Alligator Clip to Male Jumper Wires
Small Alligator Clip to Male Jumper Wire Bundle - 6 Pieces (2 needed for coil)
1 x Male/Male Jumper Wires
Premium Male/Male Jumper Wires - 40 x 3" (75mm)
1 x Signal Diode
1N4148 Signal Diode - 10 pack (1 needed)
1 x 0.1uF Capacitor
0.1uF ceramic capacitors - 10 pack (1 needed)
1 x 36ft (11m) Wire
Enameled Copper Magnet Wire – 11 meters / 0.1mm diameter (5-8m of most insulated wire will work fine)
Add to Cart
Add to Cart
Out of
Stock
Add to Cart
Out of
Stock
Add to Cart
Out of
Stock
Add to Cart
Add to Cart
Add to Cart
Add to Cart
Add to Cart
© Adafruit Industries https://learn.adafruit.com/clue-metal-detector-circuitpython Page 5 of 54
1 x 3 x AAA Switched Battery Holder
3 x AAA Battery Holder with On/Off Switch and 2-Pin JST (if you want to be mobile!)
1 x AAA Batteries
Pack of 3
Add to Cart
Add to Cart
© Adafruit Industries https://learn.adafruit.com/clue-metal-detector-circuitpython Page 6 of 54
Design
Inductance is a key part of many technologies in daily life, for example:
charging - electric toothbrushes, the latest smartphones and some wireless, in-ear headphones;
heating - induction cooking (https://adafru.it/L7e) with metal cookware;
communication - contactless smartcards using NFC (https://adafru.it/L7f), RFID (https://adafru.it/L7A)
tags and traditional tuning circuits for radios;
power supplies - transformers (https://adafru.it/L7B) reduce the mains AC voltage to a more practical
level;
metal detection - airport security, automatic car park exit gates, pipe/cable finders and hunting for
treasure.
Leon Theremin's The Thing (https://adafru.it/L7C) is an interesting, minimalist example of a resonant cavity
microphone, the equivalent of using an inductor for L (https://adafru.it/L7D)C (https://adafru.it/L7E) tuning,
an application of band-pass filtering (https://adafru.it/L7F).
Inductance and Permeability
A current flowing produces a magnetic field around it. Inductors are electrical components designed to
store energy in that magnetic field. These are typically coils and often wrapped around a core. The
magnetic field can be affected by:
the material it passes through, this property is referred to as magnetic
permeability; (https://adafru.it/L8a)
the presence of a conductor nearby changing the effective inductance of the coil from the induced
eddy currents (https://adafru.it/L8b) in that conductor creating their own magnetic field;
other magnetic fields.
These first two properties make the inductor useful for detecting conductive objects.
© Adafruit Industries https://learn.adafruit.com/clue-metal-detector-circuitpython Page 7 of 54
MAKE Presents: The Inductor (https://adafru.it/L8c) is an excellent video introduction to inductors by Collin
Cunningham (https://adafru.it/L8d).
Metal Detection
The effect of nearby conductors on an inductor makes them a useful component for detecting metal. A
classic implementation of this in electronics uses heterodyning (https://adafru.it/L8e) where the beat
frequency from mixing an inductor-based search oscillator with a reference oscillator is output to
headphones.
Beat Frequency From An Oscillator Pair
The schematic on the left from R.M. Marston's
20 Solid State
Projects For The Home (1969)
shows a transitor-based
detector with two colpitts oscillators (https://adafru.it/L8f). One
oscillator uses the search coil and the other a tuneable
reference coil which the users adjust to reduce the beat
frequency audio output to near 0Hz away from the target
material.
RLC Filters
Filters can easily be created with a resistor (R), an inductor (L) and a capacitor (C). There are a variety of
configurations of RLC filters (https://adafru.it/L8A) and many of them could be used to filter the square
wave output from a microcontroller which could then be sampled to check the attenuation of the filter
which would vary with the inductance.
An initial test of this approach with an Adafruit CLUE and a low-pass filter didn't yield promising results.
The plots below show theoretical plots for a band-stop (notch) filter made with a resistor and a parallel LC
circuit which might be worth exploring.
© Adafruit Industries https://learn.adafruit.com/clue-metal-detector-circuitpython Page 8 of 54
The lower resistor values might not be practical as they put a higher current demand on the GPIO port.
The annotated linear plot below is better for seeing how this attenuation could potentially be used to
detect small variations in inductance.
This would require sampling the 989Hz signal to determine the attenuation by the filter. A high
inductance is attractive here as it will lower the frequency making the determination of the attenuation
more accurate.
A frequency sweeping approach is an alternative for finding the frequency of the filter. This is likely to be
slower but it would be less ambiguous. A simple measurement approach at one frequency, say 2.741V,
© Adafruit Industries https://learn.adafruit.com/clue-metal-detector-circuitpython Page 9 of 54
corresponds to
two
frequencies and therefore two different inductance values.
Charging a Capacitor with RLD
An Arduino-based project on Instructables (https://adafru.it/L8B) uses an RL circuit (https://adafru.it/L8C)
with the output rectified with a diode which then charges a capacitor. The steps in the measurement of
the inductance are:
1. A few pulses are output through the circuit to charge the capacitor. A higher inductance will result in
a higher final voltage across the capacitor.
2. An analogue input then measures the capacitor's voltage with over-sampling aiming to improve the
accuracy.
3. The analogue input is changed momentarily to
output mode
to empty (sink (https://adafru.it/L8D)) the
charge from the capacitor.
A C++ program (sketch) on the Arduino Uno offers precise timing. This is essential for this approach to
give accurate results for the inductance.
In CircuitPython, the pulseio library (https://adafru.it/L8E) can be used for creating PWM signals and pulse
trains with microsecond precision. In general, as an interpreted language with garbage collection, it does
not offer precise timing. The unpredictable delay between step 1 and step 2 is likely to affect the final
accuracy of the measurement causing sporadic, spurious indications.
Continuous Charge/Discharge with RLD
The previous approach can be used in a continuous fashion where a constant series of pulses flow
through the RLD. A circuit diagram from the Falstad Circuit Simulator (https://adafru.it/L8F) is shown below.
This design could be considered as an RL filter with an envelope detector (https://adafru.it/L9a).
© Adafruit Industries https://learn.adafruit.com/clue-metal-detector-circuitpython Page 10 of 54
The value of the capacitor affects how quickly it discharges. A
tiny capacitance will cause a rapid discharge causing a ripple
which may reduce the accuracy or complicate the voltage
measurement. A large capacitor value will take time to charge
and discharge and this could make the sensing unresponsive.
A value of 0.1uF (which can be written as 100nF) was chosen
from experimental testing. For comparison, a simulation with
100pF (top left) shows a very undesirable 197mV of ripple
whereas 0.1uF only has ~1mV ripple.
A small amount of steady voltage drop around 1mV is actually useful here to ensure over-sampling is an
effective technique to improve the resolution. In the (unlikely) absence of noise or variation, a
theoretically
perfect
analogue to digital converter (ADC) (https://adafru.it/eYp) would output the same value repeatedly
for a constant voltage. The ADC Analysis (https://adafru.it/L9b) page takes a closer look at this.
Two Coil Systems
Modern metal detectors using the induction balanced approach use two, often partially overlapping
search coils. One is used for transmitting and one for receiving. A relatively small overlap will create a
section with increased sensitivity. These detectors can discriminate to some extent between metals by
reporting on the phase difference (https://adafru.it/L9c) between the transmitted and received signal. This
is typically presented to the user as a numerical value with different ranges giving an approximate
identification. Garrett's chart for their AT Pro metal detector is shown below.
© Adafruit Industries https://learn.adafruit.com/clue-metal-detector-circuitpython Page 11 of 54
CLUE Metal Detector
Some initial testing of the Continuous Charge/Discharge with RLD approach worked well so this was
selected for the project.
The CLUE has an onboard LIS3MDL, a triple-axis magnetometer. This is a useful addition for finding
magnets and magnetised items.
© Adafruit Industries https://learn.adafruit.com/clue-metal-detector-circuitpython Page 12 of 54
Microcontrollers vs Inductors
Microcontrollers vs Inductors
Inductors can generate high voltages which may exceed the desired levels in a circuit. The video above
shows a single-cell battery connected to an inductor (top right) in series with three white LEDs. The white
LEDs require over 9V to illuminate but a mere 1.5V battery is able to briefly illuminate them due to the
inductor's effect.
In this case the red wire is being used to briefly short across the non-conducting LEDs to allow current to
flow from the battery through the inductor. The inductor is storing energy in its magnetic field and this field
products the momentary higher voltage as the red wire is removed from the circuit. This demonstration of
voltage spikes suggests care is required when using inductors in circuits to keep voltage levels at normal
levels to avoid damaging sensitive components.
TDK (https://adafru.it/Lb1), a company founded on the invention of ferrite (https://adafru.it/Lb2), offers an
explanation of this below with a parallel version of the circuit lighting a 70V neon
lamp (https://adafru.it/Lb3) from a 4.5V battery. This is from TDK's The Wonders of Electromagnetism:
Power Inductors in Mobile Phones (https://adafru.it/Lb4).
© Adafruit Industries https://learn.adafruit.com/clue-metal-detector-circuitpython Page 13 of 54
GPIO Protection
The general-purpose input/output (GPIO) (https://adafru.it/Lb5) pins on microcontrollers typically have
some limited protection built-in for adverse voltages often to deal with static electricity
(ESD (https://adafru.it/Lb6)). The CLUE board uses an nRF52 series chip and this has two internal
diodes (https://adafru.it/Lb7) on each GPIO pin. The partial schematic below shows an example of how
these these two diodes are used for one pin.
The schematic shows the CLUE board's 1 Megaohm resistor. There's one resistor per large pad used for
the capacitive touch (https://adafru.it/Lb8) implementation. The schematic also shows an
external
resistor.
This is another precaution that's typically used to limit output current but it will also reduce any current
© Adafruit Industries https://learn.adafruit.com/clue-metal-detector-circuitpython Page 14 of 54
flowing through these
very small
, protective diodes in the microcontroller.
The metal detector circuit on the next page uses a resistor
primarily to limit the current from the P1
output
but it will also
reduce any adverse currents from under or over voltages
caused by the inductor.
The square wave (3.3V pk-pk (https://adafru.it/oDb), 84% duty
cycle (https://adafru.it/Lb9)) can be seen with and without the
inductor in the circuit here. The inductor does cause a small
negative
voltage which briefly "peaks" at -0.6V on the P1
pin/pad. The magnitude and brevity of this spike and the
current protection from the external 1k resistor mean the
microcontroller is not at risk.
Larger Coil Currents
If more current was being used through the coil then an external protection diode capable of handling this
higher current would be a wise precaution. The CLUE's nRF52840 can only supply low currents, higher
currents would need a separate power supply and switching with a transistor. This could aid isolation of
the GPIO from the maleffects of the voltage spikes.
Diodes are commonly found across motors (https://adafru.it/CkQ), relays and solonoids protecting against
back EMF (https://adafru.it/Lba) and are sometimes referred to as "flyback" diodes (https://adafru.it/Lbb).
© Adafruit Industries https://learn.adafruit.com/clue-metal-detector-circuitpython Page 15 of 54
Circuit
This page describes how the components are used on the breadboard to make the circuit for the metal
detector. It also describes how to make and connect the coil.
Components
The components in the circuit are:
R1 - 1k resistor.
D2 - 1N4148 signal diode (there is no D1).
C1 - 0.1uF (100nF) ceramic capacitor. These small capacitors are often labelled "104".
L1 - home-made coil.
The prototype was made with a 1N4004 rectifier diode and also tested with a germanium diode from a
crystal radio set, both worked well and could be used as alternatives to the 1N4148 diode.
© Adafruit Industries https://learn.adafruit.com/clue-metal-detector-circuitpython Page 16 of 54
Coil Construction
A coil with about 4-8m (13-26ft) is a good starting point to avoid using too much wire. Insulated wire will
work but "enamelled" copper wire (https://adafru.it/Lbc) allows a more compact coil. The enamel is a
misnomer, the coating will be something like polyurethane varnish. This insulation must be
scraped
or
burnt off
with a soldering iron at the ends to expose the copper to connect it to the circuit.
The coil shown at the top of the page is enamelled 0.56mm wire wrapped around an 84mm tube (3.3in). It
has 12 coils then 9 more coils over those then 7 coil more coils over those totalling 28. Placing the coils
close to the edge improves the effective search range but care needs to be taken to ensure the coil does
not fall off! A tiny ridge has been made on end of the tube with masking tape to reduce that risk.
The coil either needs to be very tight or held in place as movement of the wire in the coil will subtly affect
the inductance and parasitic capacitance (https://adafru.it/Lbd) of the coil.
A prototype coil was also made (not shown) with 20 turns around a core of a roll of masking tape with
diameter 116mm (4.6in). This worked well too.
Circuit Construction
The diagrams and pictures below show how the circuit can be implemented on a breadboard for the three
different configurations.
CLUE board
© Adafruit Industries https://learn.adafruit.com/clue-metal-detector-circuitpython Page 17 of 54
Loading...
+ 37 hidden pages