Software apps and online services
Hand tools and fabrication machines
Previously we have made a few robots using Arduino and ESP boards. If you remember, it takes a lot of components along side the microcontroller itself to make a robot. There are Motor Drivers, Servo Controllers and voltage regulators. To connect all these components we need breadboard or Perf board to solder everything together. This may take a considerable amount of time and makes a mess with wires. This makes it hard for people debug the connections if something goes wrong. Moreover it demotivates beginners.
To avoid this problem, Robot Controllers are used. These are compact boards with most of the important components and Pins one will need to make a robot. There are many Robot controllers on the market but the one we are going to use here is a little different, a little special. This particular board is called "Nano Robot Controller" it is designed by me and manufactured by BPI factory.
In this tutorial we shall see what a robot controller is, what is it used for and how to get started with the Nano Robot controller. So without any further ado, let's begin.
Here is a list of all the things we will need for this tutorial.
- Arduino Nano or Bpi Nano (Amazon Link)
- Nano Robot Board. (Only available at AliExpress as of now)
- 2WD Robot chassis. (Amazon Link)
The first question one might ask is, What really is a robot controller? Well in short term, robot controller is nothing but a PCB with components you might need to build a fully functioning robot. There are different types of robot controllers ranging from $10 all the way up to $500. Most cheap ones are in the form of a shield for Arduino or Raspberry Pi. Which has Motor driver and other ICs soldered on and it just snaps on to the headers of the Arduino or Pi.
Robot controllers usually have motor drivers and PWM controllers on board along with some GPIOs where you can hook up different peripherals and sensors. Some might even have a microcontroller on board eliminating the need of Arduino.
The Robot controller we are going to learn about today is called Nano Robot Controller which is a compact board designed to work with Arduino Nano and Nano compatible boards. Lets see the board in more details.
Nano Robot Controller is a compact board consisting of all the basic components you will need along with GPIO to add sensors. Below are the hardware specifications you must know before using the board.
- L293D dual H-bridge motor driver. It can control 2 DC motors speed and direction independently.
- Analog pins: Which can be used to hook-up multiple sensors like IR, Ultrasonic, and more.
- Digital pins: Six pins, out of which four are PWM enabled (D6, D9, D10, D11).
- I2C: There are two sets of I2C pins one is 3.3V and other is 5V. These pins allow I2C communication with other devices and sensors.
- Bluetooth: HC-05 or HC-06 can be connected to add wireless control.
- Logical working voltage: 5V DC.
- Motor drive voltage: 7v-12v DC.
- Maximum driving current: 1A
- Size: 75mm x 45mm (2.9" x 1.7")
To use this board, we have to know the pin configuration, The motor driver is connected to six digital pins, two of which are PWM.
Pin Configuration for Motor Controller:
- D3 = ENA
- D5 = ENB
Where ENA controls the speed of Motor 1 and ENB controls the speed of Motor 2.
- IN1 = D2
- IN2 = D4
- IN3 = D7
- IN4 = D8
Where D2, D4 controls the direction of "Motor 1" and D7, D8 controls the direction of "Motor 2". The I2C pins are connected to A4 and A5. Where SDA is A4 and SDL is A5. All the other pins are marked on the board itself. The board also has Bluetooth connector which is connected serially to the Nano i.e TX and RX. Here TX is D1 and RX is D0.
Now that we are familiar with the Robot Control Board, we can start making our first project with it.
Now that we have a better understanding of what a Robot Controller is and the necessary pinouts, we can start building our first robot.
We will need a chassis first. I have reused the chassis from KeyBot as it is a very well built frame. For adding the Robot board I mounted a peace of hard foam board on 4 pillars and mounted the board on top with 4 standoffs.You can refer to the images above for better understanding.
Once we have a chassis ready with the board secured on top, we can start connecting the wires. Follow the instructions below:
- Connect the Left motor to "Motor 2" terminal.
- Connect the Right motor to "Motor 1" terminal.
- Connect the battery to the power terminal.
Note that the power terminal is not labeled. The screw connector closest to the mounting hole is Positive.Other way you can check the pin is by using continuity checker of a multi-meter. Just touch one lead to any GND pin on the board and connect other lead of multi-meter to each terminals of the Power block. The multi-meter will beep when the connection is completed and that is the GND or negative terminal.
Use 7V-12V battery pack to power the robot.
Finally we need to write a code and upload it to the nano which will bring our robot to life. To program the robot first make sure you have Arduino IDE installed on your computer, if now then download and install the latest version from here.
Now let's start writing the code.
int ENA = 3;
int ENB = 5;
int IN1 = 2;
int IN2 = 4;
int IN3 = 7;
int IN4 = 8;
First we declare the required variable. These will control our motor driver. ENA and ENB are PWM pins which will help use control the speed of our robot. IN pins control the direction in which motors will turn.
Setup function will be the first function to execute in a code. Here we will set the mode of each pin. First I like to include the serial functionality to debug but it is optional. All the pins are set as outputs as we are not connecting any sensor to our robot in this project.
Next we will write movement functions, this will make the code a lot easier to understand and modify.We need five movement functions in general, Forward, Backward, Left and Right.
analogWrite(ENA, 75); //PWM 0-255
analogWrite(ENB, 75); //PWM 0-255
Here also I have used the serial print to print the action on serial monitor.The ENA and ENB pins both are set to 75. Notice here I have used "analogWrite" function which will set the speed of our motor. To lower or increase the speed you can lower or increase the value anywhere between 0-255, where 0 will stop the motor and 255 will run it in full speed.
For going forward we want both the motors to move in same direction at the same speed. We set the speed to 75. Also we set the pins IN1 and IN3 to HIGH. This will make both the motors to move in same direction.
The above code is pretty similar to the last one. Here only one pin IN3 is high, this will just make 'Motor 1' run forward at the speed of 50. This will cause the robot to turn Left.
Here IN1 is high which will make 'Motor 2' run forward at speed of 50. This will cause the robot to turn Right.
This function is just opposite of the first function 'front()'. Here the pins IN2 and IN4 are High, this will make both the motors run backwards.
This function will stop both the motors, as you can notice all the pins are set as Low and the ENA, ENB pins are also set as 0. Finally we need the loop function which will carry out particular actions in a loop until the board is powered off or reset.
Here as you can see, we will just call all the functions and loop will run them one by one from top to bottom.I have also added a second of delay after every function.
With that been done, we can now upload this code onto the Microcontroller. In this case Arduino Nano using the IDE.
Now all we have to do is power up the board and watch the Robot perform the maneuvers as codded in the loop function. You can interchange the movement functions to achieve different results.
This was just a basic tutorial to introduce you to the Nano Robot Board. In future we will make different robots and explore all the other features the board offers, so make sure you follow for updates.
Also if you are interested in robotics and want to build a simple WiFi controlled robot from scratch, Do checkout my eBook "Mini WiFi Robot". It covers everything designing, building and programming a compact robot.