bangnaga icon

Arduino Uno Sensor Warna TCS2300 PH

bangnaga | PRO | 09/05/21 07:42:44 AM UTC (Edited) | 0 ⭐ | 1466 👁️ | Never ⏰ | []
C++ |

7.08 KB

|

None

|

0 👍

/

0 👎

// TCS230 or TCS3200 pins wiring to Arduino
#define S0 8
#define S1 9
#define S2 10
#define S3 11
#define sensorOut 12
 
int Li          = 17;
int Lii         = 1; 
int Ri          = -1;
int Rii         = -1;
 
 
//LCD Library
#include  <Wire.h>
#include <LiquidCrystal_I2C.h>        //Library LCD I2C
LiquidCrystal_I2C lcd(0x27,16,2);     //Alamat I2C
int screenWidth = 16;
int screenHeight = 2;
// ini text untuk scrolling
String line1 = "Ini scrolling text bro";
 
int stringStart, stringStop = 0;
int scrollCursor = screenWidth;
 
 
// Stores frequency read by the photodiodes
int redFrequency = 0;
int greenFrequency = 0;
int blueFrequency = 0;
 
// Stores the red. green and blue colors
int redColor = 0;
int greenColor = 0;
int blueColor = 0;
 
void setup() {
 
  //Setting LCD
  lcd.begin(16,2);   // initialize the lcd for 16 chars 2 lines, turn on backlight 
  lcd.backlight();
  delay(250);
  lcd.noBacklight();
  delay(250);
  lcd.backlight();
 
  
  // Setting the outputs
  pinMode(S0, OUTPUT);
  pinMode(S1, OUTPUT);
  pinMode(S2, OUTPUT);
  pinMode(S3, OUTPUT);
  
  // Setting the sensorOut as an input
  pinMode(sensorOut, INPUT);
  
  // Setting frequency scaling to 20%
  digitalWrite(S0,HIGH);
  digitalWrite(S1,LOW);
  
  // Begins serial communication
  Serial.begin(9600);
   
  //Tampilan Awal LCD
 
 
 
  lcd.clear();
  for (int i = 0; i <= 13; i++) {
    lcd.setCursor(0, 0);
    lcd.print(Scroll_LCD_Right(" Alat Uji "));
    delay(200);
  }
  for (int i = 0; i <= 50; i++) {                                                                             
    lcd.setCursor(0, 1);                                                
    lcd.print(Scroll_LCD_Left("Kualitas Air Minum Menggunakan Arduino Uno & TCS2300"));  
    delay(200);
  }
 
 
 
  
 
/*
lcd.clear();
     lcd.setCursor(0,0);
      lcd.print(" Alat Uji Kualitas Air Minum ");
    for (int positionCounter = 0; positionCounter <= 19; positionCounter++) {
      // scroll one position left:
      lcd.scrollDisplayLeft();
      // wait a bit:
      delay(350);
    }
      delay(300);
*/
   
    
    
 
    lcd.clear();
 
    lcd.setCursor(0,0);
    lcd.print("Dibuat Oleh: ");
    delay(1000);
    lcd.setCursor(0,1);
    lcd.print("ASRIN AINUN");
    delay(3000);
}
 
