Jam Jar color mixer

Description

I used an Arduino, LEDs, and a jam jar “diffuser.” My program prompts users to enter a flavor of jam into the Arduino Serial monitor (“Welcome to the Jam Color Mixer! What type of jam would you like?”), then mixes red, green, and blue light to create a color approximating that jam type. Requesting strawberry jam gives a purpley-red color, blueberry gives a dark blue, and lime gives a bright green. The serial monitor repeats the request to the user and displays the RBG color combination (“You asked for cherry jam. cherry is composed of R255, G31, B31”).

To make the diffusor, a glass jam jar was lined with white tissue paper on the sides and a wad of cotton batting on the bottom. The jar screw cap (but not the rubberized seal) was screwed on to keep the tissue paper in place.

Components

  • Arduino UNO board
  • 1 red, 1 green, and 1 blue LED
  • connector wires
  • a “quilted” pattern, 6 oz glass jam jar
  • white tissue paper
  • cotton batting

Code

/* Jam RGB LED
* Serial commands control the type of jam (color of light)
* by controlling the brightness of R,G,B LEDs
* Command structure is “<fruitName>”, where “fruitName” is
* one of ten possible fruits. the colors of these fruits are translated into RGB colors.
* E.g. “apple” gives R163, G82, B0
* “blueberry” gives R51, G0, B102
*/
String fruitName; //a String class variable that will contain the entire serial input
int redPin = 9; // Red LED, connected to digital pin 9
int greenPin = 10; // Green LED, connected to digital pin 10
int bluePin = 11; // Blue LED, connected to digital pin 11
int debug = 1;
//arrays of RGB values
int redArray[10] = {163,51,46,255,245,255,112,138,184,255};
int greenArray[10] = {82,0,0,31,184,255,224,0,0,51};
int blueArray[10] = {0,102,184,31,0,31,0,184,46,102};

int colorIndex; //an index variable

void setup() {
pinMode(redPin, OUTPUT); // sets the pins as output
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
Serial.begin(9600);
analogWrite(redPin, 0); // set them all to off
analogWrite(greenPin, 0); // set them all to off
analogWrite(bluePin, 0); // set them all to off
Serial.println(“Welcome to the Jam Color Mixer! What type of jam would you like?”);
}

void loop() {
//clear the fruitName variable;
fruitName.remove(0);
//read the serial port and create a string out of it
readSerialString();

if (fruitName.length()>0) {
//confirm the request
Serial.print(“You asked for “);
Serial.print(fruitName);
Serial.println(” jam.”);

if(fruitName == “apple”)
colorIndex=0;
else if(fruitName == “blackberry”)
colorIndex=1;
else if(fruitName == “blueberry”)
colorIndex=2;
else if(fruitName == “cherry”)
colorIndex=3;
else if(fruitName == “honey”)
colorIndex=4;
else if(fruitName == “lemon”)
colorIndex=5;
else if(fruitName == “lime”)
colorIndex=6;
else if(fruitName == “plum”)
colorIndex=7;
else if(fruitName == “raspberry”)
colorIndex=8;
else if(fruitName == “strawberry”)
colorIndex=9;

analogWrite(redPin, redArray[colorIndex]);
analogWrite(greenPin, greenArray[colorIndex]);
analogWrite(bluePin, blueArray[colorIndex]);

if (debug == 1) {
Serial.print(fruitName);
Serial.print(” is composed of R”);
Serial.print(redArray[colorIndex]);
Serial.print(“, G”);
Serial.print(greenArray[colorIndex]);
Serial.print(“, B”);
Serial.println(blueArray[colorIndex]);
}

fruitName.remove(0); //removes (deletes) all of the inString so that it’s not used anymore
}

delay(100); // wait a bit, for serial data
}
//read a string from the serial and store it in a String
void readSerialString () {
//available() returns the number of bytes avaiable for reading from the serial port
if(!Serial.available()) { //if there’s no serial string received, do nothing
return;
}
else if (Serial.available()) {
fruitName=Serial.readString(); //read the entire serial input into a String variable
/*code for debugging fruitName
Serial.print(“Read in string: “);
Serial.print(fruitName);
Serial.println();*/
}
}

breadboard setup diffusor exteriorplum

Leave a Reply