2016-03-25 16:47:20 -07:00
# Magnetic Force
2016-06-09 12:34:56 -07:00
Find the amount of magnetic force (the strength of a magnet) in the direction you say.
2016-03-25 16:47:20 -07:00
```sig
input.magneticForce(Dimension.X);
```
2016-06-09 12:34:56 -07:00
## ~hint
The micro:bit measures magnetic force with **microteslas** .
## ~
2016-03-25 16:47:20 -07:00
### Parameters
2016-06-09 12:34:56 -07:00
* a [string ](/reference/types/string ) that says which direction the micro:bit should measure magnetic force in: either `x` (the left-right direction), `y` (the forward/backward direction), or `z` (the up/down direction)
2016-03-25 16:47:20 -07:00
### Returns
2016-06-09 12:34:56 -07:00
* a [number ](/reference/types/number ) of microteslas that means the strength of the magnet
2016-03-25 16:47:20 -07:00
### Example: metal detector
2016-06-09 12:34:56 -07:00
This program makes the center LED of the micro:bit get brighter when
the magnetic force is stronger, and dimmer when it is weaker.
2016-03-25 16:47:20 -07:00
```blocks
led.plot(2, 2)
basic.forever(() => {
2016-06-14 14:01:00 -07:00
let f = input.magneticForce(Dimension.X)
2016-03-25 16:47:20 -07:00
led.setBrightness(f / 2000)
})
```
### See also
2016-04-18 09:47:34 -07:00
[compass heading ](/reference/input/compass-heading )