Let's Make Robots!

Trying the arduino

So i got bored tonight and decided to try and use the one and only arduino i bought which has been laying around for a few months. I made a really quick chassis out of shapelock then used some zipties to hold everything down (literally everything). Wired up a 293d, and i think a sharp? Looked through some code other users had posted and tried to get my robot to work. The motors run fine, i'm using a 6v battery pack for the motors while having it plugged into my comp to power the sharp. For some reason, and i'm almost positive it's the code, the sharp won't respond. I was wondering if someone could just quickly look over my code and see where i went wrong. It's just a simple program that has the robot run forward until it sees a wall, stops, turns right, and then goes forward again. But first pics

DSC_0128.jpg

DSC_0127.jpg

I hate to do this but i can't seem to figure it out

int motor5 = 5; //
int motor6 = 6; //
int motor8 = 8; //
int motor9 = 9; //

void setup() {
  pinMode(motor6, OUTPUT);
  pinMode(motor5, OUTPUT);
  pinMode(motor8, OUTPUT);
  pinMode(motor9, OUTPUT);
}

void loop() {
  int distance = analogRead(1);
  if (distance < 5)
  {
     stopmot();
    delay (500);
    reverse();
    delay (500);
    right();
    delay (2000);
  }
  else
  {
    forward();
  }
}
void forward()
{
  digitalWrite(6,HIGH);
  digitalWrite(5,LOW);
  digitalWrite(8,HIGH);
  digitalWrite(9,LOW);
}
void stopmot()
{
  digitalWrite(5,LOW);
  digitalWrite(6,LOW);
  digitalWrite(8,LOW);
  digitalWrite(9,LOW);
}
void reverse()
{
  digitalWrite(6,LOW);
  digitalWrite(5,HIGH);
  digitalWrite(8,LOW);
  digitalWrite(9,HIGH);
}
void right()
{
  digitalWrite(6,LOW);
  digitalWrite(5,HIGH);
  digitalWrite(8,HIGH);
  digitalWrite(9,LOW);
}

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
how about u debug your sensor using the serial.print comand that way u can see if your sensor is working or not 

well, i dont really know, but  in 


void setup() {
  pinMode(motor6, OUTPUT); 
  pinMode(motor5, OUTPUT);
  pinMode(motor8, OUTPUT);
  pinMode(motor9, OUTPUT);

  
}

u may need to declair the pinmode for the senser so

pinMode ( distance,INPUT);

and at the start of the code

int distance= 1;

 

but im just guessing  

if the sensor is an analog sensor then it shouldnt be defined as an input. however the pin hasnt been labeled as for the sensor so that could be the problem