Go Down

Topic: ArdBot Code (Read 64 times) previous topic - next topic

kwozz48

Jun 07, 2015, 09:06 pm Last Edit: Jun 07, 2015, 09:07 pm by kwozz48
I'm building the ArdBot robot that's featured on robotoid.com and I'm having trouble implementing the software. This is the first robot I've ever built, and the first time I've ever used an Arduino board (I'm using the Uno for this project), so I was hoping I could get some help from the community. I attached a document of the code that I'm using (I got this directly from the robotoid website), so you can take a look at that if that will help.
If I need to provide more information about what my robot is supposed to do, just let me know, but it basically is a very simple autonomous rover, similar to a Roomba. I'm just wondering why the robot isn't working. I'm nearly positive all of the electrical connects are correct, but I'm not getting any response from it. It has two "feelers" on the front that function as switches, and when one of these are pressed, the robot will reverse direction, turn, and continue moving forward (this simulates hitting a wall). All I do to implement the software is type it up in the Arduino IDE on my mac, verify it to make sure there are no errors, then I plug the computer into the Arduino Uno, using a USB cable, and then I click the "upload" button on the IDE. After that I get no response from the robot. So what am I doing wrong?

Thanks for your time, and let me know if I need to clear anything up.

kwozz48

For some reason the code attachment didn't work, so here it is:
/*
 ArdBot bumper switch demo
 Requires Arduino IDE version 0017
  or later (0019 or later preferred)
*/

#include <Servo.h>

const int ledPin =  13;  // Built-in LED
const int bumpLeft = 2;  // Left bumper pin 2
const int bumpRight = 3; // Left bumper pin 3
int pbLeft = 0;          // Var for left bump
int pbRight = 0;         // Var for left bump
Servo servoLeft;         // Define left servo
Servo servoRight;        // Define right servo
                 
void setup() {
  servoLeft.attach(10);  // Left servo pin D10
  servoRight.attach(9);  // Right servo pin D9
  // Set pin modes
  pinMode(bumpLeft, INPUT); 
  pinMode(bumpRight, INPUT); 
  pinMode(ledPin, OUTPUT);
}
 
void loop() {
  forward();              // Start forward
  // Test bumper switches
  pbLeft = digitalRead(bumpLeft); 
  pbRight = digitalRead(bumpRight);

  // Show LED indicator
  showLED();
 
  // If left bumper hit
  if (pbLeft == HIGH) {
   reverse();
   delay(500);
   turnRight();
   delay(1500);
  }
 
  // If right bumper hit
  if (pbRight == HIGH) {
   reverse();
   delay(500);
   turnLeft();
   delay(1500);
  }
}

// Motion routines
void forward() {
  servoLeft.write(180);
  servoRight.write(0);
}

void reverse() {
  servoLeft.write(0);
  servoRight.write(180);
}

void turnRight() {
  servoLeft.write(180);
  servoRight.write(180);
}

void turnLeft() {
  servoLeft.write(0);
  servoRight.write(0);
}

void stopRobot() {
  servoLeft.write(90);
  servoRight.write(90);
}

void showLED() {
  // Show LED if a bumper is hit
  if (pbRight == HIGH || pbLeft == HIGH) {     
    // Turn LED on
    digitalWrite(ledPin, HIGH);
  }
  else {
    // Turn LED off
    digitalWrite(ledPin, LOW);
  }   
}

Robin2

This is how your code should be presented - using the code button '</>'
Code: [Select]
/*
 ArdBot bumper switch demo
 Requires Arduino IDE version 0017
  or later (0019 or later preferred)
*/

#include <Servo.h>

const int ledPin =  13;  // Built-in LED
const int bumpLeft = 2;  // Left bumper pin 2
const int bumpRight = 3; // Left bumper pin 3
int pbLeft = 0;          // Var for left bump
int pbRight = 0;         // Var for left bump
Servo servoLeft;         // Define left servo
Servo servoRight;        // Define right servo
                 
void setup() {
  servoLeft.attach(10);  // Left servo pin D10
  servoRight.attach(9);  // Right servo pin D9
  // Set pin modes
  pinMode(bumpLeft, INPUT);
  pinMode(bumpRight, INPUT);
  pinMode(ledPin, OUTPUT);
}
 
void loop() {
  forward();              // Start forward
  // Test bumper switches
  pbLeft = digitalRead(bumpLeft);
  pbRight = digitalRead(bumpRight);

  // Show LED indicator
  showLED();
 
  // If left bumper hit
  if (pbLeft == HIGH) {
   reverse();
   delay(500);
   turnRight();
   delay(1500);
  }
 
  // If right bumper hit
  if (pbRight == HIGH) {
   reverse();
   delay(500);
   turnLeft();
   delay(1500);
  }
}

// Motion routines
void forward() {
  servoLeft.write(180);
  servoRight.write(0);
}

void reverse() {
  servoLeft.write(0);
  servoRight.write(180);
}

void turnRight() {
  servoLeft.write(180);
  servoRight.write(180);
}

void turnLeft() {
  servoLeft.write(0);
  servoRight.write(0);
}

void stopRobot() {
  servoLeft.write(90);
  servoRight.write(90);
}

void showLED() {
  // Show LED if a bumper is hit
  if (pbRight == HIGH || pbLeft == HIGH) {     
    // Turn LED on
    digitalWrite(ledPin, HIGH);
  }
  else {
    // Turn LED off
    digitalWrite(ledPin, LOW);
  }   
}


You obviously forgot to read the "how to use the Forum"


I can't offer any suggestions based on the information you have given. There are two many possible sources of problems. If you are confident that you have copied the code properly the probably cause is a wiring fault or an inadequate power supply. Have the servos got a separate power supply from the Uno and is the servo GND connected to the Arduino GND.

Can you make a pencil drawing of all the wiring connections and post a photo of the drawing. I want to see how YOU have things connected - not how they should be connected.

The code suggests that the onboard LED should light when the bumper is touched - is that happening?

What happens if you try the device with the wheels off the ground?

...R

Go Up