RC Car to robot

Hello guys! My name is CreativeCorpse and this is my very first "robot" project. I know that there are probably 5000 diffrent versions of this same exact robot but i dont care...this one is mine haha. Basically i just used a RC car that i found in my niece's box of old toys and took the board out and replaced it with my Arduino Uno r3 with the motor sheild and then ran the motor wires into the sheild and wallah!

Navigates around the room using the PING sensor to look out in front of it. as soon as an object gets within 12 inches it backs up and turns left

  • Actuators / output devices: 2 dc motors
  • CPU: Arduino Uno R3
  • Power source: 2 9v Batterys
  • Programming language: Arduino C
  • Sensors / input devices: UltraSonic PING sensor
  • Target environment: indoor

This is a companion discussion topic for the original entry at https://community.robotshop.com/robots/show/rc-car-to-robot

**lol **

man chikenparmi sounds awesome. i shouldnt have gone to mcdonalds haha

what time is it where your at man?

i live in Texas, USA…its like 8 pm here lol

6677 is

a UK resident. 8pm your time means it is 1 or 2 am his time. He is a real live college student n stuff, I think. chickenparmi is an Aussie. I doubt you would enjoy eating him, fried or not. :stuck_out_tongue:

Congrats on your first bot.

I have 4 or 5 “carcasses” (pun intended) laying about waiting on conversion.

Building it yourself and learning to program it is the only way to go. :slight_smile:

ERR!!

for some reason the bot just keeps moving foward, then back…it still turns but it is acting like its not reading the sensor…im thinking of putting it on top of the bot

The code

Okay here is the code that i wrote for this bot…its very basic. for some reason it seems as if the sensor is not cooperating with the motors…any ideas?

 

const int pingPin = 7;

 

void setup() {

  pinMode(12, OUTPUT);

  pinMode(13, OUTPUT);

 

  pinMode(9, OUTPUT);

  pinMode(8, OUTPUT);

 

  digitalWrite(9, LOW);

  digitalWrite(8, HIGH);

 

  analogWrite(3, 175);

 

  digitalWrite(12, HIGH);

}

 

void loop() {

  long duration, inches, cm;

 

  pinMode(pingPin, OUTPUT);

  digitalWrite(pingPin, LOW);

  delayMicroseconds(2);

  digitalWrite(pingPin, HIGH);

  delayMicroseconds(5);

  digitalWrite(pingPin, LOW);

 

  pinMode(pingPin, INPUT);

  duration = pulseIn(pingPin, HIGH);

 

  inches = microsecondsToInches(duration);

 

  if(inches < 12){

    digitalWrite(9, HIGH);

    delay(100);

 

    digitalWrite(8, LOW);

    digitalWrite(13, LOW);

    analogWrite(11, 255);

 

    digitalWrite(9, LOW);

    digitalWrite(12, LOW);

    analogWrite(3, 175);

    delay(2000);

 

    digitalWrite(8, HIGH);

    digitalWrite(9, HIGH);

  }

 

  else{

    digitalWrite(12, HIGH);

    digitalWrite(9, LOW);

    analogWrite(3, 175);

  }

 

  delay(100);

}

 

long microsecondsToInches(long microseconds)

{

  return microseconds / 74 / 2;

}

**Looking over your code is still difficult to follow as **

you have so many magic numbers floating around. Where do pins 3, 11, 8, 9, 12, and 13 connect to? Are 3 and 11 really PWM?

**haha sorry **

i guess i forgot to mention that i am using a motor sheild…sorry bout that.

here are the pins, there functions, and the respective numbers

pin 12 = channel A, or the drive motor

pin 13= channel b, or the turn motor

pin 8= channel a brake

pin 9= channel b brake

and yes you are correct…pins 3 and 11 are the PWM

After responding to a post with a motor driver board just like

yours, I now see something else that should be mentioned. The L298 motor driver chip is seriously inefficient when it comes to pushing power it is fed to the motors.

**https://www.sparkfun.com/datasheets/Robotics/L298_H_Bridge.pdf The bottom of page 3 mentions total drop. Notice 1.8v min to 3.2v max for 1A and up to 4.9v max for 2A. I am pretty sure this is the ~2v drop I have read about that is expected when using this driver.

i think your right

ive actually been having issues with a voltage drop with this sheild. its running fine but it seems to draw more power out of the channel B then A. im going to hook up a multimeter and test it out…ive also been wroking with obstacle avoidance and i cant seem to get the board to compare the distances…heres the code if you wanna take a look

 

#include<Servo.h>

const int pingPin = 7;

const int dangerThresh = 12;

int leftDistance, rightDistance;

Servo panMotor;

long duration;

 

 

void setup() {

 

  pinMode(12, OUTPUT);

  pinMode(13, OUTPUT);

 

  pinMode(9, OUTPUT);

  pinMode(8, OUTPUT);

 

  digitalWrite(9, LOW);

  digitalWrite(8, HIGH);

 

  digitalWrite(12, HIGH);

 

  analogWrite(3, 175);

 

  panMotor.attach(11);

  panMotor.write(90);

}

 

 

 

void loop() {

  int distanceFwd = ping();

  if(distanceFwd > dangerThresh) {

    digitalWrite(12, HIGH);

    digitalWrite(9, LOW);

    analogWrite(3, 175);

  }

 

  else {

    panMotor.write(0);

    delay(500);

    rightDistance = ping();

    delay(500);

    panMotor.write(160);

    delay(700);

    leftDistance = ping();

    delay(500);

    panMotor.write(90);

    delay(100);

    compareDistance();

  }

}

 

void compareDistance() {

  if(leftDistance > rightDistance) {

    digitalWrite(8, LOW);

    digitalWrite(13, HIGH);

    analogWrite(11, 255);

    delay(500);

  }

 

  else if(rightDistance > leftDistance) {

    digitalWrite(8, LOW);

    digitalWrite(13, LOW);

    analogWrite(11, 255);

    delay(500);

  }

  else {

    digitalWrite(12, HIGH);

    digitalWrite(9, LOW);

    analogWrite(3, 175);

  }

}

 

long ping() {

  pinMode(pingPin, OUTPUT);

  digitalWrite(pingPin, LOW);

  delayMicroseconds(2);

  digitalWrite(pingPin, HIGH);

  delayMicroseconds(5);

  digitalWrite(pingPin, LOW);

 

  pinMode(pingPin, INPUT);

  duration = pulseIn(pingPin, HIGH);

 

  return duration / 29 / 2;

 }

Look here -->

http://pastebin.com/uQvsdDke

See if that works and maybe makes more sense. You could replace the const int w/ const byte, or, #define and then lose the = and the ; . Your call.

Similar project

We built a similar project.  However, we installed an Android device onto a RC car and used an IOIO board instead to control it autonomously. Here is the preliminary result:

http://youtu.be/vkvkfcqEUkk