EAZYLife STEM LAB · MODULE 20

Robotics and Mechatronic Systems

A robot is more than a motorised chassis. It is a coordinated system of mechanics, electronics, sensing, actuation, power and software. Learn how these parts work together, then design and programme a small differential-drive rover.

Free open lesson Robot architecture Motion and sensing
MECHANICS · ELECTRONICS · CODE
01 · THINK IN SYSTEMS

What makes a machine a robot?

A mechatronic system combines mechanical structures, electrical/electronic hardware, sensors, actuators and embedded control. A robot uses these elements to sense its environment or internal state and perform actions. Autonomy can be simple, such as following a line, or complex, such as mapping and navigating an unfamiliar space.

Robot system architecture

Environmentline · obstacle · terrainSensorsIR · encoder · distanceControllerfirmware · decisionsDriversmotor power stageMechanical platform + actuatorschassis · wheels · motors · mechanismsPower systemPower is distributed safely; signal paths and energy paths have different jobs.

System-level view. The exact power distribution, grounding and protection depend on the chosen hardware.

Mechanical system

Chassis, brackets, wheels, gears, bearings, linkages and the physical geometry that determines what the robot can reach and how it moves.

Electrical system

Battery or supply, regulators, motor drivers, wiring, protection, connectors and the distribution of power to each subsystem.

Sensing and control

Sensors measure the world or the robot itself. Firmware interprets those measurements and commands actuators to achieve a task.

Integration

Mechanical alignment, electrical noise, software timing, heat, cable routing and maintainability can make or break an otherwise good design.

02 · ROBOT CONFIGURATIONS

Choose a mechanism for the job

Differential drive

Two independently driven wheels and a caster

Two independently driven wheels create forward motion, reverse motion and turning by changing the relative wheel speeds. Simple, compact and common in educational mobile robots.

Car-like steering

Steered wheels with vehicle-like geometry

Steered front wheels and driven wheels create a turning radius like a car. Useful for vehicle-like motion, but steering geometry and turning limits add complexity.

Tracked drive

Continuous tracks for traction and skid steering

Tracks spread load and can improve traction on some surfaces. Turning by skid steering can waste energy and place higher loads on motors and gearboxes.

Legged and articulated robots

Multiple joints and coordinated actuators

Legs, arms and linkages add degrees of freedom. They need careful mechanical design, actuator sizing, kinematics and coordinated control.

There is no universally best robot layout. Start with the task, terrain, payload, speed, accuracy, cost, energy budget and maintenance requirements.

03 · DIFFERENTIAL-DRIVE MOTION

Wheel speed determines robot motion

For a two-wheel differential-drive robot, let the left and right wheel linear velocities be (v_L) and (v_R), and let the distance between wheel contact centres be (b). The ideal centre-line velocity is their average. The yaw rate depends on their difference.

v = (vR + vL) / 2
ω = (vR − vL) / b
R = v / ω when ω is not zero

Differential-drive geometry

ForwardTrack width, bLeft wheelRight wheelRobot centreTurning geometry

Conceptual top view. Real robots experience wheel slip, caster drag, uneven floors, backlash and imperfect wheel diameters.

Try the robot kinematics calculator

Enter wheel dimensions and wheel speeds. Positive RPM means forward wheel rotation; negative RPM means reverse. This ideal model assumes both wheels roll without slipping.

Centre speed34.0 cm/s
Yaw rate0.0 °/s
Turn radiusStraight
MotionStraight ahead

Ideal rolling model. Actual speed depends on load, motor performance and traction.

04 · SENSORS, ACTUATORS AND LOCALISATION

A robot needs to know what is happening

Proximity and distance

Ultrasonic and time-of-flight sensors estimate distance to nearby objects. Their fields of view, minimum range, reflectivity sensitivity and update rates differ.

Line and light sensing

Reflective IR sensors distinguish surface reflectance. Calibration matters because floor colour, height, sunlight and sensor geometry affect readings.

Wheel encoders

Measure wheel rotation and estimate travelled distance. Encoder odometry accumulates error from slip, wheel mismatch, missed pulses and mechanical play.

IMU

Accelerometers and gyroscopes measure acceleration and angular rate. Bias, vibration and integration drift must be understood before relying on orientation estimates.

Odometry: estimating movement from wheel rotation

If a wheel has circumference C = π × D and rotates through N counted encoder counts from a documented count resolution Q, its ideal travel estimate is s = (N / Q) × C. For a differential-drive robot, the difference between left and right wheel travel also estimates heading change. These estimates drift over time and should be checked against external references when accuracy matters.

Sensor fusion is not just averaging numbers

Different sensors have different noise, bias, latency, update rates and failure modes. A robust design checks whether a reading is plausible, timestamps measurements, handles missing data and chooses a suitable estimator. Do not treat a hobby ultrasonic sensor as a certified collision-prevention or life-safety device.

05 · ROBOT CONTROL ARCHITECTURE

Separate the behaviour from the hardware details

