Arduino | Maze Solving Robot (MicroMouse) \ Wall Following Robot

85,496

52

82

Introduction: Arduino | Maze Solving Robot (MicroMouse) \ Wall Following Robot

Welcome, I'm Isaac and this is my first robot "Striker v1.0".

This Robot was designed to solve a simple Maze.

In the competition we had two mazes and the robot was designed to able to identify them and solve both.

Any changes in the maze may need changes in the code or the design but it's easy to do.

Step 1: Parts

First, You need to know what are you dealing with.

Robots = Electricity + Hardware + Software

1- Electricity: batteries have many specs you should only know how much Current and Voltage you need.

2- Hardware: " Body, Motor, Motor Driver, Sensors, Wires and The Controller " you should only get the important parts that do the task, no need to get a fancy expensive controller for a simple task.


3- Software: The code is all about logic. Once you understand how the controller works it will become easy to build the functions.


Parts List:

  1. Arduino UNO
  2. 12v DC motors (x2)
  3. Wheels (x2)
  4. Motor Driver (L298N)
  5. Distance Sensor (Ultra Sonic)
  6. Wires (Jumper wires 1-pin male-male)
  7. 12v Battery (1000 mAh)

Tools List:

  1. Battery Charger
  2. Acrylic sheet
  3. Soldering Iron
  4. Wire cutter (optional)
  5. Nylon Zip Wrap

For Extra fun you can use LEDs to light it up but it's optional.

Step 2: Body Design

The main Idea was to stack the parts above the body and use the Nylon Zip Wraps to wrap them all together thanks to their lightweight.

I used CorelDRAW to design the body, check the designs above and I made extra holes in case of any future changes.

I went to a local workshop to use their laser cutter to cut the acrylic sheet, then I stacked the parts on it.
Later, I made some changes cuz the Motors were longer than I expected.

your robot doesn't have to be built the same way as mine. also the design is very flexible you can get creative.

Design PDF file and the CorelDRAW File are attached.

If you weren't able to laser cut the design, just buy the body from any store if its available.

Step 3: Implementation (building)

The design was made to fix the sensors on the body.

Step 4: Wiring

Here is a schematic diagram of the connections. connections are tied to the code and you can change the connections in the code if you want to use other pins.

Example: if you're connecting the motor driver to pin 2 but want to change it to pin 3, change the wire pin and change the code to pin 3 as well.

Sensors

Lets talk about "The Ultrasonic sensor"

An Ultrasonic sensor is simple radar that measures the distance of an object by using sound waves. It does that by sending out a sound wave and wait for it to bounce back, it records the time it took for the round trip and divides it by 2 to get the distance.

Ultrasonic Sensor connections:

  1. GND: connect this to the Ground.
  2. VCC: connect to the power source 5 voltages.(Alert! if you connect it to more than 5v it will be damaged)
  3. Echo: connect this to any pin on the Arduino. (match it to the code)
  4. TRIG: connect this to any pin on the Arduino. (match it to the code)

Remember: All grounds (sensors, Arduino, Driver) should be connected together to the battery, so make a common Ground that leads to the battery and connect all GND pins to it.

For sensors power source (Vcc), also group the 3 Sensors to a one 5v Pin, you can use the Arduino 5v pin or the Driver 5v pin, I recommend the Driver.

--------------------------------------------------------------------------------------------------

Motor Driver

The L298N H-bridge: it controls the speed and direction of two DC motors.
it can be used with motors that have a voltage of between 5 and 35V DC.

It also has an on-board 5v regulator (5v Supply), so if your battery voltage is 12v you can use the on-board 5v to supply the sensors or any other parts.

