This is an old revision of the document!


Maze Solver Robot

Author Berescu Silvia-Maria
Series and Group 332CD
GitHub Maze Solver Robot

Introduction

This project involves building a small autonomous robot capable of navigating and escaping a maze with opaque walls, using ultrasonic sensors and a wall-follower algorithm.

  • What it does: The robot detects walls in front and to the left using HC-SR04 ultrasonic sensors, makes real-time navigation decisions, and displays the measured distances and current decision on an LCD screen (FORWARD / TURN LEFT / TURN RIGHT).
  • Purpose: Autonomous maze solving without human intervention, using an ATmega328P microcontroller.
  • Starting idea: Demonstrating the use of microcontroller peripherals (PWM, I2C, UART, Interrupts) in a fully functional and autonomous physical product.

Hypothesis: I believe that using the Left-Hand Wall Follower algorithm with HC-SR04 ultrasonic sensors and real-time visual feedback through an LCD will allow the robot to solve a simple maze in under 60 seconds, as the algorithm guarantees finding the exit in any simply connected maze.

General Description

The block diagram below shows all project modules and how they interact:

Block Diagram

Main modules and their roles:

  • ATmega328P-XMINI — main microcontroller; coordinates all sensors and actuators via GPIO, PWM, I2C and external interrupts
  • HC-SR04 (front) — measures distance to the front wall; ECHO pulse is captured precisely via the INT1 external interrupt
  • HC-SR04 (left) — measures distance to the left wall via GPIO polling
  • L298N — dual H-bridge motor driver; receives PWM + GPIO commands from the ATmega and drives the two DC motors
  • LCD 16×2 I2C — displays measured distances and the current robot decision in real time
  • 2WD chassis kit — mechanical platform with 2 DC gear motors, wheels and a caster wheel
  • 2x 18650 batteries (7.4V) — autonomous power supply; L298N provides regulated 5V to the ATmega, sensors and LCD

Hardware Design

Bill of Materials

No. Component Qty Role
1 2WD chassis kit (line follower) 1 Mechanical platform
2 ATmega328P-XMINI 1 Main microcontroller
3 L298N motor driver module 1 DC motor control via PWM
4 HC-SR04 ultrasonic sensor 2 Obstacle detection
5 LCD 16×2 with I2C module (PCF8574) 1 Robot status display
6 18650 Li-ion battery 2500mAh 2 Autonomous 7.4V power
7 Dual 18650 charger 1 Battery recharging
8 2×18650 battery holder + switch 1 Battery mount + ON/OFF
9 Male-female dupont wires 40 Component connections
10 400-point breadboard 1 Connection prototyping

Pin Mapping — Arduino Labels vs ATmega328P Physical Pins

The ATmega328P-XMINI board uses Arduino-style pin labels (D2, D3, A4 etc.) which correspond to the internal ATmega328P port/pin names. The table below clarifies this mapping for all pins used in this project:

Arduino Label ATmega Port/Pin Physical Pin (DIP) Used For
D2 PD2 4 HC-SR04 Front — TRIG
D3 PD3 (INT1) 5 HC-SR04 Front — ECHO
D4 PD4 6 HC-SR04 Left — TRIG
D5 PD5 (OC0B) 11 L298N ENB — PWM Motor Right
D6 PD6 (OC0A) 12 L298N ENA — PWM Motor Left
D8 PB0 14 L298N IN1
D9 PB1 15 L298N IN2
D10 PB2 16 L298N IN3
D11 PB3 17 L298N IN4
D12 PB4 18 HC-SR04 Left — ECHO
A4 PC4 (SDA) 27 LCD I2C — SDA
A5 PC5 (SCL) 28 LCD I2C — SCL
VCC (pin 7) VCC 7 5V power input
VCC (pin 20) VCC 20 5V power input
GND (pin 8) GND 8 Ground
GND (pin 22) GND 22 Ground

D3 (PD3/INT1): connected to the INT1 external interrupt line, used for precise ECHO pulse measurement on the front sensor. Interrupt-driven measurement is more accurate than polling because the ATmega reacts instantly to the signal edge without busy-waiting.

D5 (PD5/OC0B) and D6 (PD6/OC0A): both are hardware PWM outputs of Timer0 (Channel B and Channel A respectively). Using both channels allows independent speed control of each motor, which is essential for straight-line driving — real DC motors are never perfectly identical and require small speed corrections.

D12 (PB4): plain GPIO pin used for HC-SR04 Left ECHO via polling. D12 has no special hardware function requirements since the left sensor uses software polling.

Electrical Schematic

Electrical Schematic

The schematic uses net labels instead of long wires for clarity. Two pins sharing the same net label name are electrically connected.

Schematic Explanation

Power Supply

  1. The 2×18650 batteries (7.4V in series) connect through the ON/OFF switch on the battery holder to the +12V pin of the L298N (labelled VMS on the physical module)
  2. The L298N drives the two DC motors directly at 7.4V through OUT1/OUT2 (Motor A) and OUT3/OUT4 (Motor B)
  3. The L298N has an onboard 5V regulator. Its +5V output is connected to the VCC rail, powering the ATmega328P, both HC-SR04 sensors and the LCD
  4. All GND pins across all components share a common ground

