Dagu Rover 5 - Selfmade RF24L Remote control and now with gripper :-)

I’m starting with the Dagu 5 Rover Chassis, in its 2 Wheel Drive form and the Explorer Controller Board for Dagu Rover 5 2WD.
I got it for a nice price :wink:

Controller board

Dagu Rover 5 2WD

I'm not a programmer but I have some experience with coding for the Arduino, but sensors and some of the other electronic pieces that combine to make a functional robot are new to me. Thanks for your help and input.

My first sketch is working fine with a ultrasonic sensor (SR04)

// Control of a Rover5 robot - Last update: AndreasVan 2015-02-28 Vers. 2.01
// Dagu Rover 5 2WD Tracked Chassis + Explorer Controller Board for Dagu Rover 5 2WD
// Micro controller = Arduino UNO
// Detecting obstacles with an SR04 ultrasonic sensor mounted on servo
// this code is public domain, enjoy!
 
#include <NewPing.h>        //library SR04 ultrasonic sensor
#include <Servo.h>          //library Servo (SR04 on servo)

#define TRIGGER_PIN 9       // SR04 sensor  
#define ECHO_PIN    8       // SR04 sensor
#define MAX_DISTANCE 200    //sensor distance
Servo myservo;  
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);

#define runEvery(t) for (static typeof(t) _lasttime;(typeof(t))((typeof(t))millis() - _lasttime) > (t);_lasttime += (t))

const int PWN1 = 6;           //right PWN
const int DIR1 = 7;           //right DIR
const int PWN2 =11;           //left PWN
const int DIR2 =12;           //left DIR
const int redLed = 5;         //robot drives forward
const int greenLed = 4;       //robot drives backward
const int yellowLed = 3;      //robot turns left
const int blueLed = 2;        //robot turns right

int uS;                       //value of SR04 ultrasonic sensor
int distance;                 //distance in cm of ultrasonic sensor 
int pos = 90;                 //start position of servo = 90
int servoDirection = 0;       //sweeping left or right
int MoveDirection = 0;        //0 = forward, 1 = backward, 2 = left, 3 = right
int lastMoveDirection;        //last direction of the robot
int distanceCenter;     
int distanceLeft;
int distanceRight;
int servoDelay = 55;          //servo sweep speed
const int speedLeft = 90;    //motor speed left
const int speedRight = 90;   //motor speed right
long previousMillis = 0;
const int interval = 1000;    // time to switch between the MoveDirections

