Show Posts
Pages: [1] 2 3 ... 6
1  Using Arduino / Programming Questions / Re: Help with robot code on: June 05, 2014, 10:36:06 pm
i will remember to use the input_pullup code though when i replace the sensor and on future projects as their teacher is thinking of having me come back next year with another robot and my son wants me to present a bipedal robo when he goes into 1st grade next year
2  Using Arduino / Programming Questions / Re: Help with robot code on: June 05, 2014, 10:34:01 pm
well after reading the parralax forums regarding symptoms of a ping sensor failure im going to take the safe route and replace the sensor before moving ahead in the project although i am happy to say that little scrapper the robot made the kindergarten class very happy this morning so happy infact they almost missed recess asking questions about how he was built how he works and what his components do
3  Using Arduino / Programming Questions / Re: Help with robot code on: June 05, 2014, 10:09:04 pm
im using two parralax continuous rotation servos and an eflite micro servo all of which have worked fine with the sensor together in previous projects
4  Using Arduino / Programming Questions / Re: Help with robot code on: June 05, 2014, 09:47:03 pm
well i will try again right now i believe it is a hardware problem because even running the ping example is returning erroneous values
5  Using Arduino / Programming Questions / Re: Help with robot code on: June 05, 2014, 12:17:52 am
i think the problem is somewhere in this part of the code because whenever the "neck" turns to the left or right the ping sensor gives a delay then returns a zero and centers the "neck"

Code:
void loop()
{
   
  int distanceFwd = ping(); //tells the robot distance forward
  if (distanceFwd>dangerThresh) //if path is clear
  {
    leftMotor.write(LForward); //move forward
    rightMotor.write(RForward); //move forward
  }
  else //if path is blocked
  {
    leftMotor.write(LNeutral);  //stop forward motion
    rightMotor.write(RNeutral); //stop forward motion
    panMotor.write(0); // turn ping sesor right
    delay(500);
    rightDistance = ping(); //scan to the right
    delay(500);
    panMotor.write(180);  //turn ping sensor left
    delay(500);
    leftDistance = ping(); //scan to the left
    delay(500);
    panMotor.write(90); //return to center
    delay(100);
    compareDistance();  //determine the distance on both sides
    }
}
void compareDistance()
{
  if (leftDistance>rightDistance) //if left is less obstructed
  {
    leftMotor.write(LBackward); //turn left
    rightMotor.write(RForward); //turn left
    delay(500);
  }
  else if (rightDistance>leftDistance) //if right is less obstructed
  {
    leftMotor.write(LForward);  //turn right
    rightMotor.write(RBackward); //turn right
    delay(500);
  }
   else //if they are equally obstructed
  {
    leftMotor.write(LForward); //turn 180 degrees
    rightMotor.write(RBackward); //turn 180 degrees
    delay(500);
  }
}
6  Using Arduino / Programming Questions / Re: Help with robot code on: June 05, 2014, 12:12:27 am
ok i tried that and it made it even worse
7  Using Arduino / Programming Questions / Re: Help with robot code on: June 04, 2014, 09:34:00 pm
as for the duration variables are you referring to the long duration; part of the code?
8  Using Arduino / Programming Questions / Re: Help with robot code on: June 04, 2014, 09:29:17 pm
once the "neck" moves left or right ping returns a 0 then when the "neck" is centered ping return normal values also i have noticed that the ping has been randomly returning false values while moving forward
9  Using Arduino / Programming Questions / Re: Help with robot code on: June 04, 2014, 08:22:29 pm
Umm im not sure how to answer that i used the ping code from arduino library and i need the output for the display to be a number
10  Using Arduino / Programming Questions / Re: Help with robot code on: June 04, 2014, 07:19:26 pm
so i still have the same problem with ping returning a zero after the pan servo moves it left or right i changed the delays and still the same thing

Code:
#include<Servo.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(7, 8, 9, 10, 11, 12); // lcd screen pins
const int pingPin = 4; //declares the ping pin
//const int irPin = 0;  //Sharp infrared sensor pin
const int RForward = 180; //full speed forward
const int RBackward = 0; //full speed reverse
const int LForward = RBackward; //this decides the motor control
const int LBackward = RForward; //this decides the motor control
const int RNeutral = 90; //nuetral for motor
const int LNeutral = 90; //nuetral for motor
const int dangerThresh = 4; //threshold for obstacles (in)
int leftDistance, rightDistance; //distances on either side
Servo panMotor;  //this is the "neck" of the robot
Servo leftMotor; //declare left servo motor
Servo rightMotor; //declare right servo motor
long duration; //time it takes to recieve PING))) signal

