Loading...
Pages: [1]   Go Down
Author Topic: QTI Sensors  (Read 448 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi i am working on a robot that will follow a line at the moment i am trying to figure out how to make the QTI parallax sensors work on the arduino the code i am using is as follows:

void setup()
{
Serial.begin(9600);
}

void loop()
{
Serial.println(RCTime(13)); // Connects to pin 13, displays results

}
long RCTime(int sensorIn)
{
long duration = 0;
pinMode(sensorIn, OUTPUT); // Sets pin as OUTPUT
digitalWrite(sensorIn, HIGH); // Pin HIGH
//delay(1); // Waits for 1 millisecond
pinMode(sensorIn, INPUT); // Sets pin as INPUT
digitalWrite(sensorIn, LOW); // Pin LOW
while(digitalRead(sensorIn)){ // Waits for the pin to go LOW
duration++;
}
return duration; // Returns the duration of the pulse
}




i want to know if there is a way to integrate this into a whole code that so that i can use the sensors to follow a line and turning when according to the sensors reading  the motor code i am using is as follows:


int motorpin1 = 3;                  //define digital output pin no.

int motorpin2 = 4;                  //define digital output pin no.

int motorpin5 = 5;                 // define digital output pin no.

int motorpin7 =6;                  // define digital output pin no.

void setup () {

  pinMode(motorpin1,OUTPUT);        //set pin 3 as output

  pinMode(motorpin2,OUTPUT);        // set pin 4 as output
 
  pinMode(motorpin5,OUTPUT);        // set pin 5 as output
 
  pinMode(motorpin7,OUTPUT);        // set pin 7 as output

}

void loop () {

  digitalWrite(motorpin1,LOW);

  digitalWrite(motorpin2,HIGH);
 
  delay(100);
 
  digitalWrite(motorpin5,LOW);
 
  digitalWrite(motorpin7,HIGH);
  delay (3000);




 
  digitalWrite(motorpin1,HIGH);
 
  digitalWrite(motorpin2,LOW);
 
  delay(100);
 
  digitalWrite(motorpin5,HIGH);
 
  digitalWrite(motorpin7,LOW);
 
  delay(100);
 
}

any help or suggestions?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

also for the motors because they are DC- Motors i connected them up to a L-293D chip
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 311
Posts: 35470
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
return duration; // Returns the duration of the pulse
In what units? Counting as fast as the processor can until the return echo is received provides you with no clue as to how long the pulse took to arrive, or how far the pulse had to travel.

As a result, you have a useless, dimensionless value.

Why you are (incorrectly) trying to replicate the pulseIn() method, which provides a dimensioned value, escapes me.

The comments in the code are wrong, anyway. There are no pulses being sent/timed.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

for this code in particular there was no units per say and to be frank i found this code on the net and tried messing around with it... now i just need some advice on wheter to use analog inuputs or digital inputs and what code to use...
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 137
Posts: 19001
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Any links to the sensor?
Logged

Pete, it's a fool looks for logic in the chambers of the human heart.

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Any links to the sensor?

http://www.parallax.com/tabid/768/ProductID/100/Default.aspx
- sensors

http://communityofrobots.com/tutorial/kawal/how-drive-dc-motor-using-l293d-arduino
-motors wiring and part of the code.... i wired it to fit to sensors
Logged

Pages: [1]   Go Up
Print
 
Jump to: