Introduction: Wireless Arduino Controlled Tank (nRF24L01)

Hi!

Today I'll be showing you how to build an Arduino controlled tank and remote. The 3d printed parts of the tank (with the exception of the controller, track guide and tank cover) were designed by timmiclark and can be found here.

Step 1: Gathering Materials and Tools

You will need the following materials to get started:

  • 1x Arduino UNO(here)
  • 1x Arduino Nano(here)
  • 2x nRF24L01 2.4GHz wireless modules(here)
  • 1x L298N Motor driver(here)
  • 2x Gear motor (the yellow piece of plastic)(here)
  • 1x Joystick(here)
  • 1x 9v battery clip(here)
  • 2x Power switch(here)
  • 2x TR 18650 batteries (and a charger)(here)
  • 1x TR 18650 battery holder for 2 batteries(here)
  • 1x Male to female jumper set(here)

The 3D printed parts consist of (can be found on the bottom of this step):

  • 2x Body
  • 2x TrackMidFrame
  • 52x Track
  • 4x Cog
  • 4x CogBracketInner
  • 4x CogBracketOuter
  • 1x TankCover
  • 1x Controller

You'll also need the following tools:

  • Soldering iron
  • Various drill sizes
  • Super glue
  • Pliers
  • Knife

Step 2: Put Together the Tank

After printing I assembled the tank. All the pieces except for the tracks, cogs and cover were glued together with super glue. The tracks ended up to be too tight around the cogs, it might be an issue with my printer, but I decided to add two extra tracks on each side and design a guide for the tracks. It's not the most convenient solution, but it works.

After I assembled the tank, I drilled holes to fit the wireless module and the power switch. I probably should have drilled the holes before I glued it all together, but it didn't make that much of a difference. I drilled holes and attached motor driver to the bottom of the tank with two M3 bolts.

Optional (if you have the same problem as me):

Print two tank guides from the 'optional' folder and some tracks (I suggest adding one or two on each side).

Step 3: Programming the Tank and Controller

To program the arduino you will need the RF24 library installed. So download the files below and open arduino IDE. Go to Sketch -> Include Library -> Add .ZIP Library and import 'RF24.zip' into there.

Next you'll have to connect the arduino UNO and upload 'tank.ino' to the arduino. we'll conect the wires in the next step.

Now unplug the Arduino UNO and connect the Arduino Nano and upload 'controller.ino' to the Arduino.

Remember to change the 'board' and 'port' settings under tools to the correct board type and port.

Step 4: Wiring the Tank

(the image of the nRF24L01 module is a bottom view)

Wiring the tank:

Connect the following pins.

nRF24L01 pins ---- Arduino pins



• GND 1 ---- GND
• VCC 2 ---- 3.3V
• CE 3 ---- 7
• CSN 4 ---- 8
• SCK 5 ---- 13
• MOSI 6 ---- 11
• MISO 7 ---- 12
• IRQ 8 ---- not connected


L298N ---- Arduino pins



• IN1 ---- 5
• IN2 ---- 6
• IN3 ---- 9
• IN4 ---- 10


As far as the battery pack of the tank is concerned, the ground wire goes to the GND pin of the arduino and the GND pin of the motor driver. the power wire goes to Vin pin of the arduino and to the +12V pin of the motor driver via the power switch. Oh, and the +5V pin of the motor driver is attached to the 5V pin of the arduino.

Step 5: ​Wiring the Controller

Wiring the Controller

nRF24L01 pins ---- Arduino pins



• GND 1 ---- GND
• VCC 2 ---- 3.3V
• CE 3 ---- 7
• CSN 4 ---- 8
• SCK 5 ---- 13
• MOSI 6 ---- 11
• MISO 7 ---- 12
• IRQ 8 ---- not connected


Joystick ---- Arduino pins



• GND ---- GND
• +5V ---- 5V
• VRx ---- A0
• VRy ---- A1


It's a bit of a puzzle, fitting all the components into the controller, but with some patience I'm sure you'll manage

Step 6: Test the Tank!

Now, if all goes well, you should be able to control the tank with the controller. if the tracks move in the wrong direction you can either change the code(which is a pain) or you can flip the wires running to the motor driver.

If the tank doesn't work at all you should check the connections of the nRF24L01. you can also connect both Arduino's to the computer, open two different arduino instances, open serial monitor on both and check if the signals are sent and/or received. Please note that if the controller prints the reading of the X and Y values it doesn't mean those signals reach the module.

If you have any problems or suggestions please comment and I will try to response in a timely fashion.

~Ryan

Comments

author
MahmoudS42 (author)2017-08-25

Can it works with more than 12 servo motors ?

author
NimaR2 (author)2017-08-21

i made it, it's works correctly.. tanks..

author
lokeshsingre (author)2017-06-12

does it performs pwm

author
JagdishG10 (author)2017-05-25

great project

author
Richboygotdoe (author)2017-02-05

I'm having trouble making a code that uses two joysticks that control there own separate motor. Can you help please? :)

author
tulpek (author)2017-01-28

Hi
Sorry to bother you with another stupid question but I have small issue that hopefully you'll be able to help me with, the issue is that after connecting everything up like in your instructable and loading the sketches to Uno and Nano, after powering up my motors keep running forward with the joistick in the center, when I pull the joistick back it changes to reverse same for left or right so that's all good, but forward or center position of the joistick keeps the motors running forward so I can't stop the tank. Thank You

author
RyanKolk (author)tulpek2017-01-28

Hi,

If you plug the controller into the the computer and open a serial monitor at baud rate 115200, what are the values of x and y when the joystick is not touched?

author
tulpek (author)RyanKolk2017-01-29

Hi the X reads 514 and Y reads 483-484

author
RyanKolk (author)tulpek2017-01-29

Hey,
If you do the same thing as described in the other comment I posted it should work, but instead of 480 and 502 you might want to do 470 and 492

author
KENESH (author)RyanKolk2017-01-29

Hi,

I've got the same problem , value of X = 1023, Y = 490 ~ 493.

Thank You

author
RyanKolk (author)KENESH2017-01-29

For the Y-axis all you have to do is change all the

Y > 500 and Y < 500 to Y > 480 and Y < 480 and

Y > 524 and Y < 524 to Y > 502 and Y < 502 and also 'map(Y,524,1024,0,255);' to 'map(Y,504,1024,0,255);' and

'map(Y,500,0,0,255);' to 'map(Y,480,0,0,255);' in the tank code

but it seems that the potentiometer of the x-axis is either broken or not correctly connected.

author
10maysathe (author)2016-12-19

These are the connection diagrams .i just need help with the codes

images.jpg
author
RyanKolk (author)10maysathe2016-12-19

ookay, ill have a look and get back to you asap

author
10maysathe (author)RyanKolk2016-12-20

Thank you for helping me out.I prefer your pin connections with only changes in the transmitter as this pin connection uses a L293d motor driver

author
10maysathe (author)2016-12-17

i need to use the codes for my college project. But i need to use two joysticks with their y axis in control .First joystick with its y axis for forward n backward control and the other joystick with its y axis for right n left direction control. I tried coding but i am really bad at it.Can you please provide me the codes??????

exactly like this project

can you please help me out?

author
RyanKolk (author)10maysathe2016-12-18

Hi!
From what I read I think you can achieve what you need by hooking up the x-axis running to the arduino to the y-axis on the second joystick.
Or do you want each joystick controlling one motor?

author
10maysathe (author)RyanKolk2016-12-19

Yeah . I want each joystick to control one motor with its y axis only.So the hooking up of x axis of the joystick to the y axis of other joystick wont help.I need codes that would control one motor with one joystick.

author
krish420 made it! (author)2016-08-10

instead of 24l01 transceiver how to use rf 433mhz?