A useful robot firmware architecture separates sensing, estimation, behaviour decisions, motion commands and low-level motor control. This makes it easier to replace a sensor or motor driver without rewriting the whole behaviour.

Layered mobile-robot software

Mission / behaviourNavigation and decision logicMotion control and estimationHardware drivers · sensors · actuatorsTaskPlanRegulateInteractWhat should it do?Which action next?How should it move?How to read / drive?

Use a state machine for behaviour

For a line-following rover, states might include STARTUP, FOLLOW_LINE, LINE_LOST, OBSTACLE_STOP and FAULT. Each state defines what sensor data is required, what motor commands are permitted, and what event causes a transition. A fault state should stop or otherwise place the robot into a hazard-appropriate safe condition.

06 · PRACTICAL BUILD

Build a three-sensor line-following rover

This practical uses a two-wheel differential-drive chassis. Three downward-facing reflective IR sensors detect the line; the controller adjusts the two motor speeds to steer. Start on a matte, high-contrast track with gentle curves.

Top-view sensor and chassis arrangement

Direction of travelLCRRear caster / support wheelDrive wheelDrive wheel

The three sensors are shown near the front of the chassis. Adjust height and spacing according to the sensor module and line width.

Parts list

  • Small two-wheel differential-drive chassis and caster.
  • Two matched extra-low-voltage DC gearmotors.
  • Dual H-bridge driver sized for motor current.
  • Arduino Uno-compatible 5 V board.
  • Three reflective IR line-sensor modules with compatible digital outputs.
  • Suitable protected battery pack and switch, plus a regulated logic supply if required.
  • Wires, fasteners and a high-contrast matte test track.

Design checks

  • Check motor voltage, startup/stall current and driver thermal ratings.
  • Secure the battery low and near the chassis centre.
  • Make both drive wheels the same effective diameter.
  • Keep sensor height and angle consistent.
  • Keep motor wiring away from sensitive sensor wiring where practical.
  • Ensure the robot can be switched off quickly and wheels can be lifted during initial tests.

Example wiring map

Controller pinConnects toPurpose
D5Driver PWMALeft motor PWM
D7 / D8Driver AIN1 / AIN2Left motor direction
D6Driver PWMBRight motor PWM
D9 / D10Driver BIN1 / BIN2Right motor direction
D4Driver STBYDriver enable
D A0 / A1 / A2Left / centre / right sensor outputsLine detection
5V / GNDSensor logic supply / common referenceOnly if sensor logic is 5 V compatible
Motor supplyDriver VM and supply groundMotor power, not GPIO

Follow the exact breakout-board pinout. Connect controller ground, driver ground, sensor ground and motor-supply negative to a common reference for this non-isolated design. Do not connect the motor supply positive to the controller 5 V rail unless the board's power design explicitly permits it.

Arduino sketch: basic three-sensor line follower

Assumption: the digital sensor outputs read LOW over the dark line and HIGH over the lighter floor. Verify this with the Serial Monitor before moving the robot. Some sensor boards use the opposite logic or adjustable comparators.

// Arduino Uno-compatible board + TB6612FNG-style dual driver
const byte PWMA = 5, AIN1 = 7, AIN2 = 8;
const byte PWMB = 6, BIN1 = 9, BIN2 = 10;
const byte STBY = 4;
const byte LEFT_SENSOR = A0;
const byte CENTRE_SENSOR = A1;
const byte RIGHT_SENSOR = A2;

const int BASE_SPEED = 105;   // start conservatively
const int TURN_ADJUST = 65;
const int MAX_PWM = 180;
const bool LINE_IS_LOW = true;

bool readLine(byte pin) {
  int value = digitalRead(pin);
  return LINE_IS_LOW ? value == LOW : value == HIGH;
}

void setMotor(byte pwm, byte in1, byte in2, int command) {
  command = constrain(command, -MAX_PWM, MAX_PWM);
  if (command >= 0) {
    digitalWrite(in1, HIGH);
    digitalWrite(in2, LOW);
    analogWrite(pwm, command);
  } else {
    digitalWrite(in1, LOW);
    digitalWrite(in2, HIGH);
    analogWrite(pwm, -command);
  }
}

void drive(int left, int right) {
  setMotor(PWMA, AIN1, AIN2, left);
  setMotor(PWMB, BIN1, BIN2, right);
}

void stopRobot() {
  analogWrite(PWMA, 0);
  analogWrite(PWMB, 0);
}

void setup() {
  pinMode(PWMA, OUTPUT); pinMode(AIN1, OUTPUT); pinMode(AIN2, OUTPUT);
  pinMode(PWMB, OUTPUT); pinMode(BIN1, OUTPUT); pinMode(BIN2, OUTPUT);
  pinMode(STBY, OUTPUT);
  pinMode(LEFT_SENSOR, INPUT);
  pinMode(CENTRE_SENSOR, INPUT);
  pinMode(RIGHT_SENSOR, INPUT);

  digitalWrite(STBY, LOW);
  Serial.begin(115200);
  // Confirm sensor polarity and motor direction before enabling movement.
  digitalWrite(STBY, HIGH);
}

