EAZYLife STEM LAB · MODULE 21

Robotics Sensors, Navigation and Autonomy

A robot becomes autonomous when it can interpret sensor information, estimate where it is, choose an action and check the result. Explore the ideas behind obstacle-aware mobile robots, from a single distance sensor to navigation systems.

Free open lesson Localisation Navigation
SENSE · ESTIMATE · DECIDE · ACT
01 · FROM SENSING TO AUTONOMY

What does an autonomous robot actually do?

An autonomous robot repeatedly measures its environment and internal state, interprets those measurements, selects an action and observes what happened. Autonomy is not a single sensor or clever algorithm. It is a complete loop with defined limits and recovery behaviour.

The autonomy loop

Environmentworld / taskSensorsmeasurementsState estimatewhat is happening?Plan / decidewhat next?Actuatorsmotors / toolsAction changes the environment; new measurements close the loop.

A simplified sense–estimate–plan–act loop. Real systems also monitor faults, timing, confidence and communication.

Reactive behaviour

Responds directly to a current measurement, such as slowing when an obstacle is close. It can be fast and simple, but may lack memory or a wider plan.

Deliberative behaviour

Uses a representation of goals, routes or the environment to choose actions. Planning can improve task performance but needs computation and reliable information.

Hybrid behaviour

Combines a planner with fast reactive rules. For example, follow a planned route while a protective local controller stops for an unexpected obstacle.

02 · ROBOT SENSORS

Every sensor has a useful range and a blind spot

Ultrasonic ranging

Estimates distance from the travel time of an acoustic pulse and its echo. Soft, angled or narrow objects can return weak echoes; nearby objects may fall inside the minimum range.

Infrared and time-of-flight

Reflective IR sensors can detect surfaces or nearby objects. Optical time-of-flight modules estimate distance from reflected light, but sunlight, target reflectivity and field of view matter.

Encoders and IMUs

Encoders estimate wheel rotation. Gyroscopes measure angular rate and accelerometers measure specific force. Neither gives perfect position by itself.

Camera, lidar and GNSS

Cameras provide rich visual information, lidar measures ranges across directions, and GNSS can provide global position outdoors. Cost, environment, compute and update rate influence suitability.

Sensor selection is an engineering trade-off

Compare range, field of view, update rate, resolution, latency, noise, environmental sensitivity, interface, voltage levels, power consumption, mounting and cost. Read the exact module datasheet; similarly named breakout boards may have different electrical requirements.

03 · SENSOR FUSION AND CONFIDENCE

Combine evidence, not just readings

Sensor fusion combines information from multiple sources to estimate a quantity or state. A simple weighted average is useful for learning, but a real estimator must consider units, uncertainty, timing, correlation, outliers and sensor failure.

Simple weighted range estimate

Enter two measurements of the same stationary target, and assign each a relative weight. Higher weight means the reading contributes more to this simplified estimate. The weights are not automatically calibrated sensor accuracy values.

Weighted estimate43.0 cm
Difference between readings4.0 cm
Weight total4.0

Illustrative weighted average only. Check that both sensors observe the same target at nearly the same time.

Formula: estimate = (A × weight A + B × weight B) ÷ (weight A + weight B). A zero total weight is invalid.

Why naive averaging can fail

  • One sensor may be looking at a different object or surface.
  • Measurements may have different timestamps because the robot moved between readings.
  • Repeated readings may share the same systematic bias, so averaging does not remove it.
  • An implausible outlier should be flagged, not blindly blended into the estimate.
  • A failed or disconnected sensor needs an explicit degraded-mode policy.

Confidence and data validity

Store measurement timestamps and status alongside values. Check range limits, update age, sudden jumps and consistency with other sensors. If confidence is low, slow down, stop, request assistance or switch to a defined fallback behaviour.

04 · LOCALISATION AND MAPPING

Where am I, and what is around me?

Localisation estimates the robot's pose: position and orientation. Mapping represents relevant features of the environment. A robot may know its movement relative to a starting point without knowing its global location.

Pose and coordinate frames

XYRobot pose (x, y, θ)HeadingGlobal reference frame

Pose is commonly represented by x position, y position and heading angle θ in a two-dimensional mobile robot.

Dead reckoning

Integrates measured motion from a known starting pose. Wheel odometry is simple but accumulates error from slip, wheel diameter mismatch, missed counts and floor irregularities.

Landmarks and external references

Known visual markers, beacons, GNSS or mapped features can correct accumulated drift when detected reliably.

Occupancy grids

Represent space as cells with estimated occupied/free likelihood. Resolution, map size, sensor uncertainty and update rate affect usefulness.

SLAM

Simultaneous localisation and mapping estimates robot pose while building or updating a map. It is a family of methods, not one sensor or a guaranteed accurate result.

05 · PATH PLANNING AND OBSTACLE AVOIDANCE

Choose a route, then keep checking it

Path planning selects a route through a known or represented environment. Local obstacle avoidance reacts to nearby changes. A planned path is not a promise that the route remains clear.

Global route and local response

STARTGOALObstacle

Conceptual grid only. A real planner needs map coordinates, robot footprint, obstacle inflation, route costs and sensor updates.

Common planning approaches

  • Wall following: a simple local rule for constrained environments, but it can fail in open spaces or complex layouts.
  • Breadth-first search: finds a shortest path in an unweighted grid, if a valid grid map is available.
  • Dijkstra's algorithm: finds a minimum-cost route with non-negative edge costs.
  • A* search: uses a cost estimate toward the goal to guide search; performance depends on the heuristic and map.
  • Potential fields: use attractive and repulsive influences to guide motion, but can become trapped in local minima.

Stopping distance matters

A robot needs enough distance to detect, decide and stop. A simplified physical estimate is braking distance = speed² ÷ (2 × deceleration). The robot also travels during sensor and control latency. The calculator below is an ideal estimate, not a certified safety limit.

Ideal braking distance12.5 cm
Distance during latency5.0 cm
Illustrative total + margin27.5 cm

Real stopping distance varies with surface, load, battery, tyres, driver behaviour and control delays.

06 · PRACTICAL BUILD

Build an obstacle-aware rover behaviour

Extend the differential-drive rover from Module 20 with a forward-facing distance sensor. The goal is to detect a nearby object, stop, perform a controlled scan or turn, and continue only when the path appears clear. This is a learning exercise, not a collision-prevention product.

System layout

Distance sensorTRIG / ECHOMicrocontrollermeasure · decideLeft motordriver output ARight motordriver output BDual motor driverexternal motor supplyUse a common ground for this non-isolated low-voltage setup; keep motor current out of GPIO.

Parts and checks

  • Module 20 differential-drive rover, Arduino Uno-compatible controller and suitable dual H-bridge.
  • HC-SR04-compatible ultrasonic module, only if its supply and logic are compatible with the board.
  • Protected extra-low-voltage motor supply, switch and secure wiring.
  • Check sensor blind zone, beam width, update interval and echo voltage before connection.
  • Mount the sensor firmly and avoid pointing it at the floor or chassis.

Example connection map

  • TRIG → D2; ECHO → D3 on a 5 V Uno-compatible setup.
  • Motor-driver connections remain as in Module 20.
  • Sensor VCC → regulated 5 V only if the module requires and accepts it; GND → common ground.
  • Never assume a 3.3 V controller input is 5 V tolerant; use a suitable level shifter or divider for ECHO if required.
  • Do not power motors from the controller's 5 V pin.

Arduino sketch: stop and turn away

This compact example illustrates a reactive policy. It assumes the motor helper functions from your driver setup are adapted to the actual breakout and that a valid distance reading is returned in centimetres. Start with wheels lifted and verify the stop behaviour before a slow floor test.

// Arduino Uno-compatible board + TB6612FNG-style driver.
// Verify breakout pin labels, motor polarity and supply ratings first.
const byte PWMA = 5, AIN1 = 7, AIN2 = 8;
const byte PWMB = 6, BIN1 = 9, BIN2 = 10, STBY = 4;
const byte TRIG_PIN = 2, ECHO_PIN = 3;
const float STOP_DISTANCE_CM = 25.0;
const unsigned long ECHO_TIMEOUT_US = 25000UL;

float readDistanceCm() {
  digitalWrite(TRIG_PIN, LOW);
  delayMicroseconds(3);
  digitalWrite(TRIG_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG_PIN, LOW);
  unsigned long duration = pulseIn(ECHO_PIN, HIGH, ECHO_TIMEOUT_US);
  if (duration == 0) return -1.0; // no valid echo
  return duration * 0.0343f / 2.0f;
}

