AndreaM19
Published © GPL3+

RGB Sensor Arduino

From Arduino to Processing. An Arduino board collects RGB values and shows pictures of famous paintings.

BeginnerShowcase (no instructions)557
RGB Sensor Arduino

Things used in this project

Hardware components

RGB Diffused Common Cathode
RGB Diffused Common Cathode
×1
Jumper wires (generic)
Jumper wires (generic)
×15
Resistor 1k ohm
Resistor 1k ohm
×1
Resistor 10k ohm
Resistor 10k ohm
×2
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×1

Software apps and online services

Processing
The Processing Foundation Processing

Story

Read more

Code

FinalProjectAndrea.pde

Java
                         import processing.serial.*;

Serial mySerial;  // Create object from Serial class
String myString = null;
int nl = 10;
float myVal;
int myR, myG, myB, myR2, myG2, myB2;



PFont font;


void setup() {
  size(1250, 800);
  pixelDensity(2);
  String myPort = Serial.list()[1]; //change the 0 to a 1 or 2 etc. to match your port
  mySerial = new Serial(this, myPort, 9600);
  //println(myPort);
  
  font = createFont("Helvetica", 32);
  

}

void draw() {
  background(255);

  while ( mySerial.available() > 0) {  // If data is available,
    myString = mySerial.readStringUntil(nl);

    if (myString != null) {
      myVal = float(myString);

// the code below puts the information from the Serial into a processing String Array
      String[] mySplitString = split(myString, ',');

      if (mySplitString.length >=3) {
        myR = int(mySplitString[0]);
        
        /
        myR2 = (int)map(myR, 0, 7000, 0, 255);
        myG = int(mySplitString[1]);
        myG2 = (int)map(myG, 0, 9000, 0, 255);
        myB = int(mySplitString[2]);
        myB2 = (int)map(myB, 0, 8000, 0, 255);
      }


      println(mySplitString.length + " " + myR2 + " " + myG2 + " " + myB2 + "   " + myString);

    }
  }

// this if statement is set to display a rectangle if the object over the sensor contains more red that green or blue
      if (myR2 > myG2 && myR2 > myB2 && myR2 > 20) {

PImage img;
img = loadImage("TINTORETTO.jpg");
image(img, 0, 0);
     }
           if (myG2 > myR2 && myG2 > myB2 && myG2 > 20) {

PImage img;
img = loadImage("MONET.jpg");
image(img, 0, 0); 
     }
              if (myB2 > myR2 && myB2 > myG2 && myB2 > 20) {

PImage img;
img = loadImage("BARTHES.jpg");
image(img, 0, 0);
     }
             }
     

rgbAndrea.ino

Jade
#include <Adafruit_TCS34725.h>

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

/* Example code for the Adafruit TCS34725 breakout library */

/* Connect SCL    to analog 5
   Connect SDA    to analog 4
   Connect VDD    to 3.3V DC
   Connect GROUND to common ground */

/* Initialise with default values (int time = 2.4ms, gain = 1x) */
// Adafruit_TCS34725 tcs = Adafruit_TCS34725();

/* Initialise with specific int time and gain values */
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_101MS, TCS34725_GAIN_1X);

void setup(void) {
  Serial.begin(9600);

  if (tcs.begin()) {
    Serial.println("Found sensor");
  } else {
    Serial.println("No TCS34725 found ... check your connections");
    //while (0);
  }

  // Now we're ready to get readings!
}

void loop(void) {
  uint16_t r, g, b, c;
  // colorTemp, lux;

  tcs.getRawData(&r, &g, &b, &c);

  Serial.print(r, DEC);
  Serial.print(",");
  Serial.print(g, DEC);
  Serial.print(",");
  Serial.print(b, DEC);
  Serial.println(","); //IMPORTANT println


}

Credits

AndreaM19

AndreaM19

0 projects • 1 follower

Comments