void setup() {                
  pinMode(PWN1, OUTPUT);  
  pinMode(DIR1, OUTPUT); 
  pinMode(PWN2, OUTPUT); 
  pinMode(DIR2, OUTPUT);
  analogWrite(PWN1, 0);
  analogWrite(PWN2, 0);
  pinMode(5, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(2, OUTPUT);
  pinMode(redLed, OUTPUT); 
  pinMode(greenLed, OUTPUT);
  pinMode(yellowLed, OUTPUT);
  pinMode(blueLed, OUTPUT);
  Serial.begin(9600);       //to use the serial monitor
  myservo.attach(10);       //servo on pin 10
  myservo.write(pos);       //center servo
 }

void loop() {

  sweepServo();             //servo sweep function
  
  getDistance();            //ultrasonic sensor distance 
  
    if (pos >= 15 && pos <= 45)
  {
    distanceRight = distance;  //measured distance servo is to the right = distanceRight
  }
  if (pos >= 135 && pos <= 165)
  {
    distanceLeft = distance;   //measured distance servo is to the left = distanceLeft
  }   
  if (pos > 70 && pos < 110)
  {
    distanceCenter = distance; //measured distance servo in centred  = distanceCenter
  } 

  if (distanceCenter >= 25)    //no obstacle to see for miles, straight on
  {
    MoveDirection = 0;         //move forward
  }
  else                         //obstacle detected, turn left or right?
  {
    if (distanceLeft > distanceRight)  
    {
      MoveDirection = 2;      //turn left = 2
    }
    if (distanceLeft < distanceRight)
    {
      MoveDirection = 3;      //turn right = 3
    }
    if (distanceLeft <= 5 && distanceCenter <= 5 || distanceRight <= 5 && distanceCenter <= 5)
    {
      MoveDirection = 1;      //  turn back
    }
  }

  unsigned long currentMillis = millis();  //set a timer

  if(MoveDirection == 0 && MoveDirection == lastMoveDirection)  
  {
    forward();
    lastMoveDirection = MoveDirection;
  }
  if(MoveDirection == 0 && MoveDirection != lastMoveDirection && currentMillis - previousMillis > interval )
  {  
    forward();
    lastMoveDirection = MoveDirection;
    previousMillis = currentMillis;
  }
  if(MoveDirection == 1 && MoveDirection == lastMoveDirection)
  {
    backward();
    lastMoveDirection = MoveDirection;
  }
  if(MoveDirection == 1 && MoveDirection != lastMoveDirection && currentMillis - previousMillis > interval )
  {  
    backward();
    lastMoveDirection = MoveDirection;
    previousMillis = currentMillis;
  }
  if(MoveDirection == 2 && MoveDirection == lastMoveDirection)
  {
    left();
    lastMoveDirection = MoveDirection;
  }
  if(MoveDirection == 2 && MoveDirection != lastMoveDirection && currentMillis - previousMillis > interval )
  {  
    left();
    lastMoveDirection = MoveDirection;
    previousMillis = currentMillis;
  }
  if(MoveDirection == 3 && MoveDirection == lastMoveDirection)
  {
    right();
    lastMoveDirection = MoveDirection;
  }
  if(MoveDirection == 3 && MoveDirection != lastMoveDirection && currentMillis - previousMillis > interval )
  {  
    right();
    lastMoveDirection = MoveDirection;
    previousMillis = currentMillis;
  }
}

void forward()
{
  digitalWrite(DIR1, LOW);
  digitalWrite(DIR2, LOW);   
  analogWrite(PWN1, speedLeft);
  analogWrite(PWN2, speedRight);
  digitalWrite(redLed, HIGH);
  digitalWrite(greenLed, LOW);
  digitalWrite(yellowLed, LOW);
  digitalWrite(blueLed, LOW);
}

void stop()
{
  digitalWrite(DIR1, LOW);   
  digitalWrite(DIR2, LOW);   
  analogWrite(PWN1, 0);
  analogWrite(PWN2, 0);
  digitalWrite(redLed, LOW);
  digitalWrite(greenLed, LOW);
  digitalWrite(yellowLed, LOW);
  digitalWrite(blueLed, LOW);
}

void backward()
{
  digitalWrite(DIR1, HIGH);  
  digitalWrite(DIR2, HIGH);   
  analogWrite(PWN1, speedLeft-10); 
  analogWrite(PWN2, speedRight-10); 
  digitalWrite(redLed, LOW);
  digitalWrite(greenLed, HIGH);
  digitalWrite(yellowLed, LOW);
  digitalWrite(blueLed, LOW);
}

void left()
{
  digitalWrite(DIR1, LOW);
  digitalWrite(DIR2, HIGH);   
  analogWrite(PWN1, speedLeft-20); 
  analogWrite(PWN2, speedRight+20); 
  digitalWrite(redLed, LOW);
  digitalWrite(greenLed, LOW);
  digitalWrite(yellowLed, HIGH);
  digitalWrite(blueLed, LOW);
}

void right()
{
  digitalWrite(DIR1, HIGH);
  digitalWrite(DIR2, LOW);   
  analogWrite(PWN1, speedLeft+20);  
  analogWrite(PWN2, speedRight-20); 
  digitalWrite(redLed, LOW);
  digitalWrite(greenLed, LOW);
  digitalWrite(yellowLed, LOW);
  digitalWrite(blueLed, HIGH);
}

void getDistance()
{
  runEvery(20)                      //loop for ultrasonic measurement
  {
    uS = sonar.ping();
    distance = uS / US_ROUNDTRIP_CM;
    if (uS == NO_ECHO)              // if the sensor did not get a ping        
    {
      distance = MAX_DISTANCE;      //so the distance must be bigger then the max vaulue of the sensor
    }
    Serial.print("Ping: ");         //to check distance on the serial monitor
    Serial.print(distance); 
    Serial.println("cm");
  }
}

void sweepServo()
{
  runEvery(servoDelay)                      //this loop determines the servo position
  {
    if(pos < 165 && servoDirection == 0)    // 165 = servo to the left
    {                                  
      pos = pos + 5;                        
    } 
    if(pos > 15 && servoDirection == 1)     // 15 = servo to the right
    {                                
      pos = pos - 5;
    }    
  }   
  if (pos == 165 )    
  {
    servoDirection = 1;                     //changes direction
  }
  if (pos == 15 )     
  {
    servoDirection = 0;                     //changes direction
  }   
  myservo.write(pos);                       //move servo!
}

The next step is to use the IR sensors on the Explorer board and here is the beginning of my problems.
When the rover find a obstacle he only drive forward and backward on the same place ... on and on and on ...

This is the sketch:

#include <NewPing.h>          //library SR04 ultrasonic sensor
#include <Servo.h>            //library Servo (SR04 on servo)
#include <rover_ir_sensors.h> //library ir sensors

#define TRIGGER_PIN 9         //SR04 sensor  
#define ECHO_PIN    8         //SR04 sensor
#define MAX_DISTANCE 200      //sensor distance
Servo myservo;  
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);