void loop() {
  // Setting RED (R) filtered photodiodes to be read
  digitalWrite(S2,LOW);
  digitalWrite(S3,LOW);
  
  // Reading the output frequency
  redFrequency = pulseIn(sensorOut, LOW);
  redColor = redFrequency;
  // Remaping the value of the RED (R) frequency from 0 to 255
  // You must replace with your own values. Here's an example: 
  // redColor = map(redFrequency, 70, 120, 255,0);
 // redColor = map(redFrequency, 39, 103, 255,0);
  
  // Printing the RED (R) value
  Serial.print("R = ");
  Serial.print(redFrequency);
  delay(100);
  
  // Setting GREEN (G) filtered photodiodes to be read
  digitalWrite(S2,HIGH);
  digitalWrite(S3,HIGH);
  
  // Reading the output frequency
  greenFrequency = pulseIn(sensorOut, LOW);
  greenColor = greenFrequency;
  // Remaping the value of the GREEN (G) frequency from 0 to 255
  // You must replace with your own values. Here's an example: 
  // greenColor = map(greenFrequency, 100, 199, 255, 0);
 // greenColor = map(greenFrequency, 61, 109, 255, 0);
  
  // Printing the GREEN (G) value  
  Serial.print(" G = ");
  Serial.print(greenFrequency);
  delay(100);
 
  // Setting BLUE (B) filtered photodiodes to be read
  digitalWrite(S2,LOW);
  digitalWrite(S3,HIGH);
  
  // Reading the output frequency
  blueFrequency = pulseIn(sensorOut, LOW);
  blueColor= blueFrequency;
  // Remaping the value of the BLUE (B) frequency from 0 to 255
  // You must replace with your own values. Here's an example: 
  // blueColor = map(blueFrequency, 38, 84, 255, 0);
  //blueColor = map(blueFrequency, 38, 125, 255, 0);
  
  // Printing the BLUE (B) value 
  Serial.print(" B = ");
  Serial.print(blueFrequency);
  delay(100);
  Serial.println();
 
 if((redColor >=170 && redColor <=202 ) && (greenColor >=170 && greenColor <=201) && (blueColor >=120 && blueColor <=142)){
    Serial.println("Masukkan Sample Air Minum ! ");
    
     lcd.clear();
     lcd.setCursor(0,0);
     lcd.print("  Masukkan Sample Air Minum!");
    for (int positionCounter = 0; positionCounter <= 19; positionCounter++) {
      // scroll one position left:
      lcd.scrollDisplayLeft();
      // wait a bit:
      delay(450);
    }
 }
  if((redColor >=240 && redColor <=291 ) && (greenColor >=250 && greenColor <=306) && (blueColor >=210 && blueColor <=231)){
    Serial.println("PH RENDAH");
     phrendah();
  }
  
  if((redColor >=290 && redColor <320 ) && (greenColor >=300 && greenColor <=330) && (blueColor >=200 && blueColor <=230)){
    Serial.println("PH NORMAL");
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("   PH Normal");
    lcd.setCursor(0,1);
    lcd.print("Kualitas Air Bagus");
    for (int positionCounter = 7; positionCounter > 0; positionCounter--) {
    lcd.scrollDisplayLeft();
      delay(500);
    }
    delay(500);   
  }
 
 
 
  if((redColor >=310 && redColor <=360 ) && (greenColor >=330 && greenColor <=350) && (blueColor >=220 && blueColor <=240)){
   Serial.println("PH TINGGI");
   phtinggi();
  }
 
 
}
 
//----------------------------------
String Scroll_LCD_Left(String StrDisplay){
  String result;
  String StrProcess = "                " + StrDisplay + "                ";
  result = StrProcess.substring(Li,Lii);
  Li++;
  Lii++;
  if (Li>StrProcess.length()){
    Li=16;
    Lii=0;
  }
  return result;
}
 
void Clear_Scroll_LCD_Left(){
  Li=16;
  Lii=0;
}
//----------------------------------
String Scroll_LCD_Right(String StrDisplay){
  String result;
  String StrProcess = "                " + StrDisplay + "                ";
  if (Rii<1){
    Ri  = StrProcess.length();
    Rii = Ri-16;
  }
  result = StrProcess.substring(Rii,Ri);
  Ri--;
  Rii--;
  return result;
}
 
void Clear_Scroll_LCD_Right(){
  Ri=-1;
  Rii=-1;
}
 
void phtinggi(){
      lcd.clear();
      lcd.print("   PH Tinggi   ");
      delay(100);
      
      for (int i = 0; i <= 157; i++) {                                                                             
        lcd.setCursor(0, 1);                                                
            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"));
 
        delay(200);
      }
     delay (2000);
}
 
 
void phrendah(){
      lcd.clear();
      lcd.print("   PH Rendah   ");
      delay (100);
      for (int i = 0; i <= 129; i++) {                                                                             
        lcd.setCursor(0, 1);                                                
            lcd.print(Scroll_LCD_Left("Jika dikomsumsi rutin dalam jangka waktu yang lama dapat menyebabkan : Kelelahan, sakit kepala, mengantuk, kulit melepuh, alergi"));
 
        delay(200);
      }
     delay (2000);
}

Comments