temp_1006668143.jpg
author
Idrispo (author)krish4202016-11-13

No, dont use radio as the distance sucks

author
RyanKolk (author)krish4202016-08-10

Looks good!
Personally I have never worked with the rf 433 mhz, but I would guess that if you get a simple send and receive code running, you could send the analog inputs from a joystick. Try searchin for something similar on the internet. sorry I cant help much more that that

author
Richboygotdoe (author)2016-10-08

if you put both power sources like you did, how do you connect them to a switch without giving the arduino and the motor driver the same amount of power?

author
JaredL32 (author)2016-09-14

Great project, i used this setup on a different tank chassis,which didn't turn very well but besides that the only problem i had was when you turn the remote on first, then the tank, the tank moves on it's own but only forward. However if you turn the tank on then the remote it seems to work fine.

author
Richboygotdoe (author)2016-09-05

ioctl("TIOCMGET"): Inappropriate ioctl for device

do you know how i can fix this?

author

I'm sorry for all the stupid questions below. i was eager to finish this and skipped some steps. and if you could explain, how does one add a single button for a servo?

author
krish420 (author)2016-08-16

Tx and Rx on arduino uno does not light al all.. please help bro...

author
RyanKolk (author)krish4202016-08-17

I had the same problem with one of my arduino's, for some reason it doesn't work on some arduino's. could you try changing an arduino? if the problem persists i'll be happy to try and help.

author
Scorched Earth made it! (author)2016-07-03

Great Project , easy and clear steps , thanks for sharing
Now I want to add a 2dof robotic claw clamp to the tank , and I've been struggling to do so with no success in sketching so far
If you could help me with a sketch for 2 servos that will work with your given setup then it will be great
Thanks !!

2016-07-03-025.jpg2016-07-03-026.jpg
author
RyanKolk (author)Scorched Earth2016-08-17

Hi! All you have to do is add the new lines to 'struct package' in controller and tank:

struct package
{
int X=1;
int Y=1;
int servo1=1;
int servo2=1;
};

then you can create the controller code however you want, and on the receiving end all you have to do is map 'data.servo1' or 'data.servo2' to 0 to 180 and then write it to the servo.

If that doesn't help, i made a quick sketch based on the servo knob sketch:

Transmitter:

#include <SPI.h>
#include "RF24.h"
RF24 myRadio (7, 8);
byte addresses[][6] = {"0"};
struct package
{
int servo1=1;
};
typedef struct package Package;
Package data;
void setup()
{
Serial.begin(115200);
delay(100);
myRadio.begin();
myRadio.setChannel(115);
myRadio.setPALevel(RF24_PA_MIN);
myRadio.setDataRate( RF24_250KBPS ) ;
myRadio.openWritingPipe( addresses[0]);
delay(100);
}
void loop()
{
myRadio.write(&data, sizeof(data));
Serial.print(data.servo1);
data.servo1 = analogRead(A0);
delay(100);
}

Receiver:

#include <SPI.h>
#include <Servo.h>
#include "RF24.h"
RF24 myRadio (7, 8);
struct package
{
int servo1=1;
};
byte addresses[][6] = {"0"};
Servo myservo;
typedef struct package Package;
Package data;
int val;
void setup()
{
Serial.begin(115200);
delay(1000);
myRadio.begin();
myRadio.setChannel(115);
myRadio.setPALevel(RF24_PA_MAX);
myRadio.setDataRate( RF24_250KBPS ) ;
myRadio.openReadingPipe(1, addresses[0]);
myRadio.startListening();
myservo.attach(9);
}
void loop()
{
if ( myRadio.available())
{
while (myRadio.available())
{
myRadio.read( &data, sizeof(data) );
}
val = map(data.servo1, 0, 1023, 0, 180);
myservo.write(val);
delay(15);
}
}
author
Aneriah (author)2016-07-25

Also How do I order the 3D parts?