#define runEvery(t) for (static typeof(t) _lasttime;(typeof(t))((typeof(t))millis() - _lasttime) > (t);_lasttime += (t))

const int PWN1 = 6;           //right PWN
const int DIR1 = 7;           //right DIR
const int PWN2 =11;           //left PWN
const int DIR2 =12;           //left DIR
const int redLed = 5;         //robot drives forward
const int greenLed = 4;       //robot drives backward
const int yellowLed = 3;      //robot turns left
const int blueLed = 2;        //robot turns right
const int NUM_IR_SENSORS = 4;
const int IR_Led_Pins[ NUM_IR_SENSORS ] = { A0, A0, A1, A1 };   
const int IR_Sensor_Pins[ NUM_IR_SENSORS ] = { A3, A2, A4, A5 };
const int Close_Range_IR_Value = 150;

RoverIRSensors IRSensors( 
    IR_Led_Pins[ 0 ], IR_Led_Pins[ 1 ],
    IR_Led_Pins[ 2 ], IR_Led_Pins[ 3 ],
    IR_Sensor_Pins[ 0 ], IR_Sensor_Pins[ 1 ],
    IR_Sensor_Pins[ 2 ], IR_Sensor_Pins[ 3 ] );

int uS;                     //value of SR04 ultrasonic sensor
int distance;               //distance in cm of ultrasonic sensor 
int pos = 90;               //start position of servo = 90
int servoDirection = 0;     //sweeping left or right
int MoveDirection = 0;      //0 = forward, 1 = backward, 2 = left, 3 = right
int lastMoveDirection;      //last direction of the robot
int distanceCenter;     
int distanceLeft;
int distanceRight;
int servoDelay = 55;        //servo sweep speed
const int speedLeft = 140;  //motor speed left
const int speedRight = 130; //motor speed right
long previousMillis = 0;
const int interval = 1000;  //time to switch between the MoveDirections when it detects an obstacle

