Back to Browse

Magnetometer Magic with Raspberry Pi Sense HAT | Compass & Metal Detector Tutorial

427 views
Jul 27, 2025
33:12

The Sense HAT magnetometer can do way more than you think, and in this Raspberry Pi tutorial I’ll show you how to use it in a fun, practical way. We’ll read real magnetometer values in microtesla (µT), turn your Sense HAT into a digital compass with the LED matrix, and even build a simple “metal detector” that reacts to magnetic fields. First, we start with the basics by grabbing the raw x, y, and z magnetometer readings using get_compass_raw, then formatting the output so it’s easy to read. Next, we put everything into a loop so you can see the magnetic field values change in real time as you move the Pi around. After that, we switch to compass heading using get_compass, then map heading ranges to directions so the LED matrix can display an arrow for north, northeast, east, and more. Finally, we calculate magnetic field strength using the square root of x² + y² + z², set a threshold, and change the LED matrix color—green when it’s “safe” and red when a stronger magnetic field is detected. You can even tune the threshold to make the detector more or less sensitive. ⭐ Like & Subscribe If this helps you, hit 👍 and subscribe 🔔 — it really supports the channel. 💸 Support & Bonus Some links below are affiliate links, which help support the channel at no extra cost to you. - Amazon: https://amzn.to/4kRpXQk - Robinhood: https://join.robinhood.com/travisb-707fa1 - Micro USB Active PoE Splitter Power Over Ethernet: https://amzn.to/3Hy50KL - Raspberry Pi 3 Model B+ Board: https://amzn.to/3Hy50KL - Raspberry Pi -Sense Hat: https://amzn.to/4kVl3ka 🌐 GitLab: https://gitlab.com/MadTcTutorials 🔑 Keywords / Hashtags raspberry pi sense hat magnetometer, sense hat magnetometer tutorial, raspberry pi digital compass, sense hat compass led matrix, raspberry pi compass project, sense hat get_compass_raw, sense hat get_compass heading, microtesla magnetometer readings, raspberry pi magnetic field sensor, diy metal detector raspberry pi, sense hat led matrix arrow compass, raspberry pi sensor projects, python sense hat tutorial, magnetometer threshold detection, raspberry pi stem project, diy electronics raspberry pi #raspberrypi #sensehat #magnetometer #raspberrypitutorial #python #iot #diyprojects #makerprojects #ledmatrix #electronics #stem #raspberrypiprojects #sensortutorial #digitalcompass #metaldetector ⏱️ Chapters 00:00 Intro 01:56 Basics 01:35 Code the Basics 03:40 Format Basic 06:37 Basic While Loop 08:21 Compass Heading 10:16 Digital Compass 20:15 Measure Magnetic Fields 31:26 Bonus 32:51 Like and Subscribe

Download

0 formats

No download links available.

Magnetometer Magic with Raspberry Pi Sense HAT | Compass & Metal Detector Tutorial | NatokHD