Mindstorms NXT Hack

By Kevin Packard

What You Get When You Cross a Mindstorms NXT with a Metal Detector

A few years ago, I got a Lego Mindstorms NXT along with the book Extreme NXT: Extending the Lego Mindstorms NXT to the Next Level. I first designed a gripper claw using Muscle Wire instead of motors. More recently, while surfing around the Jameco website I saw the Velleman Metal Detector Kit and I asked myself if it could be modified to be used as a sensor with the NXT. I got a couple kits to hack, but I only needed one. It ended up being easier than I thought.

My initial thought was to use the LED indicator on the metal detector to trigger the light sensor on the NXT. After assembly of the kit and re-reading several sections of the Extreme NXT book, I noticed that a direct connection to the sensor port seemed possible. Here's what I used and how I did it.

NXT-Metal Detector HackMindstorms NXT-Metal Detector Hack
Parts List:
LEGO Mindstorms NXT 2.0
Velleman Metal Detector Kit
150Ω resistor
180Ω resistor
10KΩ resistor
Extreme NXT (Chapter 7)

Step 1: Assemble the Metal Detector Kit

The first order of business is to build and test the kit as per the kit's directions. The manufacturer rates the difficulty level as 3 out of 5 and you will need to know how to solder. Considering my skill level, I thought there was sufficient room between solder joints and I was able to use a heat sink clip on the component side. (The kit comes with a push button power switch. You may want to consider replacing it with a jumper wire. This will keep the circuit active whenever the 9V battery is plugged in).

The most difficult step was winding the coils around the ferrite core. The coils are what sense the metal object. Each coil creates a magnetic field around the core. These magnetic fields interact with each other and the circuit can be adjusted to a point of equilibrium. When a piece of metal gets close enough to change how the magnetic fields interact, the circuit becomes unbalanced, and the change is amplified to power the LED.

Velleman Metal Detector K7102Velleman Metal Detector K7102

After the test and final adjustments, it should be a simple matter to put the light sensor above the LED and write a program to detect when the light is on.

The light sensor and LED work like an opto isolator. The NXT and metal detector circuit are electrically separated by the gap between the LED and light sensor.

Step 2: Modify the Metal Detector for Direct Connection to the NXT

The metal detector requires 9V @ 30mA to operate. The use of the external 9 volt battery to power the metal detector will keep it from draining power from the NXT battery.

The push button switch needs to be replaced by a toggle switch or jumper wire. I used the jumper wire and unplug the battery to turn off the detector.

original circuitOriginal Circuit
modified circuit Modified Circuit

Note from the detector circuit diagram that the 330Ω resistor (R1) is used to limit the current through transistor (T3) and LED (LD1). When the LED is off, the voltage drop across R1 should be almost zero volts and will increase as metal comes closer to the coils. The maximum voltage across R1 was measured to be 6.5V.

R1 is replaced by a voltage divider consisting of two resistors with a total value of 330Ω. 180Ω and 150Ω resistors were chosen. The voltage drop across 150Ω resistors should not exceed +5V. The 10K resistor on the lead to pin 1 of the NXT is required to scale the input voltage for the analog to digital conversion. This resistor will also help reduce the chance of over driving the NXT circuits.

Note: Make no assumptions when connecting untested homemade peripherals to your NXT. The risks to do damage to yourself or your NXT should be carefully considered before attempting any project. The following information is based on my observations and experimentations. Your results may be different.

Packard's Special Modified Circuit
Packard's Special Modified Circuit

Step 3: Test the Setup

Load the Test Program into the NXT. An explanation of the program is given in Extreme NXT (Chapter 7). Start the program and then energize the metal detector. If the voltage is 5000 mV and the LED is not on, something is wrong. If you move metal close to the coil and the LED lights but the NXT is not reading a voltage change, something is wrong. Think of it as an opportunity to practice your troubleshooting skills.

Use the "Test and final adjustments" to adjust RV1 and RV2 to achieve a voltage reading to just above zero volts. Now move a piece of metal within range of the coils and observe the voltage reading.

Test and Set Up

The LDD file contains the instructions to build a small test vehicle that will drag a trailer loaded with the metal detector around the room. When the trailer rides over metal, it stops and waits for you to reactivate the drive motors. Read the comments in the NXT-G program for an explanation. Set the millivolt detection level in for your setup.

LDD File

Mindstorms NXT Mindstorms NXT-Metal Detector Hack

Conclusion

The NXT was able to detect the voltage output change from the metal detector when metal was placed next to the coils. When pulled behind a robot, the signal was used to stop the robot but the detection area was small and sensitivity varied over the length of the coil. The chances of finding buried treasure may be slim but not impossible. For this preliminary report, little effort was made to optimize the sensitivity of the metal detector. The design of the voltage divider was given a large safety factor and could be redesigned. The connection to the NXT and program might be modified to increase sensitivity. Optimization can be investigated in the future or by anyone so inclined.

Kevin Packard is a Jameco customer whose next plans are to interface an old Bensin mini car with NXT and/or Arduino. He just wishes he could explain to his wife why this is necessary.

If you have an electronics story you'd like to share, please send it to [email protected].