Theory
📟⚙️ 6. Sensors: Making a compass
🌍 Earth is a giant magnet!
- 🧲 Microbit has a magnetic field sensor.
- 🧭 Build a compass program.
- 🚀 Start new project named ‘compass’.
- 🔴 Remove ‘on start’, keep ‘forever’.
- ➕ Create new variable: ‘degrees’.
- 🔴 Drag ‘set degrees to 0’ under ‘forever’.
- 🟣 Define variable using ‘compass heading’.
🧭 Degrees represent angles in a circle.
- 🌐 North: 316° to 45°
- ➡️ East: 46° to 135°
- 🌍 South: 136° to 225°
- ⬅️ West: 226° to 315°
- 🧲 Use magnetic field detector to determine direction.
- 💡 Drag ‘if-else’ command from logic menu after setting compass heading.
- 🌙 Replace ‘true’ with ‘0 < 0’ command.
- 🔄 Use ‘degrees’ less than 45 for North.
- 🖼️ Drag ‘show string’ under ‘if degrees < 45’.
- ✏️ Change string to ‘N’.
- 🧭 If degrees are between 0 and 45, display letter N for North.
- 🧭 Additional adjustments needed for North between 316 and 360 degrees.
- 🧭 Repeat process for East, South, and West directions.
🧭 Fill in bottom gap with ‘show string N’ for North.
- 📥 Download project onto Microbit and try it out.
- 🔄 Calibrate Micro: bit’s compass by tilting towards unlit LEDs.
- 🧲 Avoid magnets or metal to ensure compass accuracy.
- 🔍 Test compass functionality.
- 🔼 Optionally add commands for North East, North West, South East, and South West.