Creating My Own Mini Glacier

For this project, I attempted to recreate the glaciers I saw on a recent trip to Iceland. The jagged edges of the ice coupled with the pure blue color was an image that I’ll never forget and wanted to replicate. I used an Arduino board and 3 LEDs – Red, Green, and Blue – and I used a plastic shower cap to diffuse the light. Using specific keystrokes I was able to control the intensity of each of the LED’s brightness. For example, by pressing capital “R”, “G”, or “B” would result in the corresponding LED to increase it’s brightness by 50. If the lowercase letter was pressed, the intensity would increase by 15.

Components:

  1. Adruino board
  2. Breadboard
  3. 3 LEDs (red, green, blue)
  4. 3 ohm resistors
  5. 4 wires
  6. 1 plastic shower cap

 

Code:

char serInString[100]; // array that will hold the different bytes of the string. 100=100characters;
// -> you must state how long the array will be else it won’t work properly
char colorCode;
int colorVal;
int redVal;
int greenVal;
int blueVal;
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
void setup() {
pinMode(redPin, OUTPUT); // sets the pins as output
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
Serial.begin(9600);
analogWrite(redPin, 127); // set them all mid-brightness
analogWrite(greenPin, 127); // set them all mid-brightness
analogWrite(bluePin, 127); // set them all mid-brightness
Serial.println(“enter color command using r’s, b’s, g’s, R’s, B’s, and G’s (e.g. ‘rrrrrrggggg’ ‘RRBBGG’ RRRRR’) :”);
}
void loop () {
// clear the string
memset(serInString, 0, 100);
//read the serial port and create a string out of what you read
readSerialString(serInString);
// initialize all back to zero for each loop
redVal = 0;
greenVal = 0;
blueVal = 0;
colorCode = serInString[0];
if( colorCode == ‘r’ || colorCode == ‘g’ || colorCode == ‘b’ || colorCode == ‘R’ || colorCode == ‘G’ || colorCode == ‘B’) {
// increment each color based on number of each letter
for (int i = 0; i < strlen(serInString); i++) {
switch(serInString[i]) {
case ‘r’:
redVal += 15;
break;
case ‘g’:
greenVal += 15;
break;
case ‘b’:
blueVal += 15;
break;
case ‘R’:
redVal += 50;
break;
case ‘G’:
greenVal += 50;
break;
case ‘B’:
blueVal += 50;
}
}
Serial.print(“Setting color “);
Serial.println();
Serial.print(“red to “);
Serial.print(redVal);
Serial.println();
Serial.print(“green to “);
Serial.print(greenVal);
Serial.println();
Serial.print(“blue to “);
Serial.print(blueVal);
Serial.println();
serInString[0] = 0; // indicates we’ve used this string
analogWrite(redPin, redVal);
analogWrite(greenPin, greenVal);
analogWrite(bluePin, blueVal);
}
delay(100); // wait a bit, for serial data
}
//read a string from the serial and store it in an array
//you must supply the array variable
void readSerialString (char *strArray) {
int i = 0;
if(!Serial.available()) {
return;
}
while (Serial.available()) {
strArray[i] = Serial.read();
i++;
}
}

 

DSC_0411

Below an Icelandic glacier; what I wanted to mimic.

 

IMG_7384 IMG_7385 IMG_7386 IMG_7387

Lights changing video

Leave a Reply