void loop() {
  bool left = readLine(LEFT_SENSOR);
  bool centre = readLine(CENTRE_SENSOR);
  bool right = readLine(RIGHT_SENSOR);

  Serial.print(left); Serial.print(' ');
  Serial.print(centre); Serial.print(' ');
  Serial.println(right);

  if (centre && !left && !right) {
    drive(BASE_SPEED, BASE_SPEED);
  } else if (left && !right) {
    drive(BASE_SPEED - TURN_ADJUST, BASE_SPEED + TURN_ADJUST);
  } else if (right && !left) {
    drive(BASE_SPEED + TURN_ADJUST, BASE_SPEED - TURN_ADJUST);
  } else if (left && centre && right) {
    // Wide line or junction: proceed slowly.
    drive(BASE_SPEED / 2, BASE_SPEED / 2);
  } else if (!left && !centre && !right) {
    // Lost line: stop rather than searching blindly.
    stopRobot();
  } else {
    // Ambiguous pattern: stop and inspect the track/sensor spacing.
    stopRobot();
  }

  delay(5);
}

This is a simple teaching baseline, not a robust competition line follower. Sensor polarity, motor direction, PWM minimum, wheel mismatch and turn behaviour must be calibrated on the actual build. It stops when the line is lost instead of making an unbounded search turn. Add encoder feedback, controlled reacquisition and a non-blocking state machine as later improvements.

Build, test and tune in stages

  1. Assemble the chassis and check that wheels rotate freely without rubbing.
  2. With the wheels lifted, test each motor at low PWM. Confirm forward direction on both sides.
  3. Read each sensor over the floor and over the line. Confirm logic polarity and adjust sensor height.
  4. Place the robot on a straight track and test low speed. Verify that the centre sensor follows the line.
  5. Test gentle curves. Adjust sensor spacing, motor balance and turn correction gradually.
  6. Record which sensor patterns occur at junctions, sharp turns and line loss. Decide explicitly how each should be handled.
  7. Only after basic operation is reliable, add encoders, speed balancing, obstacle detection and non-blocking behaviour states.
07 · ENGINEERING THE WHOLE ROBOT

Design for reliability, not just movement

Power budgeting

Estimate current for motors, controller, sensors and accessories. Motor startup and stall current can dominate. Check battery discharge capability, regulator thermal limits, wiring and connector ratings.

Mechanical integrity

Check fasteners, shaft alignment, wheel concentricity, gear backlash, centre of gravity, payload mounting and cable strain relief. Loose structures create inconsistent sensor and motion behaviour.

Electrical noise

Brushed motors create switching noise. Follow driver guidance for local bypass capacitors, short current loops, grounding and separation of motor and sensor wiring. Investigate resets and false sensor readings.

Software safety

Use startup checks, bounded motor commands, timeouts, sensor plausibility checks and explicit fault handling. A communication or sensor fault should not leave the robot driving indefinitely.

Common integration problems

  • Robot curves on a straight command: compare motor speed, gearbox friction, wheel diameter, tyre grip and driver channel differences.
  • Line sensors behave inconsistently: check height, ambient light, surface finish, thresholds and sensor polarity.
  • Arduino resets when motors start: inspect supply sag, shared wiring impedance, grounding and decoupling.
  • Encoder odometry drifts: check counts-per-revolution definition, wheel calibration, missed edges, slip and track width.
  • Robot tips or struggles: reduce payload, lower the centre of gravity, improve wheel placement and verify torque and gearing.
  • Robot keeps moving after a fault: add a defined timeout and safe motor-disable path that is independent of the normal behaviour loop where needed.

Safety

  • Use extra-low-voltage, protected supplies for the learning build.
  • Secure the robot and lift the wheels for initial motor and direction tests.
  • Keep hands, hair, clothing and wires away from wheels, gears and linkages.
  • Use a quick power disconnect; do not work on wiring while powered.
  • Do not short batteries, deliberately stall motors or exceed driver/motor current and thermal ratings.
  • Do not use this hobby robot or its sensors for human transport, security, collision prevention or life-safety tasks.
08 · CHALLENGES AND KNOWLEDGE CHECK

Extend the rover

Challenge A · Calibrated motion

Use encoder counts to command a measured straight-line distance. Compare expected and actual travel, then calibrate effective wheel circumference.

Challenge B · Obstacle-aware line follower

Add a front distance sensor. Define clear states for line following, obstacle stop, obstacle cleared and sensor fault. Never assume one distance reading is always valid.

Challenge C · Speed balancing

Use left and right encoders to regulate both wheel speeds independently. Investigate how unequal motor characteristics affect straight-line travel.

Challenge D · Mapping the environment

Compare wheel odometry with IMU heading and external position references. Record drift and identify when sensor fusion or a different localisation method is justified.

1. What is the key feature of differential drive?

2. What does wheel odometry estimate?

3. Why separate behaviour logic from hardware drivers?

4. What should happen when the line sensor data becomes invalid?

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