Skip to content

Force Sensor

A spring-loaded button sensor: a switch (pressed/released) and a force gauge (0-10 newtons) in one.

What it measures

ModeReading
pressedtrue / false
hard-pressedtrue / false (above roughly 5 N)
force0-10 N, resolution ~0.1 N (official continuous measuring range ~2.5-10 N)

Word Blocks

wordblocks
<force sensor [B] [pressed]>
<force sensor [B] [hard-pressed]>
(force sensor [B] pressure %)
wait until <force sensor [B] pressed>

Example 1: press to launch

A press-to-start trigger for practice - the robot waits for a tap:

wordblocks
when program starts
set movement motors [A+E]
wait until <force sensor [B] pressed>
wait until <not <force sensor [B] pressed>>     ← wait for release, so the robot doesn't launch into your hand
move [forward] for [5] rotations

Example 2: wall contact detection

Mount the sensor on the robot's tail; back up into the wall - button pressed means firmly against it:

wordblocks
start moving [backward]
wait until <force sensor [B] pressed>
stop moving
reset yaw angle [0]        ← known pose against the wall: reset the yaw reference while you're here

Python

python
import runloop, force_sensor
from hub import port

async def main():
    if force_sensor.pressed(port.B):
        pass
    f = force_sensor.force(port.B)   # decinewtons: 0-100 maps to 0-10 N

runloop.run(main())

Python returns decinewtons

force() returns 0-100 in decinewtons (1 N = 10 dN). A reading of 35 = 3.5 N.

FLL uses

  • Confirming wall squaring: more reliable than "reverse a fixed distance" - contact is proven (see the full wall-squaring recipe in FLL Techniques).
  • Debug trigger: tap to run the next test segment without touching the computer.
  • Attachment end-stop: stop the arm when it presses the target, preventing overdrive.

Common pitfalls

  • The button travel is a few millimeters; mount it so impact aligns with the button axis - glancing hits may not press it.
  • It's a contact sensor: it must physically hit. For touch-free tasks use the distance sensor.

Python API quick reference

FunctionReturnsNotes
force_sensor.pressed(port.B)boolTrue while the button is pressed at all
force_sensor.force(port.B)int, decinewtons 0-10035 = 3.5 N; continuous measuring is reliable in roughly the 2.5-10 N band

More examples

Press-to-start, in Python

Waits for a tap AND the release, so the robot doesn't launch into your hand:

python
import runloop, motor_pair, force_sensor
from hub import port

motor_pair.pair(motor_pair.PAIR_1, port.A, port.E)

async def main():
    await runloop.until(lambda: force_sensor.pressed(port.B))
    await runloop.until(lambda: not force_sensor.pressed(port.B))
    await motor_pair.move_for_degrees(motor_pair.PAIR_1, 1800, 0, velocity=500)

runloop.run(main())

Wall squaring with contact confirmation

Backs up slowly until the tail-mounted sensor presses against the wall. The 4-second timeout stops the robot from grinding forever if it misses the wall - and the yaw reference is only reset when contact is actually confirmed:

python
import runloop, motor_pair, force_sensor
from hub import port, motion_sensor

motor_pair.pair(motor_pair.PAIR_1, port.A, port.E)

async def wall_square():
    motor_pair.move(motor_pair.PAIR_1, 0, velocity=-250)              # back up slowly
    await runloop.until(lambda: force_sensor.pressed(port.B), 4000)   # contact OR 4 s timeout
    motor_pair.stop(motor_pair.PAIR_1)
    if force_sensor.pressed(port.B):
        motion_sensor.reset_yaw(0)                                    # contact confirmed: reset the yaw reference
    else:
        print("wall square timed out - yaw NOT reset")

async def main():
    await wall_square()

runloop.run(main())

Next: Hub Built-in Sensors - the gyro lives there.

© 2026 FLL Knowledge Base · All rights reserved