element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
microbit
  • Learn
  • Learning Center
  • STEM Academy
  • microbit
  • More
  • Cancel
microbit
micro:bit Blog [PROJECT] BBC Micro:bit – Metal Detector!
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join microbit to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Catwell
  • Date Created: 6 Sep 2018 2:48 AM Date Created
  • Views 6437 views
  • Likes 11 likes
  • Comments 5 comments
  • micro:bit
  • stem
  • project
  • bbc
  • micro:bit project
  • microbit projects
  • microbit
  • diy
  • beginner micro:bit projects
  • steam
  • cabeatwell
  • magnetometer
  • beginner_microbit_projects
  • compass
  • stem projects
  • sensor
Related
Recommended

[PROJECT] BBC Micro:bit – Metal Detector!

Catwell
Catwell
6 Sep 2018

The BBC Micro:bit is small, different than other boards. But this board is packed with features. One, in particular, I use in this project is the onboard compass, aka a magnetometer. I wanted to use it as a metal detector!

 

The earth has a magnetic field that the Micro:bit can detect easily. My concept was to detect disruptions to the Earth’s magnetic field around the Micro:bit.

 

The magnetometer (compass) measures the magnetic field in 3D coordinates – x, y, z. When the Micro:bit starts up, the program records the magnetic field at the initial coordinate in space. This value becomes the “zero” point. As long as the Micro:bit wasn’t laying on some ferrous metals, it should react to ferrous metals. In other words, detects metals.

 

There are some nuances, but I’ll get to that in a moment.

 

 

First, let’s gather all the necessary components you’ll need to build this project. It isn’t much:

1x BBC Micro:bit

Any sort of Power Supply with a 5V USB output

 

 

Video demonstration of the project:

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

 

 

STEP 1

Load the code onto the Micro:bit. I am providing the hex file you need to drag and drop onto the Micro:bit, and the python code as two separate files. For the below process, just use the hex file.

Plug the MicroUSB cable into the Micro:bit, and plug the other end of the cable to a PC or MAC.

 

At this point, you are going to copy over the code to the Micro:bit. I am providing the program (code) in this posts that needs to be copied over. When the Micro:bit plugs into a computer, it shows up as a USB flash drive. All you have to do is copy the file over to the Micro:bit, like it’s a USB Flash Drive, and the Micro:bit will reset, and the program is active.

 

You could leave it plugged into your computer, or use that 5V USB power adapter to make the project a bit more mobile.

 

A little bit about the code:

I commented the code enough to figure out. However, here are some interesting points.

image

So, we have four images to see here. imgs(0)...  imgs(3)

 

But the base image is a single central dot, defined here:

image

 

Here is where new data is sampled. This is the hard working part of the code:

image

 

After the magnetometer data is sampled, it is compared to the base sensitivity value and the correlating image is shown.

Here is where that choice is made:

image

 

STEP 2

Lay the Micro:bit on a table that is not magnetic, and no ferrous metals around. Lay it there with the LED side face up.

 

Power the Micro:bit. I recommend some sort of power bank and use a long USB cable. Keep the battery away from the magnetometer, in other words.

 

image

This Picture is of the Micro:bit "on" and ready to sense. (RIGHT) On the right, a piece of ferrous metal.

 

 

 

STEP 3

Once the Micro:bit is started, the LED screen should show a small dot or plus sign.

 

Now, hold the Micro:bit in the same orientation it was in when it started up. You will see the LED screen turn from a dot to a full-screen circle if there is enough metal to detect.

 

NOTE: If you tilt the Micro:bit, you change the magnetic field that the Micro:bit started out detecting. It’ll give false readings.

 

image

Picture - Now the Micro:bit is laying on top of the metal circle. The LED screen is showing a full sized circle - meaning, it has detected the metal object!

 

 

 

STEP 4

When you move the Micro:bit away, it’ll change back to a single dot or small plus.

 

However, if it doesn’t change between moving over the metal objects, move on to the next steps.

 

STEP 5 (Optional)

If you are not noticing a huge change in the “circle” image on the screen, then you may have to reset the initial magnetic field detection levels.

 

This is simple to do. Just move the Micro:bit into an area without any ferrous metals or magnets, and press any of the buttons on the board. They are labeled “a” and “b.”

 

After you reset it, the circle should be reduced to a dot, and you are now at the “zero” state. Move the Micro:bit over a ferrous metal object.

 

Conclusion

This is by far the simplest metal detector one can make.

 

Another use for this project would be for detecting strong magnetic fields. Or changes within one. It would be used in a test lab for detecting field changes.

 

 

It can also show if the room you are in is spinning around. But, I think there might be other warning signs for that one. image

Attachments:
Microbit metaldetector.zip
  • Sign in to reply

Top Comments

  • mp2100
    mp2100 over 7 years ago +2
    Very nice, simple, and useful. Just like the micro:bit itself. I'll have to try this when I get home.
  • neilk
    neilk over 7 years ago +1
    Nice neat project.
  • andrewm
    andrewm over 7 years ago +1
    A very cool project - well done. I have a small suggestion for improvement. My guess is that the device has to remain still during detection, since the earth's magnetic field vector will interact with…
  • littleben1
    littleben1 over 7 years ago

    Nice!! wouldn't have thought about using the compass abilities for metal detecting, great job!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • andrewm
    andrewm over 7 years ago

    A very cool project - well done.

    I have a small suggestion for improvement. My guess is that the device has to remain still during detection, since the earth's magnetic field vector will interact with any motion. If so, you could resolve the vector length by taking the root-sum-square of the three-axis magnetometer outputs - i.e. length = sqrt (x^2 + y^2 +z^2). That should give a signal that doesn't vary as the device is rotated and you can simply subtract the vector length of the earth's field, as you do at present for each axis.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • neilk
    neilk over 7 years ago

    Nice neat project.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • genebren
    genebren over 7 years ago

    Slick little program.  I had not thought that this would work, but I see that it does.

    Nice!

    Gene

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • mp2100
    mp2100 over 7 years ago

    Very nice, simple, and useful.  Just like the micro:bit itself.  I'll have to try this when I get home.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube