A compass sensor is a device that can detect the Earth's magnetic field and provide directional information. In robotics, compass sensors are often used for navigation, orientation, and other direction-based tasks. They are especially useful in applications where a robot needs to maintain a specific heading or find its way back to a starting point.
Compass sensors work by detecting the Earth's magnetic field and converting it into an electrical signal. This signal is then processed by a microcontroller or microprocessor, which calculates the orientation of the sensor relative to magnetic north. The most common type of compass sensor used in robotics is a digital compass, which uses a magnetometer to measure the strength and direction of the magnetic field.
The microbit is a small, programmable microcontroller designed for teaching and learning digital skills. It has a built-in compass sensor that can be used to detect the direction it is facing. The compass sensor in a microbit is a magnetometer, which measures the strength and direction of the Earth's magnetic field.
Before using the microbit's compass sensor, it needs to be calibrated. Calibration ensures that the sensor provides accurate readings by accounting for any magnetic interference or distortion. To calibrate the microbit compass, you'll need to rotate the microbit in all directions, following the on-screen instructions.
input.calibrateCompass()
To use the microbit's compass sensor in a project, you'll need to write code to read the sensor's data and perform the desired actions based on the direction it detects.
input.calibrateCompass() basic.showNumber(input.compassHeading())