Printing Values detected by TCS34725 RGB sensor on an Lcd keypad shield

Hi, Im Making a card Detecting system for my school project and i am finding difficulties in printing the values of RGB sensor on an lcd keypad shield Please help me
This is my code:

#include <Wire.h>
#include <Adafruit_TCS34725.h>
#include <LiquidCrystal.h>

Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_1X);
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int ledPin = 13; // Built-in LED on most Arduino boards

void setup() {
  Serial.begin(9600);
  lcd.begin(16, 2);
  pinMode(ledPin, OUTPUT); // Set the LED pin as an output

  if (tcs.begin()) {
    Serial.println("TCS34725 found!");
    lcd.print("TCS34725 found!");
  } else {
    Serial.println("No TCS34725 found ... check your connections");
    lcd.print("No TCS34725 found...");
    while (1);
  }

  delay(2000);
  lcd.clear();
}

void loop() {
  uint16_t clear, red, green, blue;

  tcs.setInterrupt(false);
  delay(60);

  tcs.getRawData(&red, &green, &blue, &clear);

  // Print raw RGB values to Serial Monitor
  Serial.print("Raw RGB: ");
  Serial.print(red);
  Serial.print(", ");
  Serial.print(green);
  Serial.print(", ");
  Serial.println(blue);

  String detectedCard = recognizeCard(red, green, blue);

  Serial.println("Detected Card: " + detectedCard);
  lcd.setCursor(0, 0);
  lcd.print("Card: " + detectedCard);

  // Check for HDFC Card
  if (detectedCard == "HDFC_Card") {
    digitalWrite(ledPin, HIGH); // Turn on the LED
  } else {
    digitalWrite(ledPin, LOW); // Turn off the LED
  }
if(detectedCard = "HDFC_Card") {
  lcd.print("HDFC");  
}   

  delay(500);
}

String recognizeCard(uint16_t red, uint16_t green, uint16_t blue) {
  // Define custom RGB ranges for the cards
  int customHDFC_CardMin[3] = {40, 40, 45};   // HDFC Card minimum range
  int customHDFC_CardMax[3] = {60, 60, 60};   // HDFC Card maximum range
  int customKotak_CardMin[3] = {150, 65, 31}; // Kotak Card minimum range
  int customKotak_CardMax[3] = {156, 70, 33}; // Kotak Card maximum range
  int custom8G_CardMin[3] = {149, 56, 47};   // 8G Card minimum range
  int custom8G_CardMax[3] = {154, 60, 50};   // 8G Card maximum range

  // Check for custom card ranges
  if (
    red >= customHDFC_CardMin[0] && red <= customHDFC_CardMax[0] &&
    green >= customHDFC_CardMin[1] && green <= customHDFC_CardMax[1] &&
    blue >= customHDFC_CardMin[2] && blue <= customHDFC_CardMax[2]
  ) {
    lcd.setCursor(0, 1); // Set the cursor to the second line of the LCD
    lcd.print("HDFC Card");
    return "HDFC_Card";
  }

  if (
    red >= customKotak_CardMin[0] && red <= customKotak_CardMax[0] &&
    green >= customKotak_CardMin[1] && green <= customKotak_CardMax[1] &&
    blue >= customKotak_CardMin[2] && blue <= customKotak_CardMax[2]
  ) {
    return "Kotak_Card";
  }

  if (
    red >= custom8G_CardMin[0] && red <= custom8G_CardMax[0] &&
    green >= custom8G_CardMin[1] && green <= custom8G_CardMax[1] &&
    blue >= custom8G_CardMin[2] && blue <= custom8G_CardMax[2]
  ) {
    return "8G_Card";
  }
{
  return "Unknown";
}

}

Welcome to the forum.

What "difficulties", exactly?

  • What is you code intended to do?
  • What is you code actually to doing?
  • What testing/investigation/debugging have you done to find the problem?

What RGB sensor? What Keypad shield?

Please give links.

see. the i have programmed my arduino in a way that if the rgb sensor is detecting specific colour then it will display the name that i have given to that colour on an lcd keypad shield but the lcd keypad shield is not displaying anything and its screen keeps turning on and off with the tx LED on arduino

it means to display the value of rgb sensor ONlcd keypad shield

But we still don't know what "lcd keypad shield" you are using.

Please give a link to that shield so that we can see exactly what you are using.

Similarly, we don't know what "rgb sensor" you are using - is it part of this unknown shield?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.