How to Build an Avoidance Robot That Includes Infrared Control

Introduction: How to Build an Avoidance Robot That Includes Infrared Control

This is a project that was assigned to me for a school project in robotics class. It is, obviously, not an original idea but will be a great exercise to anyone that is a maker or is looking to get and introduction to how robotics and coding work. Please note that all parts were provided to me for the project so you will have to source these yourself.

The tool list is quite small and not extensive.

Tool List:

A small screwdriver

Hot glue gun or super glue

Access to a 3D printer

Soldering Iron (Optional)

Drill & Bits (Optional)

Parts List:

3d printed body or body that can be used as a base for the robot.

2 Small motors capable of running on 9V power

2 wheels that are able to attach to motors preferably as a kit.

Switch of some kind to use as a main power cutoff

Arduino Nano or equivalent

L9110 or L298n motor controller

HC- Sr01 Ultrasonic sensor

9V battery tray

KY-022 or equivalent infrared sensor and remote

2 single color (non RGB) LED of your choice Large pack of jumper wires

Step 1: Inventory

It is a good idea to start by taking an inventory of all your parts and tools. Make sure that you have everything that you would need to complete the project from the beginning to end as it is no fun to get to a part and have to stop and wait on something to complete the next step.

Step 2: Grab All of Your Code and Diagrams

You're going to want to know how to put this ting together without going at it blindly right? Head over to This Github to get your motor tests, drivers, and code for your robot. The files for the 3D print are there as well.

Step 3: Start of Assembly

So you have all your tools and parts ready to go it's now time to start assembly. You need to start here as it is pretty hard to test code without components to test them on.

Your first order of business will be the wiring but it will be somewhat helpful to place a couple of components in their places to make assembly easier.

If using the stock body I would recommend hot gluing the Ultrasonic sensor in place at this point. It will make it easier to place without wires and you will be able to easily reach the pins still.

Also attaching the motors to the bottom gives them a place to be and will keep them in place when you begin to do motor tests.

A small tip would be to find a box or some sort of platform that fits between the wheels to raise them off the bench (similar to a automotive lift) so that when you start doing motor tests the motors won't run away from you.

Step 4: Wiring

There is no steadfast way to go about this. You can begin wherever you would like. I, myself, started with the signal pins running from the Arduino to the other components. If you would like you can start with the power. That may make sense to your brain. Either way you have to pay close attention to the diagrams given. I would recommend using both as I feel that each one shows certain things better than the other.

You will also have to pay attention to your powers and grounds.

You will need 9V power coming from your battery through your switch, going to your Nano and your motor controller.

You will need 5V power coming out of your Arduino 5V pin to power your Ultrasonic Sensor and your IR sensor.

Grounds are a big issue! You have something like 6 grounds to deal with. Make sure they all have a good connection! On my project I bundled the grounds from the Arduino, battery, both LED, ultrasonic sensor, and IR sensor together. I then ran a separate ground from the second ground pin on the Arduino to the motor controller as I was having issues when the ground to the motor controller was bundled to the rest of them.

You can make these connections permanent in any way you see fit. Tape, some kind of connector, solder, whatever. I used solder initially but had an issue with the small gauge wires breaking right outside of the connection so I cut out all of my solder connections and spliced them back together and secured with heat shrink tubing.

Also be sure to wire your motors "in phase" meaning that you should make the connections the same on both sides of the motor controller. If you do not they won't be turning in the proper directions.

Step 5: Testing

This is a crucial part of the assembly of the robot. You should make sure to run all of the tests in the Github to verify that you have done your wiring correctly. You will want to do this before you put your robot together because you will most likely not get it right the first time and this will keep you from having to take it apart multiple times.

You need to verify that all of your components are working correctly.

Your motors should be turning in the same direction and going correctly forward and reverse. They should also be turning left and right correctly. Confirm with Motor Test code.

Confirm that your ultrasonic sensor is working correctly confirm with Ultrasound test code.

Confirm that your infrared sensor is working correctly confirm with Remote test code.

Step 6: Main Assembly

Now that your testing is confirmed and complete you can move on to your main assembly.

The name of the game in this step is to save as much space as you can to get everything to fit into your body if you are using the stock body.

Creative twisting of the wires will help immensely in this process. Be as gentle as you can in this as you do not want to unplug any wires or break any pins off of any of the boards.

You also need to mount your Nano to your body at this point. If using the stock body the easiest way is to place it with the 6 individual pins facing down through the small square hole in the bottom of the body and then to bend those pins over thereby locking the board into place.

While not entirely necessary some hot glue on the forward facing LED will keep them in place so that they do not fall back into the body.

Depending on the motor controller you are using there might be some modifications that may need to be dope to the body to get everything to fit. If using the L9110 motor controller this is optional as I was able to get mine to fit in the body without modifying it. If using the L298 you will have to cut away pieces of the body to be able to bring the two halves together.

Once the two halves have finally been brought together slide the lower tray forward to lock it in place.

A large zip tie wrapped around the entire body will help hold it together if you don't want to glue it permanently

There is also the optional caster to be added. It is not absolutely necessary though, of you want the robot to be able to reverse on carpet then it is necessary. You have options as to how you would like to attach it. Hot glue is one option. The other option, which I used, is to drill an appropriate sized hole for the screw that you use to attach the caster to the "foot" that came off the lower body.

Step 7: Final Code

There are actually a couple of "Mistakes" that I believe were built into the code for the students of the project to figure out. Since this is an instructable it seems kind of mean to leave those in the project. To that extent I am providing the files here and here. Replace the New Ping library in your Arduino folder with this one and use the Full Robot Code file to be able to use your IR remote correctly with the Ultrasonic sensor.

To adjust how much the robot turn you need to adjust your "delays" that are in the ir remote section of the code.

Also to adjust your top speed you will need to adjust your PWM values up or down accordingly.

That's it! Hope your build goes well. If you have any questions feel free to hit me up about it.

Step 8: Timelapse!!

Here is a Time lapse of the build for you to enjoy!

Battery Powered Contest

Participated in the
Battery Powered Contest

Be the First to Share


    • Make It Bridge

      Make It Bridge
    • Big and Small Contest

      Big and Small Contest
    • Game Design: Student Design Challenge

      Game Design: Student Design Challenge