void setup()
{
  Serial.begin(9600); //allows for serial monitoring
  lcd.begin(16, 2); //turn on the lcd screen
  lcd.print("Hello Jason"); //threw this in for fun
  delay(250);
  lcd.clear();  //clears the lcd
  lcd.print("ScrapBot V1.0");  //threw this in for fun
  delay(250);
  lcd.clear();  //clears the lcd
  lcd.print("SCRAPPER SAYS HI");  //threw this in for fun
  delay(250);
  lcd.clear();  //clears the lcd
  rightMotor.attach(5); //attach right servo motor to proper pin
  leftMotor.attach(6); //attach left servo motor to proper pin
  panMotor.attach(3); //attach pan servo motor to proper pin
  panMotor.write(90); //center the "neck" of the robot
  delay(50);

 
}


void loop()
{
   
  int distanceFwd = ping(); //tells the robot distance forward
  if (distanceFwd>dangerThresh) //if path is clear
  {
    leftMotor.write(LForward); //move forward
    rightMotor.write(RForward); //move forward
  }
  else //if path is blocked
  {
    leftMotor.write(LNeutral);  //stop forward motion
    rightMotor.write(RNeutral); //stop forward motion
    panMotor.write(0); // turn ping sesor right
    delay(500);
    rightDistance = ping(); //scan to the right
    delay(500);
    panMotor.write(180);  //turn ping sensor left
    delay(500);
    leftDistance = ping(); //scan to the left
    delay(500);
    panMotor.write(90); //return to center
    delay(100);
    compareDistance();  //determine the distance on both sides
    }
}
void compareDistance()
{
  if (leftDistance>rightDistance) //if left is less obstructed
  {
    leftMotor.write(LBackward); //turn left
    rightMotor.write(RForward); //turn left
    delay(500);
  }
  else if (rightDistance>leftDistance) //if right is less obstructed
  {
    leftMotor.write(LForward);  //turn right
    rightMotor.write(RBackward); //turn right
    delay(500);
  }
   else //if they are equally obstructed
  {
    leftMotor.write(LForward); //turn 180 degrees
    rightMotor.write(RBackward); //turn 180 degrees
    delay(500);
  }
}
long ping()  //ping sensor programming from library
{
  long duration, inches;
  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);
  lcd.print(inches);
  lcd.print("in to obstacle");  //displays ditance on the lcd
  delay(100);
  lcd.clear();  //clears the lcd
  delay(100);
  Serial.print(inches);
  Serial.print("in, ");
  Serial.println(); // this is for serial monitoring of the ping signal
  return inches; //return measurement for ping sensor
}
long microsecondsToInches(long microseconds)
{
  return microseconds / 74 / 2;
}

11  Using Arduino / Programming Questions / Re: Help with robot code on: June 04, 2014, 06:01:26 pm
ok so far its kind of working but i still get no value showing on the lcd screen when it turns right or left
12  Using Arduino / Programming Questions / Re: Help with robot code on: June 04, 2014, 05:10:14 pm
I think it had to do with the delays getting ready to retest it and the ping sensor is mounted on a servo for turning
13  Using Arduino / Programming Questions / Help with robot code on: June 04, 2014, 04:51:38 pm
so i have made an obstacle avoidance robot but there seems to be a problem as it will not return a value when the ping sensor turns left or right

Code:
#include<Servo.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(7, 8, 9, 10, 11, 12); // lcd screen pins
const int pingPin = 4; //declares the ping pin
const int irPin = 0;  //Sharp infrared sensor pin
const int RForward = 180; //full speed forward
const int RBackward = 0; //full speed reverse
const int LForward = RBackward; //this decides the motor control
const int LBackward = RForward; //this decides the motor control
const int RNeutral = 90; //nuetral for motor
const int LNeutral = 90; //nuetral for motor
const int dangerThresh = 2; //threshold for obstacles (in)
int leftDistance, rightDistance; //distances on either side
Servo panMotor;  //this is the "neck" of the robot
Servo leftMotor; //declare left servo motor
Servo rightMotor; //declare right servo motor
long duration; //time it takes to recieve PING))) signal

void setup()
{
  Serial.begin(9600); //allows for serial monitoring
  lcd.begin(16, 2); //turn on the lcd screen
  lcd.print("Hello Jason"); //threw this in for fun
  delay(250);
  lcd.clear();  //clears the lcd
  lcd.print("Activating KITT");  //threw this in for fun
  delay(250);
  lcd.clear();  //clears the lcd
  rightMotor.attach(5); //attach right servo motor to proper pin
  leftMotor.attach(6); //attach left servo motor to proper pin
  panMotor.attach(3); //attach pan servo motor to proper pin
  panMotor.write(90); //center the "neck" of the robot
  delay(50);
  lcd.print("KITT Online");  //threw this in for fun
  delay(250);
  lcd.clear();  //clears the lcd
 
}


