Mid-Senior Engineers: Reinvent your career with Robotics, earning $100k-$200k+ in the next 90 days. Learn More

Program Arduino IR Remote to Control a Mobile Robot

Liz Miller Learn Robotics

About the Author, Liz Miller, Founder/CEO @ Learn Robotics

Liz graduated with a degree in Robotics Engineering from Worcester Polytechnic Institute and researched drones at UPenn's GRASP Lab. Liz is a former Raytheon Engineer, where she managed major $MM automation projects worldwide. Today, she's the driving force behind Learn Robotics, offering the Robotics Career Blueprint for Engineering Professionals and beginner courses through the Online Robotics Class. Liz is a third-generation entrepreneur who is all about the application of innovation in robotics, automation, and AI. Follow Liz on LinkedIn and Facebook.

Disclosure: Some of the links below are affiliate links. This means that, at zero cost to you, Learn Robotics will earn an affiliate commission if you click through the link and finalize a purchase. Learn Robotics is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a way for websites to earn advertising revenues by advertising and linking to Amazon.com.

Join our Private Discord Server, MakeRobots! Sign Up

If you liked my article on Controlling an Arduino Mobile Robot using a Bluetooth Keyboard, then you’re in for a real treat! This week’s article will be focused on using an Infrared (IR) sensor to control the Arduino Robot using a TV remote.

Before we get started, let’s learn about Infrared signals and sensors, and how the robot will use them to make decisions.

All things Infrared

There are plenty of tutorials and articles out there on how IR Remote Signals work, but here’s a great overview (and short) video from Rick Osgood.

He forgot to mention robots in his video, but that’s what this tutorial is for!

Our Task

Determine what code is being sent to the IR receiver, then command the robot to move according to the signal.

Step 1 – Download and Add the IR Remote Library from Github

Rafi Khan was kind enough to write an IR Remote Library, which will simplify our development for this project. Go ahead and download a copy of his library, here.

Next, you’ll need to add the .ZIP library to Arduino using the Library Importer. Navigate to Sketch > Include Library > Add .ZIP Library and select the .ZIP folder you just downloaded.

Step 2 – Run the Test Remote Code

Part A. Open up the Example Program, IRrecvDemo.ino (File > Examples > IRremote > IRrecvDemo)

Part B. Connect the IR Sensor to Pin 11 on your Arduino (any available PWM pin is fine, just make sure you change the value of int RECV_PIN = 11; to the pin you have your sensor plugged into.)

Part C. Upload the code to your Arduino. Open up the Serial Monitor. Then press some buttons on your remote. You should see a different HEX value displayed in the serial monitor for each button you press. Here’s a visual of what it should look like. (Your HEX Values may be different). The row of F’s signifies that a different HEX code has been received.

Program Arduino IR Remote to Control a Mobile Robot
HEX values received from pressing buttons on my TV Remote

Step 3 – Map Each Button to a Control Function

We’re going to modify this IRrecvDemo code to receive and return the results.value as an unsigned long. This will make it slightly easier to compare readings rather than converting to HEX. Once we have a reading, we will then initiate the robot.go() or move command on the robot.

Can you move?

If you haven’t written the code to initiate your motors (i.e. you cannot move forward, back, left, right, or stop), then YOU MUST write that code first. If your robot uses an L298N motor controller, then feel free to use my Create Robot library. Install this library like we did for the IR Remote library and be sure to follow the README.md for wiring and programming instructions. Once you have your move code configured and working, proceed to the following steps.

The thought process. Make sure you read this paragraph!

Using either if-statements, we can check each results.value reading and then initiate the robot movement. For example, if the “Up Arrow” on my TV remote is pressed, I may want the robot to move forward. We’ll first obtain the remote value for Up Arrow, then we’ll call move forward to make the robot move in the forward direction. Then we’ll repeat this for every direction. Sound simple enough?

Step 3 – Test Out the Code

Go ahead and watch the recap video. Sometimes a picture (or video) is worth a thousand words.

From the video you’ll see that I like to print out a String that says what I’m going to do when the remote button is pressed. That way, I can test to see if the code works before putting in the motor control. If it works, it’s just a matter of writing the line of code that controls the direction of the motor. If not, I can troubleshoot to see what needs to happen.

While you don’t need to do it that way, it’s an easy way to test your program while tethered to your computer. No need to worry about the robot flying off the table!

IR Remote + Arduino Robot = Simple RC Control

As you can see, it’s not too difficult to use a TV remote to control your Arduino Robot. All you need is an IR Receiver, the IR Remote Library, and a little time to develop your movement code. Using if-statements and logic comparisons, we can click a button on our remote to command the robot in a direction.

While I provided the skeleton for using the IR remote to control the robot’s movement, I challenge you to use the other buttons to control speed, sensors, and modes. And if you do take me up on that challenge, PLEASE share your project with me on Facebook or Instagram (tag @learnrobotics)! I enjoy seeing what my readers are up to!

And that’s a wrap!

Thanks for checking out this week’s article! If you enjoyed this tutorial, and want to see more like it, please leave a comment below.

Experienced Engineer (Mechanical, Electrical, Computer, Software): If I offered to help you upgrade your engineering career to robotics, earning $100k-$200k+ in the next 90 days, would you take me up on that offer? Click here for details.
Liz Miller Learn Robotics

🚀 Pre-Launch: Become a "MakeR" with MakeRobots!

Hey Reader, 👋

Liz Miller, Founder/CEO, here with some Exciting News!

Learn Robotics just acquired MakeRobots™, an Online Robotics Community, and are prepping its Official Learn Robotics Debut in Late 2023.

MakeRobots™ is your one-stop-shop for learning, gaining coding, electronics, and robotics skills, connecting, and building robots for one low monthly membership!

Join MakeRobots™ at our Special Pre-launch Rate!
🤖 Access our Private Community & Robotics Courses
💬 Network, Collaborate, Connect with Other Makers
🔓 Only $5.99/month – locked in for life
⏱️ Pre-launch deal is Limited to the first 1,000 subscribers

This is a perfect opportunity for you to get into the fastest growing robotics community on the internet, at our ground-level, pre-launch membership rates.

👇 Click the button below to Claim your Pre-launch Membership and become a MakeR in the MakeRobots Community, today!

Learn Robotics Botly Favicon