Arduino RC Tamiya

Arduino RC Tamiya – Part 2

In the previous post the Tamiya RC car was built and we covered the electronic components. This gave us the knowledge required to look at replacing the factory components and control the RC car via code! Now let’s look at adding an Arduino for custom functionality.

Setting up the hardware

For this step I will be using an Arduino board to replace the receiver. This means the car will no longer have any radio transmission. Instead the servos and electronic speed controller will be controlled via code written to the Arduino board.

I’ve chosen to use the Arduino Uno WiFi Rev2 board because it has the required power and functionality. It also has the added bonus of WiFi which will be useful to enable Internet remote control of the car. Take a look at the above link for more information on the technical specification of the board.

I also bought an Arduino Proto Shield Rev3. With some soldering this will sit on top of the Arduino Uno board and allow custom ports and wiring. The servos can then be quickly plugged in or unplugged.

Arduino Uno WiFi Rev2
PROTO SHIELD REV3

The first step is to act on the above and do the custom modification to the proto shield. This involves adding two 3 pin connectors to the board over the 5V, gnd and 8, 9 digital inputs. You can see the outcome of doing that in the following photos:

Both the three pin connectors shown allow for a servo and electronic speed controller to be directly connected, powered and controlled by the Arduino.

Writing Arduino code

We are ready to write and apply some custom code to the logic. I highly recommend that you try your code with the servos not connected to RC car parts to begin with. It is far too easy to accidentally upload some code that runs a servo at full speed and your fully built RC car flies off your desk and cables rip apart, drinks go flying and screens smash etc… I warned you!!

At this point we can open up the Arduino IDE to start writing some c++ code. There’s many tutorials out there on how to use this IDE to upload code to the board and it’s straightforward. A quick Google will get you on the right track.

The first step to setup the code is to declare which digital pins the two servos are connected to. I mentioned earlier that I’ve chosen to use pins 9 and 10. If you have good eyesight you might be able to see that on the board in the photos.

Fortunately there’s an Arduino Servo class ready for us to implement: https://www.arduino.cc/en/reference/servo

#include <Servo.h>

Servo steering;
Servo throttle;

void setup()  {
    throttle.attach(9);
    steering.attach(10);
}

Our first movement

Simple, now we have two Servo variables that we can write to and control the physical Servos. The next tricky bit is figuring out the ranges of your Servo, most Servos range from 0 to 180. In the acceleration configuration there’s a neutral range around 90-100 with forward and reverse above and below those ranges respectively. The higher or lower the value from the neutral the faster your speed. In the steering servo configuration 90 is straight, 0 -> 89 is left and 91 -> 180 right. The higher this value the tighter the turn.

The below is a very simple script to demo forward movement and stopping. The car will first steer straight and then move forwards at a slow speed for two seconds before stopping for five seconds. This gives us a few seconds to grab the car before we realise our speed controller works in a different range and accelerates into the nearest wall at full speed… (you’re testing without the Servos attached to the car though, right?!).

#include <Servo.h>

Servo steering;
Servo throttle;

void setup() {
    throttle.attach(9);
    steering.attach(10);
    // Before we move the car, reset the steering
    steering.write(90);
}

void loop() {
    // Accelerate forwards at a slow speed for two seconds
    throttle.write(105);
    delay(2000);

    // Enter the neutral range for 5 seconds
    throttle.write(90);
    delay(5000);
}

If the above was a success we can try getting our car to turn around in circles by itself. The following code will repeat an automated three point turn:

#include <Servo.h>

Servo steering;
Servo throttle;

int accelerationSpeed = 89; // Slowest accelerate speed 90
int reverseSpeed = 104;     // Slowest reverse speed 102
int neutral = 91;
int brake = 180;

int noTurn = 90;
int leftTurn = 0;
int rightTurn = 180;

bool debug = true;

void setup() {
    if (debug) {
        Serial.begin(9600);
    }
    throttle.attach(9);
    steering.attach(10);
}

void Logger(String message) {
    if (debug) {
        Serial.println(message);
    }
}

void MoveBackward() {
    Logger("Move: reverse");
    throttle.write(reverseSpeed);
}

void MoveForward() {
    Logger("Move: accelerate");
    throttle.write(accelerationSpeed);
}

void Brake() {
    Logger("Move: brake");
    throttle.write(brake);
}

void Stop() {
    Logger("Move: stop");
    throttle.write(neutral);
}

void SteerLeft() {
    Logger("Steer: left");
    steering.write(leftTurn);
}