void loop()
{
   
  int distanceFwd = ping(); //tells the robot distance forward
  if (distanceFwd>dangerThresh) //if path is clear
  {
    leftMotor.write(LForward); //move forward
    rightMotor.write(RForward); //move forward
  }
  else //if path is blocked
  {
    leftMotor.write(LNeutral);  //stop forward motion
    rightMotor.write(RNeutral); //stop forward motion
    panMotor.write(0); // turn ping sesor right
    delay(1000);
    rightDistance = ping(); //scan to the right
    delay(1000);
    panMotor.write(180);  //turn ping sensor left
    delay(1000);
    leftDistance = ping(); //scan to the left
    delay(1000);
    panMotor.write(90); //return to center
    delay(1000);
    compareDistance();  //determine the distance on both sides
  }
}
void compareDistance()
{
  if (leftDistance>rightDistance) //if left is less obstructed
  {
    leftMotor.write(LBackward); //turn left
    rightMotor.write(RForward); //turn left
    delay(100);
  }
  else if (rightDistance>leftDistance) //if right is less obstructed
  {
    leftMotor.write(LForward);  //turn right
    rightMotor.write(RBackward); //turn right
    delay(1000);
  }
   else //if they are equally obstructed
  {
    leftMotor.write(LForward); //turn 180 degrees
    rightMotor.write(RBackward); //turn 180 degrees
    delay(1000);
  }
}
long ping()  //ping sensor programming from library
{
  long duration, inches;
  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);
  lcd.print(inches);
  lcd.print("in to obstacle");  //displays ditance on the lcd
  delay(100);
  lcd.clear();  //clears the lcd
  delay(100);
  Serial.print(inches);
  Serial.print("in, ");
  Serial.println(); // this is for serial monitoring of the ping signal
  return inches; //return measurement for ping sensor
}
long microsecondsToInches(long microseconds)
{
  return microseconds / 74 / 2;
}


I have to present this to a bunch of kids tomorrow and just realized this error please help
14  Topics / Robotics / Re: need some help with code on: September 01, 2013, 06:12:24 pm
oh my i feel like an idiot went back through my wiring and found a loose ground it works now
15  Topics / Robotics / Re: need some help with code on: August 30, 2013, 09:27:58 pm
uh oh i think something broke i went to test it out again to show some buddies and for some reason my right servo does not stop when the danger thresh hold is met the rest of the parts do what they are supposed to

Code:
#include<Servo.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(7, 8, 9, 10, 11, 12); // lcd screen pins
const int pingPin = 4; //declares the ping pin
const int irPin = 0;  //Sharp infrared sensor pin
const int RForward = 0; //full speed forward
const int RBackward = 180; //full speed reverse
const int LForward = RBackward; //this decides the motor control
const int LBackward = RForward; //this decides the motor control
const int RNeutral = 90; //nuetral for motors
const int LNeutral = 90; //constants for motor speed
const int dangerThresh = 5; //threshold for obstacles (in cm)
int leftDistance, rightDistance; //distances on either side
Servo panMotor;  //this is the "neck" of the robot
Servo leftMotor; //declare left servo motor
Servo rightMotor; //declare right servo motor
long duration; //time it takes to recieve PING))) signal

void setup()
{
  Serial.begin(9600); //allows for serial monitoring
  lcd.begin(16, 2); //turn on the lcd screen
  lcd.print("Hello Jason");
  delay(250);
  lcd.clear();
  lcd.print("Activating KITT");
  delay(250);
  lcd.clear();
  rightMotor.attach(5); //attach left servo motor to proper pin
  leftMotor.attach(6); //attach right servo motor to proper pin
  panMotor.attach(3); //attach pan servo motor to proper pin
  panMotor.write(90); //center the "neck" of the robot
  delay(50);
  lcd.print("KITT Online");
  delay(250);
  lcd.clear();
 
}


void loop()
{
   
  int distanceFwd = ping(); //tells the robot distance forward
  if (distanceFwd>dangerThresh) //if path is clear
  {
    leftMotor.write(LForward);
    rightMotor.write(RForward); //move forward
  }
  else //if path is blocked
  {
    leftMotor.write(LNeutral);
    rightMotor.write(RNeutral); //stop forward motion
    panMotor.write(0);
    delay(100);
    rightDistance = ping(); //scan to the right
    delay(100);
    panMotor.write(180);
    delay(100);
    leftDistance = ping(); //scan to the left
    delay(100);
    panMotor.write(90); //return to center
    delay(100);
    compareDistance();
  }
}
void compareDistance()
{
  if (leftDistance>rightDistance) //if left is less obstructed
  {
    leftMotor.write(LBackward);
    rightMotor.write(RForward); //turn left
    delay(100);
  }
  else if (rightDistance>leftDistance) //if right is less obstructed
  {
    leftMotor.write(LForward);
    rightMotor.write(RBackward); //turn right
    delay(100);
  }
   else //if they are equally obstructed
  {
    leftMotor.write(LForward);
    rightMotor.write(RBackward); //turn 180 degrees
    delay(100);
  }
}
long ping()
{
  long duration, inches;
  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);
  lcd.print(inches);
  lcd.print("in to obstacle");
  delay(100);
  lcd.clear(); 
  delay(100);
  Serial.print(inches);
  Serial.print("in, ");
  Serial.println(); // this is for serial monitoring of the ping signal
  return inches;
}
long microsecondsToInches(long microseconds)
{
  return microseconds / 74 / 2;
}

Pages: [1] 2 3 ... 6