Motor Control

The L298N receives direction signals on IN1–IN4 from ATmega pins D8–D11:

IN1 IN2 Motor Left behavior
HIGH LOW Forward
LOW HIGH Reverse
LOW LOW Stop

The same logic applies to IN3/IN4 for Motor Right.

Speed is controlled via PWM on both ENA (D6/OC0A) and ENB (D5/OC0B) using Timer0 Fast PWM mode.This allows independent speed adjustment for each motor to compensate for mechanical differences.

HC-SR04 Front Sensor

  • TRIG - D2 (PD2): ATmega sends a 10µs HIGH pulse to start a measurement
  • ECHO - D3 (PD3/INT1): the sensor returns a HIGH pulse proportional to distance
  • INT1 triggers on both rising and falling edges — firmware records the Timer1 value at each edge to compute pulse duration
  • Distance (cm) = pulse duration (µs) / 58

HC-SR04 Left Sensor

  • TRIG - D4 (PD4)
  • ECHO - D12 (PB4): GPIO polling — firmware busy-waits for the pulse to end
  • D12 was chosen instead of D5 because D5 (OC0B) is needed for ENB PWM control
  • Polling is acceptable here since the left wall changes less frequently than the front wall

LCD 16x2 I2C

  • SDA - A4 (PC4): I2C serial data
  • SCL - A5 (PC5): I2C serial clock
  • The onboard PCF8574 expander converts I2C to the parallel HD44780 interface internally
  • I2C address: 0x27 (PCF8574 default)
  • Only 2 signal wires needed instead of 16 for parallel mode

Power Supply Summary

  1. 2×18650 batteries (7.4V) → ON/OFF switch → L298N +12V (VMS)
  2. L298N → motors at 7.4V
  3. L298N 5V OUT → ATmega328P + HC-SR04 x2 + LCD I2C

Hardware Progress

Assembled Robot

The image shows the fully wired robot with all components mounted and powered via the 2×18650 battery pack (7.4V).

Component Identification

  • ATmega328P-XMINI — powered via the 5V regulated output of the L298N module. The onboard amber LED is lit, confirming the board is receiving stable 5V power from the battery pack through the L298N regulator. GND from the ATmega is connected to the breadboard ground rail to establish a common ground reference for all components.
  • L298N motor driver — all 4 red indicator LEDs are on, confirming the module is powered and IN1–IN4 lines are in a defined logic state. The 5V regulated output feeds the breadboard power rail which distributes power to all logic components.
  • LCD 16×2 I2C — the blue backlight is on, confirming the LCD module is receiving stable 5V power from the battery pack via the L298N regulated output. No characters are displayed yet as the firmware has not been uploaded at this stage. I2C communication will be verified once the ATmega is programmed.
  • HC-SR04 ultrasonic sensors — both front and left sensors are mounted and connected to ATmega via the breadboard.
  • Breadboard — distributes the 5V and GND rails from the L298N to all logic components. The red (+) rail carries 5V and the blue (-) rail carries GND, with the ATmega GND also connected to the same rail for common ground.
  • Battery holder 2×18650 — mounted on the chassis.

What the Indicators Confirm

  • L298N red LEDs on — motor driver is powered and input pins IN1–IN4 are in a defined state, confirming correct power wiring.
  • LCD backlight on — the 5V regulated output of the L298N is confirmed working, supplying stable power to the LCD module via the breadboard power rail.
  • ATmega amber LED on — microcontroller is powered and operational.
  • Common GND established — ATmega GND pin is connected to the breadboard ground rail shared with L298N, sensors and LCD, ensuring all components share the same voltage reference.

Software Design

Lab Concepts Used

Lab concept Usage in project
GPIO TRIG/ECHO sensor pins, motor direction pins IN1–IN4
PWM Timer0 Fast PWM on OC0A (D6) and OC0B (D5) — both motors
I2C TWI communication with LCD 16×2 via PCF8574 on A4/A5
UART Debug data transmission at 9600 baud via TX (D1)
Interrupts INT1 on D3 (PD3) for precise front ECHO pulse measurement

The robot uses the Left-Hand Wall Follower algorithm:

  1. If left is free (distance > 20cm): turn left 90° + move forward
  2. Else if front is free (distance > 20cm): move forward
  3. Else: turn right 90°

Results

Conclusions

Download

Journal

Week Activity Status
Week 1 Component selection, ordering parts Done
Week 2 Chassis assembly, mounting motors and wheels Done
Week 3 L298N wiring + electrical schematic Done
Week 4 HC-SR04 integration + distance measurement test Planned
Week 5 LCD I2C integration + data display Planned
Week 6 Navigation algorithm implementation + maze test Planned
Week 7 90° turn calibration, code optimization, final demo Planned

Bibliography / Resources

Hardware Resources

pm/prj2026/jan.vaduva/silvia.berescu.1779111777.txt.gz · Last modified: 2026/05/18 16:42 by silvia.berescu
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0