The DIY Remote Controlled Robot with an Autonomous Mode

This is my first attempt to build a remote controlled robot with an autonomous mode.

I was thinking about some Roomba-style autonomous Arduino robot for some time now. It could be used to monitor the home environment and keep my cat busy when we’re away.

Teodor The Bored Cat

This project is my first attempt in the world of Arduino robotics and the first step towards something more useful. Subscribe to the newsletter if you want to be notified about next tutorials where I’ll demonstrate upgrades and further development. It’s my first C++ project so please be lenient if you see any anti-patterns. Of course feel free to comment if you feel something could be improved.

Requirements

First, let’s focus on the requirements.

Occasionally autonomous arduino robot should be able:

  • explore area
  • move forward/backward and turn left/right during the explorations
  • avoid collisions with the obstacles
  • have an easy way to expand the case
  • use 9V battery as the power source

Remotely controlled  arduino robot’s operator should be able:

  • to use a standard TV remote
  • to turn left/right, move forward/backward with help of the remote
  • to switch autonomous mode on and off

Arduino Robot

Next, let’s see which components we will use to make robot move and feel.

Arduino Robot’s frame

For the robot’s case, I found this cool modular robot frame project and 3D printed it. I had continuous servos at home so it was a great fit. Unfortunately, this frame happened to have some drawback, like not being able to climb on carpets. The next project, I’ll choose a more versatile chassis.

All robot’s files and instructions are available here:

http://www.thingiverse.com/thing:1720394

Distance sensor

I had decided to use simple ultrasonic proximity sensor HC-SR04.

An ultrasonic sensor consists of one or more ultrasonic transmitter/s (basically speakers), a receiver, and a control circuit. The transmitters emit a high-frequency ultrasonic sound, which bounces off any nearby objects. Some of that ultrasonic sound is reflected and identified by the receiver on the sensor. That return signal is processed by the control circuit to calculate the time difference between the transmitted signal and received one. Finally, this time can be used, along with some calculations, to determine the distance between the sensor and the reflecting object.

Motors

The choice of the frame determined my choice of motors. I’ve used continuous rotation servo motors.

This servo rotates fully forward or backward instead of moving to a position. You can use any servo code, hardware or library to control these servos. Good for making simple moving robots.

An IR sensor and a remote

I bought the simple “KEYES” KY-022 IR receiver module which uses an 1838 infrared receiver.

It’s receiving angle is 90°, the distance 18 m, the operating voltage 2.7-5.5V and the operating frequency 37.9KHZ.

As a remote controller, I’ve used some random IR TV Remote. Every key on the remote sends specific code, identifying which key has been pressed. I’ve decided to use up/down, left/right buttons to control Arduino robot’s movement directions and Enter/OK button to toggle autonomous mode on and off.

Assembly

3D printing and robot assembly instruction please download here:
http://www.thingiverse.com/thing:1720394/#files

The diagram below shows how to connect sensors and motors.

The assembled robot should look like that.

Programming

The code base for an arduino robot can grow with time. Arduino robot projects tend to has a complex and tangled control structure. Our code needs to be modular, easy to modify, scale and manage.  We can achieve it using classes, inheritance and all OOP (Object Oriented Programming) goodies. We create separate drivers for every major hardware component we use. Code comments should make everything clear. The Arduino Robot’s logic should be separate from components implementation.

Note: I have extensive knowledge about high-level OOP (Java, C#), but as I mentioned before I’m not an expert in C++/C, so I’m not sure if my code is optimal. In case You feel something should be done differently just give me a hint in the comments section.

I’ve built a small library where I’ll keep all the drivers for the components used in my projects. It’s available on github.
https://github.com/robertmeisner/useful-drivers

Most up to date version of the robot’s source code is available in a GitHub repo. Just clone it and have fun.

https://github.com/robertmeisner/cat-robot

to clone this repository use –recursive flag as it uses sub-modules feature to link other repos.

You can watch a fast-forward video describing how to clone and upload code to Arduino.

Motor

To understand how The Motor Driver works see Arduino Continuous Rotation (360 degree) Servo Driver Implementation.

https://github.com/robertmeisner/useful-drivers/tree/master/motor

Distance sensor

To understand how The Distance Sensor Driver works see Arduino HC-SR04 Distance Sensor Driver Implementation.

https://github.com/robertmeisner/useful-drivers/tree/master/distance

Infrared

To understand how The Distance Sensor Driver works see Arduino Infrared (IR) Remote Driver Implementation.

https://github.com/robertmeisner/useful-drivers/tree/master/IR

The Autonomous Arduino Robot

Here sits all the Arduino robot’s logic.

 

Arduino Loop

Finally just create robot’s instance, init it and run in the loop.

 

Final result