chowdhury_riham

Color sensor code (TCS3200)

Nov 17th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. #define S0 4
  2. #define S1 5
  3. #define S2 6
  4. #define S3 7
  5. #define sensorOut 8
  6. int frequency = 0;
  7. void setup() {
  8. pinMode(S0, OUTPUT);
  9. pinMode(S1, OUTPUT);
  10. pinMode(S2, OUTPUT);
  11. pinMode(S3, OUTPUT);
  12. pinMode(sensorOut, INPUT);
  13.  
  14. // Setting frequency-scaling to 20%
  15. digitalWrite(S0,HIGH);
  16. digitalWrite(S1,LOW);
  17.  
  18. Serial.begin(9600);
  19. }
  20. void loop() {
  21. // Setting red filtered photodiodes to be read
  22. digitalWrite(S2,LOW);
  23. digitalWrite(S3,LOW);
  24. // Reading the output frequency
  25. frequency = pulseIn(sensorOut, LOW);
  26. // Printing the value on the serial monitor
  27. Serial.print("R= ");//printing name
  28. Serial.print(frequency);//printing RED color frequency
  29. Serial.print(" ");
  30. delay(100);
  31. // Setting Green filtered photodiodes to be read
  32. digitalWrite(S2,HIGH);
  33. digitalWrite(S3,HIGH);
  34. // Reading the output frequency
  35. frequency = pulseIn(sensorOut, LOW);
  36. // Printing the value on the serial monitor
  37. Serial.print("G= ");//printing name
  38. Serial.print(frequency);//printing RED color frequency
  39. Serial.print(" ");
  40. delay(100);
  41. // Setting Blue filtered photodiodes to be read
  42. digitalWrite(S2,LOW);
  43. digitalWrite(S3,HIGH);
  44. // Reading the output frequency
  45. frequency = pulseIn(sensorOut, LOW);
  46. // Printing the value on the serial monitor
  47. Serial.print("B= ");//printing name
  48. Serial.print(frequency);//printing RED color frequency
  49. Serial.println(" ");
  50. delay(100);
  51. }
  52. // for Advance level : http://playground.arduino.cc/Code/NewPing
Add Comment
Please, Sign In to add comment