Muhammed Azhar
Published © CC BY

The Ultimate Offroad RC Rover

A great starter project for hobbyists - In this tutorial I am showing how to make an all terrain remote controlled rover bot.

IntermediateFull instructions provided3 hours8,156
The Ultimate Offroad RC Rover

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Duel DC motor driver
×1
NRF2401
×1
HC-05 Bluetooth Module
HC-05 Bluetooth Module
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Metal gear motor
×2
Gear motor
×2
Wheel
×4
Slide Switch
Slide Switch
×1
LIPO 2600 mah battery
×1
'L' shaped clamp for plastic gear motor
×3
'L' shaped clamp for metal gear motor
×2
Aluminium sheet 2 mm (from local store)
×1

Software apps and online services

Bluetooth RC car (Only for Bluetooth controlling option)

Hand tools and fabrication machines

Screwdriver
Wire cutter
Soldering iron (generic)
Soldering iron (generic)
Drilling machine(not important)

Story

Read more

Schematics

Circuit diagram

Code

RC_rover_code_for_RF_function.ino

C/C++
This code is for controlling the robot using the custom made remote. For the code used in the transmitter(Remote) visit the tutorial of making remote -Click here to visit that tutorial. In this arduino code there is a library called print.h
/*
 Written by: Mujahed Altahle
 
This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ 
or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

 */
/* A simple Project for Remote Controlling with nRF24L01+ radios. 
 We have 2 nodes, the transmitter (this one) and the receiver which is attached to the Car.
 The idea is to transmit  2 parameters , one is Direction (Backward, or Forward with the speed) the other is the Steering (Left, or Right with the degree of rotation).
 The nRF24L01 transmit values in type of "uint8_t" with maximum of 256 for each packet, so the values of direction is divided by (10) at the Tx side,
 then it is multiplied by 10 again at the Rx side.
 The Rx rules is to output the received parameters to port 3 and 6 where the Servo and the ESC are are attached
 a condition is required to prevent the controller from transmitting values that is not useful (like 1480-1530 for ESC and 88-92 for Servo) to save more power as much as we can
 */
 
#include <Servo.h> 
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include "printf.h"
//
// Hardware configuration
//

// Set up nRF24L01 radio on SPI bus plus pins 9 & 10
RF24 radio(9,10);
int stop1=2;
int stop2=4;
int back1=5;
int back2=7;

int pwm1=6;
int pwm2=3;



// Single radio pipe address for the 2 nodes to communicate.
const uint64_t pipe = 0xE8E8F0F0E1LL;

//
// Payload
//

uint8_t received_data[2];
uint8_t num_received_data =sizeof(received_data);

//
// Setup
//

void setup(void)
{
  delay(2000); //wait until the esc starts in case of Arduino got power first
  pinMode(6, OUTPUT);
  pinMode(3, OUTPUT);
  
  pinMode(stop1, OUTPUT); 
  pinMode(stop2, OUTPUT); 
  pinMode(back1, OUTPUT); 
  pinMode(back2, OUTPUT); 


  //
  // Print preamble
  //

  Serial.begin(57600);
  printf_begin();

  //
  // Setup and configure rf radio
  //

  radio.begin(); //Begin operation of the chip.
  // This simple sketch opens a single pipes for these two nodes to communicate
  // back and forth.  One listens on it, the other talks to it.
  radio.openReadingPipe(1,pipe);
  radio.startListening();
  //
  // Dump the configuration of the rf unit for debugging
  //
  radio.printDetails(); 
}


void Stop(void)
{
  analogWrite(pwm1, 0);
  analogWrite(pwm2, 0);
}
void Forward1(void)
{
  analogWrite(pwm1, 255);
  digitalWrite(back1, LOW);
  digitalWrite(back2, LOW); 
}
void Forward2(void){
  analogWrite(pwm2, 255);
  digitalWrite(back1, LOW);
  digitalWrite(back2, LOW); 
}
void Backward1(void){
  analogWrite(pwm1, 255);
  digitalWrite(back1, HIGH);

}
void Backward2(void){
  analogWrite(pwm2, 255);

  digitalWrite(back2, HIGH); 
}


void loop(void)
{
  // if there is data ready
  if ( radio.available() )
  {
    bool done = false;
    int value1;
    int value2;
    while (!done)
    {
      // Fetch the payload, and see if this was the last one.
      done = radio.read( received_data, num_received_data );
      value1=received_data[0]; //Multiplication by 10 because the ESC operates for vlues around 1500 and the nRF24L01 can transmit maximum of 255 per packet 
      value2=received_data[1]; //Multiplication by 10 because the ESC operates for vlues around 1500 and the nRF24L01 can transmit maximum of 255 per packet 
    //analogWrite(pwm2,value2);
    Serial.println("value2=");
    Serial.println(value2);
    Serial.println("value1=");
    Serial.println(value1);   
       if(value1<170 && value1>140 || value2>70 && value2<100){
       Stop();
       }
       if(value1>170 && value1!=0){
       Forward1();
       }
       if(value2<70 && value2!=0){
       Forward2();
       }
       if(value1<140 && value1!=0){
       Backward1();
       }
       if(value2>100 && value2!=0){
       Backward2();
       }

    }
  }
}

printf.h

C/C++
This is the print.h library for above code. You need to add the print.h file and arduino code in a same folder that I have provided here.
/*
 Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
 
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 version 2 as published by the Free Software Foundation.
 */
 
/**
 * @file printf.h
 *
 * Setup necessary to direct stdout to the Arduino Serial library, which
 * enables 'printf'
 */

#ifndef __PRINTF_H__
#define __PRINTF_H__

#ifdef ARDUINO

int serial_putc( char c, FILE * ) 
{
  Serial.write( c );

  return c;
} 

void printf_begin(void)
{
  fdevopen( &serial_putc, 0 );
}

#else
#error This example is only for use on Arduino.
#endif // ARDUINO

#endif // __PRINTF_H__

RC_rover_code_for_bluetooth_controling.ino

C/C++
This code is for bluetooth controlling option, using this application.
#include <Servo.h> 
//Constants and variable
int stop1=2;
int stop2=4;
int back1=5;
int back2=7;

int pwm1=6;
int pwm2=3;

char dataIn = 'S';
char determinant;
char det;
int vel = 255; //Bluetooth Stuff


void setup() {
  Serial.begin(9600); // set up Serial library at 9600 bps

  pinMode(6, OUTPUT);
  pinMode(3, OUTPUT);
  
  pinMode(stop1, OUTPUT); 
  pinMode(stop2, OUTPUT); 
  pinMode(back1, OUTPUT); 
  pinMode(back2, OUTPUT); 
  
  //Initalization messages
  Serial.println("ArduinoBymyself - ROVERBot");
  Serial.println("     AF Motor test!");
 
}

void loop() {

  det = check(); //call check() subrotine to get the serial code
  
  //serial code analysis
  switch (det){
    case 'F': // F, move forward
  analogWrite(pwm1,vel);
  digitalWrite(back1, LOW);
  digitalWrite(back2, LOW); 

  analogWrite(pwm2, vel);
  digitalWrite(back1, LOW);
  digitalWrite(back2, LOW); 
    det = check();
    break;
   //------- 

    case 'B': // B, move back
  analogWrite(pwm1, vel);
  digitalWrite(back1, HIGH);
   
  analogWrite(pwm2, vel);
  digitalWrite(back2, HIGH); 
    det = check();
    break;
    
//-----    
    case 'L':// L, move wheels left
    analogWrite(pwm1,vel);
    digitalWrite(back1, LOW);
    analogWrite(pwm2, vel);
    digitalWrite(back2, HIGH); 
    det = check();
    break;
//----------
    
    case 'R': // R, move wheels right
    analogWrite(pwm2, vel);
    digitalWrite(back2, LOW); 
    analogWrite(pwm1, vel);
    digitalWrite(back1, HIGH); 
    det = check();
    break;
  //-----


   case 'I': // I, turn right forward
    analogWrite(pwm1,0);
    digitalWrite(back1, LOW);
    digitalWrite(back2, LOW); 

    analogWrite(pwm2, vel);
    digitalWrite(back1, LOW);
    digitalWrite(back2, LOW); 
    det = check();
    break;
    
    case 'J': // J, turn right back
  analogWrite(pwm1,vel);
  digitalWrite(back1, HIGH);

  analogWrite(pwm2,0);
  digitalWrite(back2, HIGH); 
    det = check();
    break;
    
    case 'G': // G, turn left forward
  analogWrite(pwm1,vel);
  digitalWrite(back1, LOW);
  digitalWrite(back2, LOW); 

  analogWrite(pwm2,0);
  digitalWrite(back1, LOW);
  digitalWrite(back2, LOW); 
    det = check();
    break;
    
    case 'H': // H, turn left back
  analogWrite(pwm1,0);
  digitalWrite(back1, HIGH);

  analogWrite(pwm2, vel);
  digitalWrite(back2, HIGH);
    det = check();
    break;


  case 'S': // R, move wheels right
    analogWrite(pwm1, 0);
    analogWrite(pwm2, 0);
    digitalWrite(back1, LOW);
    digitalWrite(back2, LOW); 
    det = check();
    break;
    
  }
}
    

//get bluetooth code received from serial port
int check(){
  if (Serial.available() > 0){// if there is valid data in the serial port
    dataIn = Serial.read();// stores data into a varialbe

    //check the code
    if (dataIn == 'F'){//Forward
      determinant = 'F';
    }
    else if (dataIn == 'B'){//Backward
      determinant = 'B';
    }
    else if (dataIn == 'L'){//Left
      determinant = 'L';
    }
    else if (dataIn == 'R'){//Right
      determinant = 'R';
    }
    else if (dataIn == 'I'){//Froward Right
      determinant = 'I';
    }
    else if (dataIn == 'J'){//Backward Right
      determinant = 'J';
    }
    else if (dataIn == 'G'){//Forward Left
      determinant = 'G';
    }    
    else if (dataIn == 'H'){//Backward Left
      determinant = 'H';
    }
    else if (dataIn == 'S'){//Stop
      determinant = 'S';
    }
    else if (dataIn == '0'){//Speed 0
      vel = 0;
    }
    else if (dataIn == '1'){//Speed 25
      vel = 25;
    }
    else if (dataIn == '2'){//Speed 50
      vel = 50;
    }
    else if (dataIn == '3'){//Speed 75
      vel = 75;
    }
    else if (dataIn == '4'){//Speed 100
      vel = 100;
    }
    else if (dataIn == '5'){//Speed 125
      vel = 125;
    }
    else if (dataIn == '6'){//Speed 150
      vel = 150;
    }
    else if (dataIn == '7'){//Speed 175
      vel = 175;
    }
    else if (dataIn == '8'){//Speed 200
      vel = 200;
    }
    else if (dataIn == '9'){//Speed 225
      vel = 225;
    }
    else if (dataIn == 'A'){//Speed 255
      vel = 255;
    }
    else if (dataIn == 'X'){//Extra On
      determinant = 'X';
    }
    }
  return determinant;
}

Credits

Muhammed Azhar

Muhammed Azhar

1 project • 163 followers
I am Muhammed Azhar a maker from India. Visit my blog for more projects- robotechmaker.com

Comments