void SteerStraight() {
    Logger("Steer: staight");
    steering.write(noTurn);
}

void SteerRight() {
    Logger("Steer: right");
    steering.write(rightTurn);
}

void loop() {
    SteerLeft();
    MoveForward();
    delay(2000);
      
    Brake();
    delay(250);
    
    Stop();
    delay(2000);

    SteerRight();
    MoveBackward();
    delay(2000);
    
    Stop();
    delay(2000);
}

Summary

You should now have an RC car that does something similar to the one I made in this video:

That’s all for part two. Have a play around with the code and see what you can make the car do. There’s a couple of projects out there that have incorporated sensors at this point. They would stop the cars movement before it drove into anything. That could be quite useful functionality if you’re looking for more small additions.

I’ve created a GitHub repository for the above code samples and I’ll be adding more along the way. Check it out: https://github.com/dant89/arduino-rc-car

Stay tuned for part 3 coming in the near future. The next step will be using the WiFi on the Arduino board to allow remote control over the Internet.

Arduino RC Tamiya Car
Remote Control Arduino Tamiya

Arduino RC Tamiya – Part 1

This is my first blogged side project and it’s quite an exciting / fun one. I hope this set of posts inspires you to get involved and give it a go yourself.

What is this project?
This project is about taking a standard remote control Tamiya and replacing the electronics (in particular the receiver) with an Arduino. This then allows the introduction of custom C / C++ code so we can do anything we want with the RC car! One particular interest I have is to make the RC car remote driveable, via Wifi for example so that friends can drive around my location. Once that works there’s a future step to add a mounted phone to the car with an app that would allow friends to have a telepresence.

Why would you do this?
There’s two reasons for this, the first being that we’re currently stuck in-doors due to Coronavirus (COVID-19) and there’s nothing to do so I need something to keep my creative and constantly logic solving mind at peace. The second is that when I was 11 years old I received and built my first Tamiya, a TL01 and have missed crashing it into things. What better way to get back into that then let a robot drive into things at full speed… Okay I’ll try to avoid that but robotics and programming can create some interesting scenarios.

What’s the plan?
As of writing I’ve already dived head first into this project so firstly I need to update on my progress so far, here goes:

The first step is to get some sort of remote control car that uses electronic components that are easy to get at and modify. As I have experience with Tamiya I know exactly how these cars work and the parts included, due to the lockdown I also knew I’d enjoy the building bit so I went with the Tamiya Grasshopper. This is very much a hobbyist level entry RC car but for this projects that’s perfect, I didn’t want to spend too much and ideally I don’t actually want or need it to be fast.

I already have the radio equipment and car electronics from previously so I didn’t need to invest in more of that but this is the build list so far:

  • Tamiya Grasshopper
  • 1x Futaba T2ER controller (this has lasted 19 years at time of writing)
  • 2x NI-CD 7.2V batteries at 1800MAH and 3000MAH
  • Lots of random electronic speed controllers
    • Xtra Ripmac QUAKE
    • LRP Runner plus reverse digital
    • Tamiya TBLE-02S
  • Lots of random servos
    • Futaba
    • Hitec
  • Futaba FP-R122JE receiver with 40Mhz green crystal

The Grasshopper arrived and I spent an afternoon reminiscing how pleasurable and often extremely frustrating it is building kit RC cars. If you’ve never done this step then I highly recommend it, starting out with plastic moulds and finishing off with quite a powerful little car is very satisfying!

So that’s the first stage complete, I have a built and working remote control car that I can begin to adapt.

The car currently functions as normal with all the default parts an RC car has. To go through those quickly we have the receiver, this talks to the remote control and receives the transmission of data from the throttle and direction sticks. It sends this data to either the servo that controls the speed or the servo that controls the steering. Servos are small mechanical servomotors that contain a motor and gears, they perform movements such as rotating to push and pull steering rods. Most RC cars will have two by default, one works to steer and the second would control the speed via a manual speed controller, these have now mostly been replaced with electronic speed controllers so you’re more likely to only need a steering servo. The electronic speed controller does what it says on the tin, the receiver sends the speed related data to it and it tells the motor how fast to rotate, when to stop and when to put that car into reverse. Lastly connected to this is the battery that powers all of these components.

That’s all for step 1, we now have everything needed on the RC car side setup and working so we can begin to hack away with the electronics. In step two I will go into detail on replacing the receiver with an Arduino and how we can wire the servos into the Arduino so that we can program them to control what they do.

Part 2 is now available: https://dant.blog/arduino-rc-tamiya-part-2-33/