author
RyanKolk (author)Aneriah2016-08-10

ordering parts to print can be done on countless ways. but one i suggest is 3dhubs.com. You can have your print printed by someone Who is relatively close and is usually cheaper than havig it printed by a professional. Hope that helps!

author
RyanKolk (author)Aneriah2016-08-10

you could use AA batteries, but I have noticed that they are not powerful enough. the only way I got it tonwork was with 2 battery packs with AA batteries, but in that case it was cheaper for me just to order the big batteries I use on te tank

author
Aneriah (author)2016-07-27

Also can I just use AA batteries.

author
Richboygotdoe (author)2016-06-27

does the Arduino nano come with a cord? where could I buy one?

author
Richboygotdoe (author)2016-06-15

Do you have a raw picture of all the wires and arduino of the tank without the model of the tank? thanks that would really help

author
TheodoreL4 (author)2016-05-31

Have checked and rechecked all connections. programs compile an load. Using a micro. Nothing happens, power lights up but nothing moves, tx and rx led's on micro do not show any action. Way ahead???

author
RyanKolk (author)TheodoreL42016-06-01

I think the problem lays with the wifi modules. I suggest using the Getting started guide in the library. this uses two way communictaion, so you know if the modules work. You might find this site useful. In my code I actually changed pins 9 and 10 to 7 and 8 because The motor driver uses PWM. I had some trouble getting the modules working, but I messed around with it a bit and got them to work. I'm sure you'll be able to do the same!

author
Richboygotdoe made it! (author)2016-05-19

with the joystick, which is the negative and positive leads?

F56VSMUIO09FARM.MEDIUM.jpg
author
RyanKolk (author)Richboygotdoe2016-05-19

the joystick I use has pins on them that are labelled. so you should be able to tell on the joystick you use.

author
Richboygotdoe (author)2016-05-15

Does the 12v on the motor driver connect to the same port as the switch? how do i do that?

author
RyanKolk (author)Richboygotdoe2016-05-15

Hi,
The + of the battery connects to the middel pin of the switch. One of the outer pins of the switch connects to the +12V of the motor driver and the Vin pin of the arduino

author
Richboygotdoe (author)RyanKolk2016-05-16

Arduino: 1.6.4 (Mac OS X), Board: "Arduino Uno"

Tank.ino:9:19: fatal error: RF24.h: No such file or directory

compilation terminated.

Error compiling.

This report would have more information with

"Show verbose output during compilation"

enabled in File > Preferences.

author
RyanKolk (author)Richboygotdoe2016-05-16

have you installed the RF24 library?

author
Richboygotdoe (author)RyanKolk2016-05-17

could you include a link because i dont know where to look

author
RyanKolk (author)Richboygotdoe2016-05-17

in step 3 there is a file called RF24.zip. follow the instructions in step 3 to install that file and that should fix the problem.

author
matthew_carlsen (author)2016-05-16

Ok. But then how do you connect both power sources to the same circuit?

author
RyanKolk (author)matthew_carlsen2016-05-16

well, one power source is used for the arduino and the other for the motors, so what you have to do is tie the ground wires of the power sources together creating a common ground and have one power lead run through the switch to Vin of the arduino and the other through the switch to the +12V of the motor driver.

author
matthew_carlsen (author)2016-05-15

Where did you get your power switches from?

author
RyanKolk (author)matthew_carlsen2016-05-15

I bought them from ebay here. but if you plan on using multiple power supplies(seperate ones for motors and arduino) you'll need something like this here

author
matthew_carlsen (author)RyanKolk2016-05-15

How do you know what power supply to use and/or how many power supplies?

author
RyanKolk (author)matthew_carlsen2016-05-15

oh, sorry for the confusion. i meant battery packs. I only used one for the tank, but they are pretty powerful batteries. In that case you'd use the first power switch. If one choses to use a 4-6AA battery pack for the motors and a 9V battery for the arduino they should buy the second power switch