Advertisement
bangnaga

Arduino Uno Sensor Warna TCS2300 PH

Sep 5th, 2021 (edited)
1,181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.08 KB | None | 0 0
  1. // TCS230 or TCS3200 pins wiring to Arduino
  2. #define S0 8
  3. #define S1 9
  4. #define S2 10
  5. #define S3 11
  6. #define sensorOut 12
  7.  
  8. int Li          = 17;
  9. int Lii         = 1;
  10. int Ri          = -1;
  11. int Rii         = -1;
  12.  
  13.  
  14. //LCD Library
  15. #include  <Wire.h>
  16. #include <LiquidCrystal_I2C.h>        //Library LCD I2C
  17. LiquidCrystal_I2C lcd(0x27,16,2);     //Alamat I2C
  18. int screenWidth = 16;
  19. int screenHeight = 2;
  20. // ini text untuk scrolling
  21. String line1 = "Ini scrolling text bro";
  22.  
  23. int stringStart, stringStop = 0;
  24. int scrollCursor = screenWidth;
  25.  
  26.  
  27. // Stores frequency read by the photodiodes
  28. int redFrequency = 0;
  29. int greenFrequency = 0;
  30. int blueFrequency = 0;
  31.  
  32. // Stores the red. green and blue colors
  33. int redColor = 0;
  34. int greenColor = 0;
  35. int blueColor = 0;
  36.  
  37. void setup() {
  38.  
  39.   //Setting LCD
  40.   lcd.begin(16,2);   // initialize the lcd for 16 chars 2 lines, turn on backlight
  41.   lcd.backlight();
  42.   delay(250);
  43.   lcd.noBacklight();
  44.   delay(250);
  45.   lcd.backlight();
  46.  
  47.  
  48.   // Setting the outputs
  49.   pinMode(S0, OUTPUT);
  50.   pinMode(S1, OUTPUT);
  51.   pinMode(S2, OUTPUT);
  52.   pinMode(S3, OUTPUT);
  53.  
  54.   // Setting the sensorOut as an input
  55.   pinMode(sensorOut, INPUT);
  56.  
  57.   // Setting frequency scaling to 20%
  58.   digitalWrite(S0,HIGH);
  59.   digitalWrite(S1,LOW);
  60.  
  61.   // Begins serial communication
  62.   Serial.begin(9600);
  63.    
  64.   //Tampilan Awal LCD
  65.  
  66.  
  67.  
  68.   lcd.clear();
  69.   for (int i = 0; i <= 13; i++) {
  70.     lcd.setCursor(0, 0);
  71.     lcd.print(Scroll_LCD_Right(" Alat Uji "));
  72.     delay(200);
  73.   }
  74.   for (int i = 0; i <= 50; i++) {                                                                            
  75.     lcd.setCursor(0, 1);                                                
  76.     lcd.print(Scroll_LCD_Left("Kualitas Air Minum Menggunakan Arduino Uno & TCS2300"));  
  77.     delay(200);
  78.   }
  79.  
  80.  
  81.  
  82.  
  83.  
  84. /*
  85. lcd.clear();
  86.      lcd.setCursor(0,0);
  87.       lcd.print(" Alat Uji Kualitas Air Minum ");
  88.     for (int positionCounter = 0; positionCounter <= 19; positionCounter++) {
  89.       // scroll one position left:
  90.       lcd.scrollDisplayLeft();
  91.       // wait a bit:
  92.       delay(350);
  93.     }
  94.       delay(300);
  95. */
  96.    
  97.    
  98.    
  99.  
  100.     lcd.clear();
  101.  
  102.     lcd.setCursor(0,0);
  103.     lcd.print("Dibuat Oleh: ");
  104.     delay(1000);
  105.     lcd.setCursor(0,1);
  106.     lcd.print("ASRIN AINUN");
  107.     delay(3000);
  108. }
  109.  
  110. void loop() {
  111.   // Setting RED (R) filtered photodiodes to be read
  112.   digitalWrite(S2,LOW);
  113.   digitalWrite(S3,LOW);
  114.  
  115.   // Reading the output frequency
  116.   redFrequency = pulseIn(sensorOut, LOW);
  117.   redColor = redFrequency;
  118.   // Remaping the value of the RED (R) frequency from 0 to 255
  119.   // You must replace with your own values. Here's an example:
  120.   // redColor = map(redFrequency, 70, 120, 255,0);
  121.  // redColor = map(redFrequency, 39, 103, 255,0);
  122.  
  123.   // Printing the RED (R) value
  124.   Serial.print("R = ");
  125.   Serial.print(redFrequency);
  126.   delay(100);
  127.  
  128.   // Setting GREEN (G) filtered photodiodes to be read
  129.   digitalWrite(S2,HIGH);
  130.   digitalWrite(S3,HIGH);
  131.  
  132.   // Reading the output frequency
  133.   greenFrequency = pulseIn(sensorOut, LOW);
  134.   greenColor = greenFrequency;
  135.   // Remaping the value of the GREEN (G) frequency from 0 to 255
  136.   // You must replace with your own values. Here's an example:
  137.   // greenColor = map(greenFrequency, 100, 199, 255, 0);
  138.  // greenColor = map(greenFrequency, 61, 109, 255, 0);
  139.  
  140.   // Printing the GREEN (G) value  
  141.   Serial.print(" G = ");
  142.   Serial.print(greenFrequency);
  143.   delay(100);
  144.  
  145.   // Setting BLUE (B) filtered photodiodes to be read
  146.   digitalWrite(S2,LOW);
  147.   digitalWrite(S3,HIGH);
  148.  
  149.   // Reading the output frequency
  150.   blueFrequency = pulseIn(sensorOut, LOW);
  151.   blueColor= blueFrequency;
  152.   // Remaping the value of the BLUE (B) frequency from 0 to 255
  153.   // You must replace with your own values. Here's an example:
  154.   // blueColor = map(blueFrequency, 38, 84, 255, 0);
  155.   //blueColor = map(blueFrequency, 38, 125, 255, 0);
  156.  
  157.   // Printing the BLUE (B) value
  158.   Serial.print(" B = ");
  159.   Serial.print(blueFrequency);
  160.   delay(100);
  161.   Serial.println();
  162.  
  163.  if((redColor >=170 && redColor <=202 ) && (greenColor >=170 && greenColor <=201) && (blueColor >=120 && blueColor <=142)){
  164.     Serial.println("Masukkan Sample Air Minum ! ");
  165.    
  166.      lcd.clear();
  167.      lcd.setCursor(0,0);
  168.      lcd.print("  Masukkan Sample Air Minum!");
  169.     for (int positionCounter = 0; positionCounter <= 19; positionCounter++) {
  170.       // scroll one position left:
  171.       lcd.scrollDisplayLeft();
  172.       // wait a bit:
  173.       delay(450);
  174.     }
  175.  }
  176.   if((redColor >=240 && redColor <=291 ) && (greenColor >=250 && greenColor <=306) && (blueColor >=210 && blueColor <=231)){
  177.     Serial.println("PH RENDAH");
  178.      phrendah();
  179.   }
  180.  
  181.   if((redColor >=290 && redColor <320 ) && (greenColor >=300 && greenColor <=330) && (blueColor >=200 && blueColor <=230)){
  182.     Serial.println("PH NORMAL");
  183.     lcd.clear();
  184.     lcd.setCursor(0,0);
  185.     lcd.print("   PH Normal");
  186.     lcd.setCursor(0,1);
  187.     lcd.print("Kualitas Air Bagus");
  188.     for (int positionCounter = 7; positionCounter > 0; positionCounter--) {
  189.     lcd.scrollDisplayLeft();
  190.       delay(500);
  191.     }
  192.     delay(500);  
  193.   }
  194.  
  195.  
  196.  
  197.   if((redColor >=310 && redColor <=360 ) && (greenColor >=330 && greenColor <=350) && (blueColor >=220 && blueColor <=240)){
  198.    Serial.println("PH TINGGI");
  199.    phtinggi();
  200.   }
  201.  
  202.  
  203. }
  204.  
  205. //----------------------------------
  206. String Scroll_LCD_Left(String StrDisplay){
  207.   String result;
  208.   String StrProcess = "                " + StrDisplay + "                ";
  209.   result = StrProcess.substring(Li,Lii);
  210.   Li++;
  211.   Lii++;
  212.   if (Li>StrProcess.length()){
  213.     Li=16;
  214.     Lii=0;
  215.   }
  216.   return result;
  217. }
  218.  
  219. void Clear_Scroll_LCD_Left(){
  220.   Li=16;
  221.   Lii=0;
  222. }
  223. //----------------------------------
  224. String Scroll_LCD_Right(String StrDisplay){
  225.   String result;
  226.   String StrProcess = "                " + StrDisplay + "                ";
  227.   if (Rii<1){
  228.     Ri  = StrProcess.length();
  229.     Rii = Ri-16;
  230.   }
  231.   result = StrProcess.substring(Rii,Ri);
  232.   Ri--;
  233.   Rii--;
  234.   return result;
  235. }
  236.  
  237. void Clear_Scroll_LCD_Right(){
  238.   Ri=-1;
  239.   Rii=-1;
  240. }
  241.  
  242. void phtinggi(){
  243.       lcd.clear();
  244.       lcd.print("   PH Tinggi   ");
  245.       delay(100);
  246.      
  247.       for (int i = 0; i <= 157; i++) {                                                                            
  248.         lcd.setCursor(0, 1);                                                
  249.             lcd.print(Scroll_LCD_Left("Jika dikomsumsi rutin dalam jangka waktu yang lama dapat menyebabkan : Kerang Otot, Kesemutan, Nyeri Dada, Sesak Nafas, Demam, Muntah-muntah dan berkeringat"));
  250.  
  251.         delay(200);
  252.       }
  253.      delay (2000);
  254. }
  255.  
  256.  
  257. void phrendah(){
  258.       lcd.clear();
  259.       lcd.print("   PH Rendah   ");
  260.       delay (100);
  261.       for (int i = 0; i <= 129; i++) {                                                                            
  262.         lcd.setCursor(0, 1);                                                
  263.             lcd.print(Scroll_LCD_Left("Jika dikomsumsi rutin dalam jangka waktu yang lama dapat menyebabkan : Kelelahan, sakit kepala, mengantuk, kulit melepuh, alergi"));
  264.  
  265.         delay(200);
  266.       }
  267.      delay (2000);
  268. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement