Pages: [1]   Go Down
Author Topic: Grid follower robot. Need help...  (Read 2648 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi i have build a line follower robot with the help of six analog ir reflectant sensor array. it works good following the line. Now i want to modify it for the grid follower robot. i have difficulty in counting the no of events(no of intersections on the grid). at a particular intersection, i want the robot to take a turn left/right. how to count the no of intersection by this sensor array? smiley-confuse
my sensor gives the value>750 on black surface and <750 on the white surface... i am uploading both the codes of my line follower and grid follower.. here is the preview of my code:- please help smiley-sad
in this code i am trying the robot to turn left on the 2nd intesection
Code:
#define leftCenterSensor   3
#define leftNearSensor     4
#define leftFarSensor      5
#define rightCenterSensor  2
#define rightNearSensor    1
#define rightFarSensor     0

int leftCenterReading;
int leftNearReading;
int leftFarReading;
int rightCenterReading;
int rightNearReading;
int rightFarReading;

#define leftMotor1  10
#define leftMotor2  9
#define rightMotor1 6
#define rightMotor2 5

void setup(){
  
  pinMode(leftCenterSensor, INPUT);
  pinMode(leftNearSensor, INPUT);
  pinMode(leftFarSensor, INPUT);
  pinMode(rightCenterSensor, INPUT);
  pinMode(rightNearSensor, INPUT);
  pinMode(rightFarSensor, INPUT);
    
  pinMode(leftMotor1, OUTPUT);
  pinMode(leftMotor2, OUTPUT);
  pinMode(rightMotor1, OUTPUT);
  pinMode(rightMotor2, OUTPUT);

}

void loop(){
  readSensors();
  if(leftNearReading>750 && rightNearReading>750 && (leftCenterReading<750 || rightCenterReading<750)){
    straight();
  }
  else{
    stayOnLine();
  }
}
void readSensors(){
  
  leftCenterReading  = analogRead(leftCenterSensor);
  leftNearReading    = analogRead(leftNearSensor);
  leftFarReading     = analogRead(leftFarSensor);
  rightCenterReading = analogRead(rightCenterSensor);
  rightNearReading   = analogRead(rightNearSensor);
  rightFarReading    = analogRead(rightFarSensor);  
}

void stayOnLine(){
  if(leftNearReading>750 && leftCenterReading<750 && rightCenterReading<750 && rightNearReading<750){
    turnRight();
  }
  if(leftNearReading<750 && leftCenterReading<750 && rightCenterReading<750 && rightNearReading>750){
    turnLeft();
  }
  if(leftNearReading>750 && leftCenterReading<750 && rightCenterReading>750 && rightNearReading>750){
    turnLeft();
  }
  if(leftNearReading>750 && leftCenterReading>750 && rightCenterReading<750 && rightNearReading>750){
    turnRight();
  }
  if(leftNearReading<750 && leftCenterReading<750 && rightCenterReading<750 && rightNearReading<750){
    endmotion();
  }
}
  void turnLeft(){
    
     while(analogRead(rightCenterSensor)<750||analogRead(leftCenterSensor)<750){
     digitalWrite(leftMotor1, LOW);
    digitalWrite(leftMotor2, HIGH);
    digitalWrite(rightMotor1, HIGH);
    digitalWrite(rightMotor2, LOW);
    delay(2);
     digitalWrite(leftMotor1, LOW);
    digitalWrite(leftMotor2, LOW);
    digitalWrite(rightMotor1, LOW);
    digitalWrite(rightMotor2, LOW);
    delay(1);
  }
    
  while(analogRead(rightCenterSensor)>750){
    digitalWrite(leftMotor1, LOW);
    digitalWrite(leftMotor2, HIGH);
    digitalWrite(rightMotor1, HIGH);
    digitalWrite(rightMotor2, LOW);
    delay(2);
    digitalWrite(leftMotor1, LOW);
    digitalWrite(leftMotor2, LOW);
    digitalWrite(rightMotor1, LOW);
    digitalWrite(rightMotor2, LOW);
    delay(1);
  }
  }
    void turnRight(){

    
  while(analogRead(rightCenterSensor)<750){
     digitalWrite(leftMotor1, HIGH);
    digitalWrite(leftMotor2, LOW);
    digitalWrite(rightMotor1, LOW);
    digitalWrite(rightMotor2, HIGH);
    delay(2);
     digitalWrite(leftMotor1, LOW);
    digitalWrite(leftMotor2, LOW);
    digitalWrite(rightMotor1, LOW);
    digitalWrite(rightMotor2, LOW);
    delay(1);
  }
   while(analogRead(rightCenterSensor)>750){
     digitalWrite(leftMotor1, HIGH);
    digitalWrite(leftMotor2, LOW);
    digitalWrite(rightMotor1, LOW);
    digitalWrite(rightMotor2, HIGH);
    delay(2);
     digitalWrite(leftMotor1, LOW);
    digitalWrite(leftMotor2, LOW);
    digitalWrite(rightMotor1, LOW);
    digitalWrite(rightMotor2, LOW);
    delay(1);
  }
   while(analogRead(leftCenterSensor)>750){
     digitalWrite(leftMotor1, HIGH);
    digitalWrite(leftMotor2, LOW);
    digitalWrite(rightMotor1, LOW);
    digitalWrite(rightMotor2, HIGH);
    delay(2);
    digitalWrite(leftMotor1, LOW);
    digitalWrite(leftMotor2, LOW);
    digitalWrite(rightMotor1, LOW);
    digitalWrite(rightMotor2, LOW);
    delay(1);
  }
    }
  
  void straight(){
  if( analogRead(leftCenterSensor)>750){
    digitalWrite(leftMotor1, HIGH);
    digitalWrite(leftMotor2, LOW);
    digitalWrite(rightMotor1, HIGH);
    digitalWrite(rightMotor2, LOW);
    delay(1);
    digitalWrite(leftMotor1, HIGH);
    digitalWrite(leftMotor2, LOW);
    digitalWrite(rightMotor1, LOW);
    digitalWrite(rightMotor2, LOW);
    delay(5);
    return;
  }
  if(analogRead(rightCenterSensor)>750){
    digitalWrite(leftMotor1, HIGH);
    digitalWrite(leftMotor2, LOW);
    digitalWrite(rightMotor1, HIGH);
    digitalWrite(rightMotor2, LOW);
    delay(1);
    digitalWrite(leftMotor1, LOW);
    digitalWrite(leftMotor2, LOW);
    digitalWrite(rightMotor1, HIGH);
    digitalWrite(rightMotor2, LOW);
    delay(5);
    return;
  }
  
    digitalWrite(leftMotor1, HIGH);
    digitalWrite(leftMotor2, LOW);
    digitalWrite(rightMotor1, HIGH);
    digitalWrite(rightMotor2, LOW);
    delay(4);
    digitalWrite(leftMotor1, LOW);
    digitalWrite(leftMotor2, LOW);
    digitalWrite(rightMotor1, LOW);
    digitalWrite(rightMotor2, LOW);
    delay(1);
  
}
  
  void endmotion(){
    digitalWrite(leftMotor1, LOW);
    digitalWrite(leftMotor2, LOW);
    digitalWrite(rightMotor1, LOW);
    digitalWrite(rightMotor2, LOW);
  }
  
  

* mygridsolver.ino (4.67 KB - downloaded 66 times.)
* accurate_line_follower.ino (4.99 KB - downloaded 69 times.)
« Last Edit: July 04, 2013, 09:45:44 pm by kaushikatarduino » Logged

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

What's with the smiley faces in the code? Why didn't you post the code correctly?

The code does something (if it even compiles. Missing ; make me doubt that). What does it do? How does that differ from what you want?
Logged

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

sorry about those similes dats not the part of the code... i modified it.
yup this code works and makes the robot follow the line...
i want my robot to detect and count the no of intersections on the grid and take a turn on the particular intersection...
please help......
Logged

California
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3375
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

sorry about those similes dats not the part of the code... i modified it.

Why not simply follow the instructions posted in the How to Use this Forum - Please Read thread and surround your code with CODE tags?
Logged

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

hi i have build a line follower robot with the help of six analog ir reflectant sensor array. it works good following the line. Now i want to modify it for the grid follower robot. i have difficulty in counting the no of events(no of intersections on the grid). at a particular intersection, i want the robot to take a turn left/right. how to count the no of intersection by this sensor array?
my sensor gives the value<750 on black surface and >750 on the white surface... i am uploading both the codes of my line follower and grid follower.. here is the preview of my code:- please help
in this code i am trying the robot to turn left on the 2nd intesection
Code:
#define leftCenterSensor   3
#define leftNearSensor     4
#define leftFarSensor      5
#define rightCenterSensor  2
#define rightNearSensor    1
#define rightFarSensor     0

int state=LOW;
int lastState=LOW;
int count=0;

int leftCenterReading;
int leftNearReading;
int leftFarReading;
int rightCenterReading;
int rightNearReading;
int rightFarReading;

#define leapTime 150

#define leftMotor1  10
#define leftMotor2  9
#define rightMotor1 6
#define rightMotor2 5

void setup(){
 
  pinMode(leftCenterSensor, INPUT);
  pinMode(leftNearSensor, INPUT);
  pinMode(leftFarSensor, INPUT);
  pinMode(rightCenterSensor, INPUT);
  pinMode(rightNearSensor, INPUT);
  pinMode(rightFarSensor, INPUT);
   
  pinMode(leftMotor1, OUTPUT);
  pinMode(leftMotor2, OUTPUT);
  pinMode(rightMotor1, OUTPUT);
  pinMode(rightMotor2, OUTPUT);
  state=digitalRead(s1);
}

void loop(){
  readSensors();
  if(leftNearReading>750 && rightNearReading>750 && (leftCenterReading<750 || rightCenterReading<750)){
    straight();
  }
  else{
    solveTheGrid();
  }
  if(leftNearReading<750 && rightNearReading<750 && leftCenterReading<750 && rightCenterReading<750){
    state=1;
    count++;
 }
  lastState=state;
 
}
void readSensors(){
 
  leftCenterReading  = analogRead(leftCenterSensor);
  leftNearReading    = analogRead(leftNearSensor);
  leftFarReading     = analogRead(leftFarSensor);
  rightCenterReading = analogRead(rightCenterSensor);
  rightNearReading   = analogRead(rightNearSensor);
  rightFarReading    = analogRead(rightFarSensor); 
}
void SolveTheGrid(){
  if count==2{
    turnLeft()
  }
   void turnLeft(){
   
     while(analogRead(rightCenterSensor)<750||analogRead(leftCenterSensor)<750){
     digitalWrite(leftMotor1, LOW);
    digitalWrite(leftMotor2, HIGH);
    digitalWrite(rightMotor1, HIGH);
    digitalWrite(rightMotor2, LOW);
    delay(2);
     digitalWrite(leftMotor1, LOW);
    digitalWrite(leftMotor2, LOW);
    digitalWrite(rightMotor1, LOW);
    digitalWrite(rightMotor2, LOW);
    delay(1);
  }
   
  while(analogRead(rightCenterSensor)>750){
    digitalWrite(leftMotor1, LOW);
    digitalWrite(leftMotor2, HIGH);
    digitalWrite(rightMotor1, HIGH);
    digitalWrite(rightMotor2, LOW);
    delay(2);
    digitalWrite(leftMotor1, LOW);
    digitalWrite(leftMotor2, LOW);
    digitalWrite(rightMotor1, LOW);
    digitalWrite(rightMotor2, LOW);
    delay(1);
  }
  }
    void turnRight(){

   
  while(analogRead(rightCenterSensor)<750){
     digitalWrite(leftMotor1, HIGH);
    digitalWrite(leftMotor2, LOW);
    digitalWrite(rightMotor1, LOW);
    digitalWrite(rightMotor2, HIGH);
    delay(2);
     digitalWrite(leftMotor1, LOW);
    digitalWrite(leftMotor2, LOW);
    digitalWrite(rightMotor1, LOW);
    digitalWrite(rightMotor2, LOW);
    delay(1);
  }
   while(analogRead(rightCenterSensor)>750){
     digitalWrite(leftMotor1, HIGH);
    digitalWrite(leftMotor2, LOW);
    digitalWrite(rightMotor1, LOW);
    digitalWrite(rightMotor2, HIGH);
    delay(2);
     digitalWrite(leftMotor1, LOW);
    digitalWrite(leftMotor2, LOW);
    digitalWrite(rightMotor1, LOW);
    digitalWrite(rightMotor2, LOW);
    delay(1);
  }
   while(analogRead(leftCenterSensor)>750){
     digitalWrite(leftMotor1, HIGH);
    digitalWrite(leftMotor2, LOW);
    digitalWrite(rightMotor1, LOW);
    digitalWrite(rightMotor2, HIGH);
    delay(2);
    digitalWrite(leftMotor1, LOW);
    digitalWrite(leftMotor2, LOW);
    digitalWrite(rightMotor1, LOW);
    digitalWrite(rightMotor2, LOW);
    delay(1);
  }
    }
 
  void straight(){
  if( analogRead(leftCenterSensor)>750){
    digitalWrite(leftMotor1, HIGH);
    digitalWrite(leftMotor2, LOW);
    digitalWrite(rightMotor1, HIGH);
    digitalWrite(rightMotor2, LOW);
    delay(1);
    digitalWrite(leftMotor1, HIGH);
    digitalWrite(leftMotor2, LOW);
    digitalWrite(rightMotor1, LOW);
    digitalWrite(rightMotor2, LOW);
    delay(5);
    return;
  }
  if(analogRead(rightCenterSensor)>750){
    digitalWrite(leftMotor1, HIGH);
    digitalWrite(leftMotor2, LOW);
    digitalWrite(rightMotor1, HIGH);
    digitalWrite(rightMotor2, LOW);
    delay(1);
    digitalWrite(leftMotor1, LOW);
    digitalWrite(leftMotor2, LOW);
    digitalWrite(rightMotor1, HIGH);
    digitalWrite(rightMotor2, LOW);
    delay(5);
    return;
  }
 
    digitalWrite(leftMotor1, HIGH);
    digitalWrite(leftMotor2, LOW);
    digitalWrite(rightMotor1, HIGH);
    digitalWrite(rightMotor2, LOW);
    delay(4);
    digitalWrite(leftMotor1, LOW);
    digitalWrite(leftMotor2, LOW);
    digitalWrite(rightMotor1, LOW);
    digitalWrite(rightMotor2, LOW);
    delay(1);
 
}
 
  void endmotion(){
    digitalWrite(leftMotor1, LOW);
    digitalWrite(leftMotor2, LOW);
    digitalWrite(rightMotor1, LOW);
    digitalWrite(rightMotor2, LOW); 
  }
there is problem compiling this code... is there a problem with the count function???
how can i count the no of events(no of intersections on the grid with the help of six analog reflectant sensor array???
please suggest a code for this...
Logged

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

Quote
there is problem compiling this code.
Why don't you fix that? Or tell us what the problem is?
Logged

New Jersey
Offline Offline
Faraday Member
**
Karma: 67
Posts: 3675
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If I try compiling that, I get a number of fairly clear compiler error messages. s1 isn't defined, there's a capitalization error with a difference between the declaration of SolveTheGrid and the call to it, next is a missing semi-colon.
Logged

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

Quote
i want my robot to detect and count the no of intersections on the grid and take a turn on the particular intersection...
There are three parts to this - detecting an intersection, counting the number of detection events, and doing something when the count reaches a particular value.

The only one that takes more than 5 brain cells is detecting the intersection. That is a simple matter of noticing that the center sensors continue to see black while the outer ones see white, black, white (assuming that the intersection is two black lines crossing).

What have you tried?
Logged

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

thanks for the reply smiley
actually i have the code for the line follower robot.. here it is:
Code:
#define leftCenterSensor   3
#define leftNearSensor     4
#define leftFarSensor      5
#define rightCenterSensor  2
#define rightNearSensor    1
#define rightFarSensor     0

int leftCenterReading;
int leftNearReading;
int leftFarReading;
int rightCenterReading;
int rightNearReading;
int rightFarReading;

#define leftMotor1  10
#define leftMotor2  9
#define rightMotor1 6
#define rightMotor2 5

void setup(){
 
  pinMode(leftCenterSensor, INPUT);
  pinMode(leftNearSensor, INPUT);
  pinMode(leftFarSensor, INPUT);
  pinMode(rightCenterSensor, INPUT);
  pinMode(rightNearSensor, INPUT);
  pinMode(rightFarSensor, INPUT);
   
  pinMode(leftMotor1, OUTPUT);
  pinMode(leftMotor2, OUTPUT);
  pinMode(rightMotor1, OUTPUT);
  pinMode(rightMotor2, OUTPUT);

}

void loop(){
  readSensors();
  if(leftNearReading>750 && rightNearReading>750 && (leftCenterReading<750 || rightCenterReading<750)){
    straight();
  }
  else{
    stayOnLine();
  }
}
void readSensors(){
 
  leftCenterReading  = analogRead(leftCenterSensor);
  leftNearReading    = analogRead(leftNearSensor);
  leftFarReading     = analogRead(leftFarSensor);
  rightCenterReading = analogRead(rightCenterSensor);
  rightNearReading   = analogRead(rightNearSensor);
  rightFarReading    = analogRead(rightFarSensor); 
}

void stayOnLine(){
  if(leftNearReading>750 && leftCenterReading<750 && rightCenterReading<750 && rightNearReading<750){
    turnRight();
  }
  if(leftNearReading<750 && leftCenterReading<750 && rightCenterReading<750 && rightNearReading>750){
    turnLeft();
  }
  if(leftNearReading>750 && leftCenterReading<750 && rightCenterReading>750 && rightNearReading>750){
    turnLeft();
  }
  if(leftNearReading>750 && leftCenterReading>750 && rightCenterReading<750 && rightNearReading>750){
    turnRight();
  }
  if(leftNearReading<750 && leftCenterReading<750 && rightCenterReading<750 && rightNearReading<750){
    endmotion();
  }
}
  void turnLeft(){
   
     while(analogRead(rightCenterSensor)<750||analogRead(leftCenterSensor)<750){
     digitalWrite(leftMotor1, LOW);
    digitalWrite(leftMotor2, HIGH);
    digitalWrite(rightMotor1, HIGH);
    digitalWrite(rightMotor2, LOW);
    delay(2);
     digitalWrite(leftMotor1, LOW);
    digitalWrite(leftMotor2, LOW);
    digitalWrite(rightMotor1, LOW);
    digitalWrite(rightMotor2, LOW);
    delay(1);
  }
   
  while(analogRead(rightCenterSensor)>750){
    digitalWrite(leftMotor1, LOW);
    digitalWrite(leftMotor2, HIGH);
    digitalWrite(rightMotor1, HIGH);
    digitalWrite(rightMotor2, LOW);
    delay(2);
    digitalWrite(leftMotor1, LOW);
    digitalWrite(leftMotor2, LOW);
    digitalWrite(rightMotor1, LOW);
    digitalWrite(rightMotor2, LOW);
    delay(1);
  }
  }
    void turnRight(){

   
  while(analogRead(rightCenterSensor)<750){
     digitalWrite(leftMotor1, HIGH);
    digitalWrite(leftMotor2, LOW);
    digitalWrite(rightMotor1, LOW);
    digitalWrite(rightMotor2, HIGH);
    delay(2);
     digitalWrite(leftMotor1, LOW);
    digitalWrite(leftMotor2, LOW);
    digitalWrite(rightMotor1, LOW);
    digitalWrite(rightMotor2, LOW);
    delay(1);
  }
   while(analogRead(rightCenterSensor)>750){
     digitalWrite(leftMotor1, HIGH);
    digitalWrite(leftMotor2, LOW);
    digitalWrite(rightMotor1, LOW);
    digitalWrite(rightMotor2, HIGH);
    delay(2);
     digitalWrite(leftMotor1, LOW);
    digitalWrite(leftMotor2, LOW);
    digitalWrite(rightMotor1, LOW);
    digitalWrite(rightMotor2, LOW);
    delay(1);
  }
   while(analogRead(leftCenterSensor)>750){
     digitalWrite(leftMotor1, HIGH);
    digitalWrite(leftMotor2, LOW);
    digitalWrite(rightMotor1, LOW);
    digitalWrite(rightMotor2, HIGH);
    delay(2);
    digitalWrite(leftMotor1, LOW);
    digitalWrite(leftMotor2, LOW);
    digitalWrite(rightMotor1, LOW);
    digitalWrite(rightMotor2, LOW);
    delay(1);
  }
    }
 
  void straight(){
  if( analogRead(leftCenterSensor)>750){
    digitalWrite(leftMotor1, HIGH);
    digitalWrite(leftMotor2, LOW);
    digitalWrite(rightMotor1, HIGH);
    digitalWrite(rightMotor2, LOW);
    delay(1);
    digitalWrite(leftMotor1, HIGH);
    digitalWrite(leftMotor2, LOW);
    digitalWrite(rightMotor1, LOW);
    digitalWrite(rightMotor2, LOW);
    delay(5);
    return;
  }
  if(analogRead(rightCenterSensor)>750){
    digitalWrite(leftMotor1, HIGH);
    digitalWrite(leftMotor2, LOW);
    digitalWrite(rightMotor1, HIGH);
    digitalWrite(rightMotor2, LOW);
    delay(1);
    digitalWrite(leftMotor1, LOW);
    digitalWrite(leftMotor2, LOW);
    digitalWrite(rightMotor1, HIGH);
    digitalWrite(rightMotor2, LOW);
    delay(5);
    return;
  }
 
    digitalWrite(leftMotor1, HIGH);
    digitalWrite(leftMotor2, LOW);
    digitalWrite(rightMotor1, HIGH);
    digitalWrite(rightMotor2, LOW);
    delay(4);
    digitalWrite(leftMotor1, LOW);
    digitalWrite(leftMotor2, LOW);
    digitalWrite(rightMotor1, LOW);
    digitalWrite(rightMotor2, LOW);
    delay(1);
 
}
 
  void endmotion(){
    digitalWrite(leftMotor1, LOW);
    digitalWrite(leftMotor2, LOW);
    digitalWrite(rightMotor1, LOW);
    digitalWrite(rightMotor2, LOW);
  }
 
   
i want to modify it for the grid follower robot please help..
Logged

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

thanks for the reply smiley
i am having difficulty in using counters....
how to use them?
the intersection will be detected when all the six sensors are on the black line i.e they give the value<750...
i have a code which counts the no of digital inputs and at a particular value of count, it turns on the led. here is my code for this:_
Code:
int state=LOW;
int lastState=LOW;
int count=0;
int led =13;
int s1 = 8;

void setup()
{
Serial.begin(9600);
pinMode(s1, INPUT);
pinMode(led, OUTPUT);
state=digitalRead(s1);
}
void loop(){
if (state==HIGH && lastState==LOW){
count++;
Serial.println(count);
}
lastState=state;
state=digitalRead(s1);
if (count == 2){
  digitalWrite(led, HIGH);
}
if (count == 15){
  digitalWrite(led, LOW);
}
}


i want to modify this code taking the input from six analog sensors...
please help...
Logged

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

Code:
int state=LOW;
int lastState=LOW;
int count=0;
int led =13;
int s1 = 8;

void setup()
{
Serial.begin(9600);
pinMode(s1, INPUT);
pinMode(led, OUTPUT);
state=digitalRead(s1);
}
void loop(){
if (state==HIGH && lastState==LOW){
count++;
Serial.println(count);
}
lastState=state;
state=digitalRead(s1);
if (count == 2){
  digitalWrite(led, HIGH);
}
if (count == 15){
  digitalWrite(led, LOW);
}
}

this code reads the input from a digital sensor and counts the no of state... and turn on led at a particular count....
i want to modify this code a little bit... instead of using a single sensor, i want to use 6 analog sensors....
it should count the no of event(each time when all of the six sensor gives same value, say<750) please help..
Logged

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

Topics merged.
Please don't cross-post
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

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

Hey,
In your line follower code you have assigned the same arduino pin number(5) to both the sensor and the motor.How does that work?
Tried uploading this code using 6 out of the 8 sensors of pololu QTR 8RC sensors.Nothing happened.
Logged

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

Quote
you have assigned the same arduino pin number(5) to both the sensor and the motor.How does that work?
Analogue pin 5 != digital pin 5.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

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

Right!overlooked that,sorry!
We are using the QTR 8RC pololu sensors.He seemed to have used the 8A sensors(6 of them).When we run the calibration code for the sensors in the QTR library,we observe a "1000" for the sensors which are over a black line.So,How do we arrive at the "750" that we see in the above code?? Basically how would the above code differ when we use the RC sensors(6 of the 8 in the array) ?? Sorry for the rudimentary questions,but this is our first project with a microcontroller.Please help.
« Last Edit: July 24, 2013, 04:17:23 am by project_quest » Logged

Pages: [1]   Go Up
Jump to: