In the last article, we completed the body of the RC car. But, during the building process, we had some issues. Today, we will continue working on the RC car controller. As the Arduino UNO was too large to mount on the car, we will use an Arduino Pro Mini instead.
We will start by making the controller for the RC car.
Last time, we could rotate the car’s wheels left and right and go forward and backward. So, we will build the controller to control these movements. About the program on the Arduino side, we will translate the analog values input via the controller parts into movement.
Today, we will use a tact switch and a joystick as the controller parts.
Picture 1 Tact Switch
As you can tell from its name, a tact switch is a type of switch. It makes a clicking sound when you press it, and returns to its original position when you lift your finger. This type of switch is used when we want it to be ON only when it’s being pressed.
Picture 2 Joystick
The joystick is a well-known part as it’s used to play video games. the joystick is a part consisting of two potentiometers, arranged along the horizontal and vertical axes. When the stick is moved, the potentiometers activate and the resistance changes. On the Arduino, we can determine the state of the joystick based on this change in resistance.
Picture 3 The controller will look something like this
Picture 4 Controller
The tact switches will be used for the forward and the backward movement. The joystick will be used for steering left and right. The joystick can be moved along both X and Y axis. Since we are only using it for steering this time, we will only using it on the X axis.
The circuit will look like the following.
Figure 1 Circuit for the controller
To verify the input from the switches and the joystick, we will run a sample program.
// Controller Sample Program
The joystick will provide analog input values between 0–1023. For a joystick, the initial value is when the stick is centered along the horizontal dimension (X axis). With our current circuit, the value 512 will be displayed when the joystick is at rest.
For the tact switch, the circuit is complete only when it is pressed, at which point the contents of the if statements are evaluated.
Once we’ve confirmed that the controller is functional, we’ll integrate it with the RC car itself. The circuit will look like the following figure.
Figure 2 RC car circuit
It’s getting a bit complex and a little confusing at first glance. But it’s built upon components we’re familiar with. So, we only need to be careful about incorrectly connecting the jump wires.
Picture 5 The basic setup is complete
The final program will be as follows.
#include <Servo.h> // Load servo motor library
Servo myservo;// Create an object for the servo
intval;// Variable to store servo angle
myservo.attach(11);// Set digital pin 11 as output pin for servo angle commands
intst=analogRead(A2);// 0-1023, center is 512
myservo.write(val);//Move servo based on joystick value
We’ve got to the point where we have the basic functionality of our RC car.
However, it is inconvenient in its current form because the Arduino is too big.
Now, I’d now like to implement several ideas to make the RC car smaller and neater.
Miniaturization with the Arduino Pro Mini
Until now, we have been using Arduino UNO. But it’s too big for the RC car. Hence, today we will work on the miniaturization by using an Arduino Pro Mini.
As I mentioned in the first article, there are different types of Arduino. Today we’ll try out the Arduino Pro mini, which is among the smaller types of Arduino. One word about these compatible boards. As the program to write on the Arduino chips is publicly available, anyone can create his own Arduino by using few components and using a supported chip (such as AVR microcontrollers). Thanks to this, many Arduino boards, compatible with the official versions, are sold. If a board is out of stock, you might want to check something different from the official version. And you can also find something cheaper. It might be worth searching for compatible boards.
Picture 6 Comparison between Arduino UNO (top) and Arduino Pro Mini (bottom)
The major differences between the Arduino UNO and the Arduino Pro mini are the following.
Dramatically smaller size
Available in 3.3v and 5v operating voltage versions (We’re using the 5v version)
The Arduino UNO connects via USB, the Arduino Pro mini connects via serial port
Has analog pins 6,7 (absent on the Arduino UNO)
One of the important point is that the Arduino Pro Mini comes in two operating voltage versions.For example, when using a servo that operates at 5v, we can operate it with the 5v Arduino without any external voltage. But, with a 3.3v Arduino, the voltage is insufficient and it won’t run! When using the Arduino Pro mini, we must choose between the 5v or 3.3v version depending on the use case.
It operates in the same way as the Arduino UNO. Only some settings are different, as shown in the following figure.
Figure 3 In “Tools” → “Board”, select the Arduino Pro Mini
Figure 4 In “Tools”→ “Serial Port”, select serial cable via USB
Once configured, it can be used just like the Arduino UNO. So, we’ll test it out with the LED blinking.
Picture 7 LED blinking with the Arduino Pro mini
Once the LED blinking is successful, we’ll transfer the RC car circuit that we made on the Arduino UNO to the Arduino Pro mini.
By “transfer”, we only need to reconnect the jump wires according to the pin numbers, so this work is quickly done.
Picture 8 We finished the transfer from the Arduino UNO to the Arduino Pro mini
Picture 9 Mounting on top of the body
The RC car is now complete!
There are some other ways to make it even lighter and more compact. We can find infinite possibilities, such as replacing the LEGO car body with other parts. Or we could solder the components on the breadboard to a circuit board. As I want to build and RC car using different sensors’ features, I’ll introduce you various type of sensors next time.