void setup() {                
  pinMode(PWN1, OUTPUT);  
  pinMode(DIR1, OUTPUT); 
  pinMode(PWN2, OUTPUT); 
  pinMode(DIR2, OUTPUT);
  analogWrite(PWN1, 0);
  analogWrite(PWN2, 0);
  pinMode(5, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(2, OUTPUT);
  pinMode(redLed, OUTPUT); 
  pinMode(greenLed, OUTPUT);
  pinMode(yellowLed, OUTPUT);
  pinMode(blueLed, OUTPUT);
  Serial.begin(9600);       //to use the serial monitor
  myservo.attach(10);       //servo on pin 10
  myservo.write(pos);       //center servo
  delay(2000);              //start delay
}

void loop() {
  
    
    IRSensors.takeReadings();  // read from the IR sensors  
    int frontLeftIR = IRSensors.lastFrontLeftReading();
    int frontRightIR = IRSensors.lastFrontRightReading();
    int rearLeftIR = IRSensors.lastRearLeftReading();
    int rearRightIR = IRSensors.lastRearRightReading();
 
  sweepServo();                //servo sweep function
  
  getDistance();               //ultrasonic sensor distance 
  
    if (pos >= 15 && pos <= 45)
  {
    distanceRight = distance;  //measured distance servo right = distanceRight
  }
  if (pos >= 135 && pos <= 165)
  {
    distanceLeft = distance;   //measured distance servo left = distanceLeft
  }   
  if (pos > 70 && pos < 110)
  {
    distanceCenter = distance; //measured distance servo centred  = distanceCenter
  } 

  if (distanceCenter >= 25
              || rearLeftIR >= Close_Range_IR_Value
              || rearRightIR >= Close_Range_IR_Value)    //no obstacle to see for miles, straight on
  {
    MoveDirection = 0;         //move forward
  }
  else                         //obstacle detected, turn left or right
  {
    if (distanceLeft > distanceRight 
              || frontLeftIR >= Close_Range_IR_Value
              || frontRightIR <= Close_Range_IR_Value
              || rearLeftIR >= Close_Range_IR_Value
              || rearRightIR <= Close_Range_IR_Value )  
    {
      MoveDirection = 2;      //turn left = 2
    }
    if (distanceLeft < distanceRight 
              || frontLeftIR >= Close_Range_IR_Value
              || frontRightIR <= Close_Range_IR_Value
              || rearLeftIR >= Close_Range_IR_Value
              || rearRightIR <= Close_Range_IR_Value ) 
    {
      MoveDirection = 3;      //turn right = 3
    }
    if (distanceLeft <= 5 && distanceCenter <= 5 || distanceRight <= 5 && distanceCenter <= 5
                    || frontLeftIR <= Close_Range_IR_Value
                    || frontRightIR <= Close_Range_IR_Value
                    || rearLeftIR >= Close_Range_IR_Value
                    || rearRightIR >= Close_Range_IR_Value )
    {
      MoveDirection = 1;      //  turn back = 1
    }
  }

  unsigned long currentMillis = millis();  //timer

  if(MoveDirection == 0 && MoveDirection == lastMoveDirection)  
  {
    forward();
    lastMoveDirection = MoveDirection;
  }
  if(MoveDirection == 0 && MoveDirection != lastMoveDirection && currentMillis - previousMillis > interval )
  {  
    forward();
    lastMoveDirection = MoveDirection;
    previousMillis = currentMillis;
  }
  if(MoveDirection == 1 && MoveDirection == lastMoveDirection)
  {
    backward();
    lastMoveDirection = MoveDirection;
  }
  if(MoveDirection == 1 && MoveDirection != lastMoveDirection && currentMillis - previousMillis > interval )
  {  
    backward();
    lastMoveDirection = MoveDirection;
    previousMillis = currentMillis;
  }
  if(MoveDirection == 2 && MoveDirection == lastMoveDirection)
  {
    left();
    lastMoveDirection = MoveDirection;
  }
  if(MoveDirection == 2 && MoveDirection != lastMoveDirection && currentMillis - previousMillis > interval )
  {  
    left();
    lastMoveDirection = MoveDirection;
    previousMillis = currentMillis;
  }
  if(MoveDirection == 3 && MoveDirection == lastMoveDirection)
  {
    right();
    lastMoveDirection = MoveDirection;
  }
  if(MoveDirection == 3 && MoveDirection != lastMoveDirection && currentMillis - previousMillis > interval )
  {  
    right();
    lastMoveDirection = MoveDirection;
    previousMillis = currentMillis;
  }
}

void forward()
{
  digitalWrite(DIR1, LOW);
  digitalWrite(DIR2, LOW);   
  analogWrite(PWN1, speedLeft);
  analogWrite(PWN2, speedRight);
  digitalWrite(redLed, HIGH);
  digitalWrite(greenLed, LOW);
  digitalWrite(yellowLed, LOW);
  digitalWrite(blueLed, LOW);
}

void stop()
{
  digitalWrite(DIR1, LOW);   
  digitalWrite(DIR2, LOW);   
  analogWrite(PWN1, 0);
  analogWrite(PWN2, 0);
  digitalWrite(redLed, LOW);
  digitalWrite(greenLed, LOW);
  digitalWrite(yellowLed, LOW);
  digitalWrite(blueLed, LOW);
}

void backward()
{
  digitalWrite(DIR1, HIGH);  
  digitalWrite(DIR2, HIGH);   
  analogWrite(PWN1, speedLeft-10); 
  analogWrite(PWN2, speedRight-10); 
  digitalWrite(redLed, LOW);
  digitalWrite(greenLed, HIGH);
  digitalWrite(yellowLed, LOW);
  digitalWrite(blueLed, LOW);
}

void left()
{
  digitalWrite(DIR1, LOW);
  digitalWrite(DIR2, HIGH);   
  analogWrite(PWN1, speedLeft-20); 
  analogWrite(PWN2, speedRight+20); 
  digitalWrite(redLed, LOW);
  digitalWrite(greenLed, LOW);
  digitalWrite(yellowLed, HIGH);
  digitalWrite(blueLed, LOW);
}

void right()
{
  digitalWrite(DIR1, HIGH);
  digitalWrite(DIR2, LOW);   
  analogWrite(PWN1, speedLeft+20);  
  analogWrite(PWN2, speedRight-20); 
  digitalWrite(redLed, LOW);
  digitalWrite(greenLed, LOW);
  digitalWrite(yellowLed, LOW);
  digitalWrite(blueLed, HIGH);
}

void getDistance()
{
  runEvery(20)                      //loop for ultrasonic measurement
  {
    uS = sonar.ping();
    distance = uS / US_ROUNDTRIP_CM;
    if (uS == NO_ECHO)              // if the sensor did not get a ping        
    {
      distance = MAX_DISTANCE;      //so the distance must be bigger then the max vaulue of the sensor
    }
    Serial.print("Ping: ");         //to check distance on the serial monitor
    Serial.print(distance); 
    Serial.println("cm");
  }
}

void sweepServo()
{
  runEvery(servoDelay)                      //this loop determines the servo position
  {
    if(pos < 165 && servoDirection == 0)    //servo to the left
    {                                  
      pos = pos + 5;                        
    } 
    if(pos > 15 && servoDirection == 1)     //servo to the right
    {                                
      pos = pos - 5;
    }    
  }   
  if (pos == 165 )    
  {
    servoDirection = 1;                     //changes direction
  }
  if (pos == 15 )     
  {
    servoDirection = 0;                     //changes direction
  }   
  myservo.write(pos);                       //move servo
}

Here is a pic so far ...

Unfortunately not the best video, but you can see what I mean...

Youtube

Thanks for your help and input.

I have tested a IR sensor only sketch. Thats works too ...

#include <rover_ir_sensors.h> //library ir sensors

#define runEvery(t) for (static typeof(t) _lasttime;(typeof(t))((typeof(t))millis() - _lasttime) > (t);_lasttime += (t))

const int PWN1 = 6;           //right PWN
const int DIR1 = 7;           //right DIR
const int PWN2 =11;           //left PWN
const int DIR2 =12;           //left DIR
const int redLed = 5;         //robot drives forward
const int greenLed = 4;       //robot drives backward
const int yellowLed = 3;      //robot turns left
const int blueLed = 2;        //robot turns right
const int NUM_IR_SENSORS = 4;
const int IR_Led_Pins[ NUM_IR_SENSORS ] = { A0, A0, A1, A1 };   
const int IR_Sensor_Pins[ NUM_IR_SENSORS ] = { A3, A2, A4, A5 };
const int Close_Range_IR_Value = 200;

RoverIRSensors IRSensors( 
    IR_Led_Pins[ 0 ], IR_Led_Pins[ 1 ],
    IR_Led_Pins[ 2 ], IR_Led_Pins[ 3 ],
    IR_Sensor_Pins[ 0 ], IR_Sensor_Pins[ 1 ],
    IR_Sensor_Pins[ 2 ], IR_Sensor_Pins[ 3 ] );


int servoDirection = 0;     //sweeping left or right
int MoveDirection = 0;      //0 = forward, 1 = backward, 2 = left, 3 = right
int lastMoveDirection;      //last direction of the robot
int distanceCenter;     
int distanceLeft;
int distanceRight;
int servoDelay = 55;        //servo sweep speed
const int speedLeft = 150;  //motor speed left
const int speedRight = 140; //motor speed right
long previousMillis = 0;
const int interval = 1000;  //time to switch between the MoveDirections when it detects an obstacle

void setup() {                
  pinMode(PWN1, OUTPUT);  
  pinMode(DIR1, OUTPUT); 
  pinMode(PWN2, OUTPUT); 
  pinMode(DIR2, OUTPUT);
  analogWrite(PWN1, 0);
  analogWrite(PWN2, 0);
  pinMode(5, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(2, OUTPUT);
  pinMode(redLed, OUTPUT); 
  pinMode(greenLed, OUTPUT);
  pinMode(yellowLed, OUTPUT);
  pinMode(blueLed, OUTPUT);
  Serial.begin(9600);       //to use the serial monitor
  delay(2000);              //start delay
}

void loop() {
  
    IRSensors.takeReadings();  // read from the IR sensors  
    int frontLeftIR = IRSensors.lastFrontLeftReading();
    int frontRightIR = IRSensors.lastFrontRightReading();
    int rearLeftIR = IRSensors.lastRearLeftReading();
    int rearRightIR = IRSensors.lastRearRightReading();
        
    Serial.print(frontLeftIR);
    Serial.print(frontRightIR);
    Serial.print(rearLeftIR);
    Serial.print(rearRightIR);
    Serial.print("");
 
 
    if (frontRightIR <= Close_Range_IR_Value && frontLeftIR <= Close_Range_IR_Value)    //no obstacle to see for miles, straight on
    {
      MoveDirection = 0;         //move forward
    }
    else                         //obstacle detected, turn left or right
    {
    if (frontRightIR >= Close_Range_IR_Value)  
    {
      MoveDirection = 2;      //turn left = 2
    }
    if (frontLeftIR >= Close_Range_IR_Value) 
    {
      MoveDirection = 3;      //turn right = 3
    }
    if (frontRightIR >= Close_Range_IR_Value && frontLeftIR >= Close_Range_IR_Value)
    {
      MoveDirection = 3;      //  turn back = 1
    }
  }

  unsigned long currentMillis = millis();  //timer

  if(MoveDirection == 0 && MoveDirection == lastMoveDirection)  
  {
    forward();
    lastMoveDirection = MoveDirection;
  }
  if(MoveDirection == 0 && MoveDirection != lastMoveDirection && currentMillis - previousMillis > interval )
  {  
    forward();
    lastMoveDirection = MoveDirection;
    previousMillis = currentMillis;
  }
  if(MoveDirection == 1 && MoveDirection == lastMoveDirection)
  {
    backward();
    lastMoveDirection = MoveDirection;
  }
  if(MoveDirection == 1 && MoveDirection != lastMoveDirection && currentMillis - previousMillis > interval )
  {  
    backward();
    lastMoveDirection = MoveDirection;
    previousMillis = currentMillis;
  }
  if(MoveDirection == 2 && MoveDirection == lastMoveDirection)
  {
    left();
    lastMoveDirection = MoveDirection;
  }
  if(MoveDirection == 2 && MoveDirection != lastMoveDirection && currentMillis - previousMillis > interval )
  {  
    left();
    lastMoveDirection = MoveDirection;
    previousMillis = currentMillis;
  }
  if(MoveDirection == 3 && MoveDirection == lastMoveDirection)
  {
    right();
    lastMoveDirection = MoveDirection;
  }
  if(MoveDirection == 3 && MoveDirection != lastMoveDirection && currentMillis - previousMillis > interval )
  {  
    right();
    lastMoveDirection = MoveDirection;
    previousMillis = currentMillis;
  }
}

void forward()
{
  digitalWrite(DIR1, LOW);
  digitalWrite(DIR2, LOW);   
  analogWrite(PWN1, speedLeft);
  analogWrite(PWN2, speedRight);
  digitalWrite(redLed, HIGH);
  digitalWrite(greenLed, LOW);
  digitalWrite(yellowLed, LOW);
  digitalWrite(blueLed, LOW);
}

void stop()
{
  digitalWrite(DIR1, LOW);   
  digitalWrite(DIR2, LOW);   
  analogWrite(PWN1, 0);
  analogWrite(PWN2, 0);
  digitalWrite(redLed, LOW);
  digitalWrite(greenLed, LOW);
  digitalWrite(yellowLed, LOW);
  digitalWrite(blueLed, LOW);
}

void backward()
{
  digitalWrite(DIR1, HIGH);  
  digitalWrite(DIR2, HIGH);   
  analogWrite(PWN1, speedLeft-10); 
  analogWrite(PWN2, speedRight+10); 
  digitalWrite(redLed, LOW);
  digitalWrite(greenLed, HIGH);
  digitalWrite(yellowLed, LOW);
  digitalWrite(blueLed, LOW);
}

void left()
{
  digitalWrite(DIR1, LOW);
  digitalWrite(DIR2, HIGH);   
  analogWrite(PWN1, speedLeft-30); 
  analogWrite(PWN2, speedRight+30); 
  digitalWrite(redLed, LOW);
  digitalWrite(greenLed, LOW);
  digitalWrite(yellowLed, HIGH);
  digitalWrite(blueLed, LOW);
}

void right()
{
  digitalWrite(DIR1, HIGH);
  digitalWrite(DIR2, LOW);   
  analogWrite(PWN1, speedLeft+30);  
  analogWrite(PWN2, speedRight-30); 
  digitalWrite(redLed, LOW);
  digitalWrite(greenLed, LOW);
  digitalWrite(yellowLed, LOW);
  digitalWrite(blueLed, HIGH);
}

The problem comes when i combine ultrasonic and IRsensor :frowning:

Update 8)

Youtube !

IR remote and LCD display added.

RoverIR.txt (9.69 KB)

My only question is why doesn't it reverse the motors (drive the motors in opposite directions, which is one of the main features of a tank track vehicle) and turn left or right after backing away from the wall ? That would be a simple code modification.

raschemmel:
My only question is why doesn't it reverse the motors (drive the motors in opposite directions, which is one of the main features of a tank track vehicle) and turn left or right after backing away from the wall ? That would be a simple code modification.

Not really understand what you mean. To rotate the Rover the motors drive in opposite directions! For turning right the tracks on the right drives back and the tracks on the left side drives forward and for turning left vise versa .... !?

My question is why doesn't the rover spin left or right in one place in the video ? It never turns in the video.
It just drives forward and backs up and repeats. To turn left or right you rotate both motor shafts the the same direction CW or CCW . (looking directly at the shaftside of the motor). That never happened in that video. Why not ?

For turning right the tracks on the right drives back and the tracks on the left side drives forward and for turning left vise versa .... !?

That's correct but I never saw it happen.

Ok, the video is not the best quality, but when you look second 10 to second 12 maybe you can see when to Rover turns to the left.

NEVERMIND. I was watching the WRONG video ! I was watching the video in Reply#3. I finally noticed the "update" video and it does exactly what I was asking about. Nice job !

raschemmel:
Nice job !

Thanks :wink:

Selfmade LCD Shield with IR Remote and Bluetooth and LED's for direction.

Code is updated, better performance with IR-sensors :wink:

Rover501.txt (11 KB)

Cool Project !

Any news ?

Thanks :slight_smile:

I made a remote control Klick ! with Arduino Uno & joystick shield to control the Rover and gripper. The LCD shows the current of the motors and the battery voltages of the battery from the Rover.

Way cool !

Rover 5 with gripper !

Youtube !

AndreasVan:
Rover 5 with gripper !

Youtube !

Cool! Great work!

Is it possible to get some detail pics? And what kind of servo you use to lift and rotate the arm. Looks like something special ...

Robia42:
Cool! Great work!

Thanks 8)

Robia42:
Is it possible to get some detail pics? And what kind of servo you use to lift and rotate the arm. Looks like something special ...

There is nothing special. Lift and rotate are two separat Servos. For lifting I have a standard size Servo and for rotating a mini Servo. All servos have metal gears!

Here some pics.