void setMotor(byte in1, byte in2, byte pwmPin, int command) {
  command = constrain(command, -255, 255);
  digitalWrite(in1, command >= 0 ? HIGH : LOW);
  digitalWrite(in2, command >= 0 ? LOW : HIGH);
  analogWrite(pwmPin, abs(command));
}
void stopMotors() {
  analogWrite(PWMA, 0); analogWrite(PWMB, 0);
  digitalWrite(AIN1, LOW); digitalWrite(AIN2, LOW);
  digitalWrite(BIN1, LOW); digitalWrite(BIN2, LOW);
}
void driveForward(int pwm) {
  setMotor(AIN1, AIN2, PWMA, pwm);
  setMotor(BIN1, BIN2, PWMB, pwm);
}
void turnRight(int pwm) {
  setMotor(AIN1, AIN2, PWMA, pwm);
  setMotor(BIN1, BIN2, PWMB, -pwm);
}

void setup() {
  pinMode(PWMA, OUTPUT); pinMode(AIN1, OUTPUT); pinMode(AIN2, OUTPUT);
  pinMode(PWMB, OUTPUT); pinMode(BIN1, OUTPUT); pinMode(BIN2, OUTPUT);
  pinMode(STBY, OUTPUT); digitalWrite(STBY, HIGH);
  pinMode(TRIG_PIN, OUTPUT); pinMode(ECHO_PIN, INPUT);
  stopMotors();
}

void loop() {
  float distance = readDistanceCm();
  if (distance < 0 || distance <= STOP_DISTANCE_CM) {
    stopMotors();              // stop on invalid or near reading
    delay(150);
    turnRight(90);             // short, supervised manoeuvre
    delay(300);
    stopMotors();
    delay(100);
  } else {
    driveForward(90);          // begin slowly; tune for the actual chassis
  }
}

This is a deliberately simple blocking teaching sketch. Confirm that the driver input polarity matches your motors; reverse the relevant motor command if needed. A fixed timed turn is not localisation-aware and may not clear the obstacle. A more robust controller needs non-blocking timing, repeated valid measurements, sensor plausibility checks, motor feedback, bounded retries and an explicit fault state.

Test in stages

  1. With motors disconnected, verify sensor supply, logic levels and distance readings against a ruler at several distances.
  2. Test invalid/no-echo handling and confirm the controller requests a stop.
  3. Lift the wheels, verify motor direction and that the stop command actually stops both motors.
  4. Run at low speed in a clear, bounded area with a reachable power switch and a spotter.
  5. Introduce a large soft obstacle, observe detection and stopping, then repeat at lower speed and greater separation.
  6. Record missed detections, false detections, stopping distance and repeatability. Change one variable at a time.

Extension challenges

  • Replace the timed turn with a servo-mounted sensor scan and compare left/right clearance.
  • Add encoder feedback so a turn can be measured rather than timed.
  • Use a state machine with DRIVE, STOP, SCAN, TURN and FAULT states.
  • Combine wheel odometry and IMU yaw as a learning exercise; observe drift before and after correction.
  • Represent a small test area as a grid and implement breadth-first search or A* on a computer before deploying a bounded planner.
07 · KNOWLEDGE CHECK

Check your understanding

1. What is localisation?

2. Why can averaging two sensors still give a poor estimate?

3. What should a robot do when a required range reading is invalid?

4. What does A* use to guide its search?

08 · ENGINEERING RESPONSIBILITY

Autonomy needs boundaries

  • Hobby sensors are not certified collision-avoidance, access-control or life-safety devices.
  • Test at low speed in a bounded area, with a reachable stop switch and people clear of moving parts.
  • Sensor failure, stale measurements, software lock-up and power faults must be considered explicitly.
  • Use independent protection where a software failure could cause harm; do not rely on one sensor or one code path.
  • Never use an educational rover sketch to control a road vehicle, lift, medical device or safety-critical machine.

For deeper learning, build the basic rover first, record what it does, then add one autonomy capability at a time. For project-specific design reviews, troubleshooting or guided robotics training, EazyLife offers personalised paid support.

KEEP LEARNING · GO FURTHER

Free to learn. More support when you need it.

Explore these open lessons at your own pace. For personalised explanations, project-specific troubleshooting, guided practical training or masterclasses, EazyLife offers paid support tailored to your learning goals.

Free or sponsored lesson referrals may be available through active programmes; they are not guaranteed.

Enquire about guidance