1

i m working on a robot that can sense different colours and then follow a particular path accordingly.previously i was using "pulseIn" function to read the out frequency but the results are not very stable and consistent. Also it tends to give same output for 2 same colours. Can anyone help me to use some other function or code that can perform better. Thanks

int pin0=2, pin1=3, pin2=4, pin3 = 5;
int OutPut= 10;
unsigned int frequency = 0;


void setup() {
Serial.begin(9600);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(10, INPUT);
pinMode(13, OUTPUT);
digitalWrite(2,HIGH);
digitalWrite(3,LOW);
digitalWrite(13, HIGH);

}

void loop() {
digitalWrite(pin2,LOW);
digitalWrite(pin3,LOW);
frequency = pulseIn(OutPut, LOW);
Serial.print(" red   ");
Serial.println(frequency);
delay(1000);
digitalWrite(pin2,LOW);
digitalWrite(pin3,HIGH);
frequency = pulseIn(OutPut, LOW);
Serial.print(" blue   ");
Serial.println(frequency);
delay(1000);
digitalWrite(pin2,HIGH);
digitalWrite(pin3,HIGH);
frequency = pulseIn(OutPut, LOW);
Serial.print(" green   ");
Serial.println(frequency);
delay(1000);




}

closed as unclear what you're asking by user31481, gre_gor, per1234, MatsK, KIIV Nov 24 '17 at 17:31

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    How about sharing some details on your system architecture and your code? "I have a sensor but it doesn't really work" is a little bit too rough. – mic Jan 16 '15 at 11:49
  • @mic i have edited the question with my code – Adnan Jan 16 '15 at 13:27