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";
}
}