Sign up ×
Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. It's 100% free, no registration required.

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);




}
share|improve this 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 at 11:49
    
@mic i have edited the question with my code – Adnan Jan 16 at 13:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.