Pins map (Check the drivers picture):

  1. DC motor 1 “+” > connect this the motor #1
  2. DC motor 1 “-” > connect this the motor #1
  3. 12v jumper > keep this connected to enable the 5v regulator.
  4. Power Source > Connect your battery positive here
  5. GND > connect this the battery negative
  6. 5v output (if 12v jumper in place) > connect the sensors here
  7. DC motor 1 enable jumper > Remove the jumper and connect it to the Arduino this is used to control the speed of motor 1 (match it to the code).
  8. IN1 Direction Control > connect it to the Arduino this is used to control the direction of motor 1 (match it to the code).
  9. IN2 Direction Control > connect it to the Arduino this is used to control the direction of motor 1 (match it to the code).
  10. IN3 Direction Control > connect it to the Arduino this is used to control the direction of motor 2 (match it to the code).
  11. IN4 Direction Control > connect it to the Arduino this is used to control the direction of motor 2 (match it to the code).
  12. DC motor 2 enable jumper > Remove the jumper and connect it to the Arduino this is used to control the speed of motor 2 (match it to the code).
  13. DC motor 2 “+” > connect this the motor #2
  14. DC motor 2 “-” > connect this the motor #2

Note: This Driver allows only 1A per channel, draining more current will damage the IC. this simply means that each motor should only drain 1A Max.

------------------------------------------------------------------------------------------------------

Battery

I used 12v Battery with 1000 mAh.

The table Above shows the voltage drop when the battery discharges. just keep it in mind and recharge the battery when it drops.

To calculate how much time you have:

Discharge time is the battery capacity (Ah or mAh) divided by the current drained.

Example: for a 1000mAh battery with a load that draws 300mA you have:

1000/300 = 3.3 hours

logically if you drain more current you get less time. just make sure that you don't exceed the Battery Discharge Current Limit or it will be damaged.

Again remember to connect all grounds to a common Ground to the battery negative.

Step 5: Coding

I had fun coding this robot. so make sure to enjoy that as well.

The main goal is to get out the maze without hitting the walls.

I had 2 simple mazes so I build it to use 2 algorithms:

- The blue maze uses right wall following algorithm.

- The red maze uses left wall following algorithm.

The photo above shows the way out in both mazes.

if you want to force only one algorithm please check the following

I made a code that can solve both mazes, so to be able to know which wall to follow I made those 3 variables:

1- first_turn = false ;

2- rightWallFollow = false ;

3- leftWallFollow = false ;

so at first they are all set to false and the robot will only go forward until it finds the first turn, if the turn is right, then the robot will follow the the right wall, and it will set first_turn and rightWallFollow to true and when it can't detect any walls it will stop (assuming that it is out of the maze). If the first turn was left then it will set first_turn and leftWallFollow to true and follow the left wall.

if you want to overwrite that you can always set them true as you want, for example:

to make the robot follow the right wall:

first_turn = true ;

rightWallFollow = true ;

leftWallFollow = false ;

if you want it to follow the left wall:

first_turn = true ;

rightWallFollow = false ;

leftWallFollow = true ;

- for readsensors I found 2 methods to get sensor readings, one kinda slow but accurate and the other is fast with less accuracy, So I put both in that section but I commented out the slow ones.

That means it's there but it's not used. to use it just uncomment it and comment the other one. If you want to use it just remove the "//" and comment out the other one as shown in the photo.

I separated each function to make the code more simple (also you can find some lines that were commented out that were used for experiments). so the main flow is the code runs the main function and calls out the other functions as needed.

Code flow:

  1. defining the pins
  2. defining output and input pins
  3. check sensors' readings
  4. use sensors' reading to define walls
  5. check first route (if it was left then follow the left wall, if it's right follow the right wall)
  6. Use PID to avoid hitting the walls and to control motors' speed

You can use this code but change the pins and the constant numbers to get the best results.

Follow This Link for the code.

https://create.arduino.cc/editor/is7aq_shs/391be92...

Follow This Link for the library and the Arduino Code File.

https://github.com/Is7aQ/Maze-Solving-Robot

Step 6: Have Fun

Make sure to have fun :D

This is all for fun don't panic if it's not working or if there is any thing wrong. track the error and don't give up.

Thanks for reading and I hope it helped.


Contact:

E-mail: Is7aq.s7s@gmail.com

Arduino Contest 2017

Participated in the
Arduino Contest 2017

3 People Made This Project!

Recommendations

  • Lamps Challenge

    Lamps Challenge
  • Puzzles Challenge

    Puzzles Challenge
  • Rice & Grains Challenge

    Rice & Grains Challenge

82 Comments

0
Mohana Segaran
Mohana Segaran

Question 6 months ago on Step 4

What type of wires are you using?

0
Isaac Hossam El-Din
Isaac Hossam El-Din

Answer 4 months ago

Jumper wires 1-pin male-male

0
Fridayabraha m
Fridayabraha m

Question 4 years ago on Introduction

Mr Isaac I don't know why the code is not working properly on my car(malfunctioning). Motors are working without controls from the US sensors

0
Isaac Hossam El-Din
Isaac Hossam El-Din

Answer 1 year ago

Hi,

The code was designed for the shared maze to follow the wall .. make sure you're following the same conditions so that you can achieve the same results.

follow this link and download all files and make sure to add "NewPing" folder to the arduino library

https://github.com/Is7aQ/Maze-Solving-Robot

0
Isaac Hossam El-Din
Isaac Hossam El-Din

Answer 3 years ago

Hi,
check the connections carefully .. and make sure that the sensors are not damaged or anything .. also if you changed the connections make sure to change them in the code too .. if you didn't you might get wrong results .. also change the code algorithms if you're working with different maze ..

0
simonfans0928
simonfans0928

1 year ago

HI, I have studied your code a few week, but I still don't understand why after you using the RMS and LMS value ,then still set the direction, Could you please explain some more?

0
simonfans0928
simonfans0928

Reply 1 year ago

And what does RMS LMS control for motor?

0
Isaac Hossam El-Din
Isaac Hossam El-Din

Reply 1 year ago

They control the speed of each motor ..

RMS = Right Motor Speed
LMS = Left Motor Speed

Hope this helped

0
Isaac Hossam El-Din
Isaac Hossam El-Din

Reply 1 year ago

Hi,

set Direction is just to send signal to enable pins for the bridge to operate .. RMS and LMS are the analogue speed values .. so we need to use them to write the speed through the bridge ..

0
kavithadarshaka1
kavithadarshaka1

Question 2 years ago

What is 'first_turn = false; ' mean? Thank you.

0
Isaac Hossam El-Din
Isaac Hossam El-Din

Answer 2 years ago

it means that the robot didn't detect the first turn and will use the kickoff PID instead of wall following algorithms.

0
MüminElcin
MüminElcin

2 years ago

what is the change I need to make in my maze path width 20 cm code. thank you.

0
Isaac Hossam El-Din
Isaac Hossam El-Din

Reply 2 years ago

Hi,
If I got your question right, you'll need to change wall thresholds and try with different speeds.

0
MüminElcin
MüminElcin

Reply 2 years ago

what are the dimensions of the robot you made. let me compare

0
Isaac Hossam El-Din
Isaac Hossam El-Din

Reply 2 years ago

Hi,
as for the body itself the PDF file is ready to print which means it's the exact dimensions which is 10 cm x 15.5 cm .. however, some parts like the motors are of the body which increases the width of the robot .. also after the build I kinda broke the tail part so the length was shorter anyway it's the smallest I can get.

0
MüminElcin
MüminElcin

Reply 2 years ago

thank you

0
MohammedA741
MohammedA741

3 years ago

how How you built the pid?

0
nguyen01266
nguyen01266

3 years ago

I'm making a robot with a labyrinth measuring 120 cm x 210 cm
Wall covering is 20 cm high, the width of each wall is 30 cm, the vehicle size is 18 x 18 cm
I have seen how to connect hardware but I don't use leds, can you show me and fix the code for me?

unnamed.png
0
Isaac Hossam El-Din
Isaac Hossam El-Din

Reply 3 years ago

Hi,
Simply don't connect any leds, the code will work normally without them .. however, the wall following algorithm isn't designed for the maze you shared in the picture .. it will take longer paths and may not work perfectly for your case (check the maze I shared) and I didn't develop a code that works with the maze you shared .. you may need to check A* algorithm or other memory dependent algorithms ..