Colored Smoke Cylinder

Description:
I used dryer sheets, ping pong balls and the cotton-like material that we had used in class to create an impression of a smoke chimney. The diffuser gives a very close approximation of white and the output is in RGB format. Of the things I had trouble with was using only a single input (no carriage return) and changing the color. The blue was also the strongest LED in the set and hence the resultant white had a tinge of blue.

Components:
I used dryer sheets, ping pong balls and the cotton-like material that we had used in class to create an

  • 1 Arduino Uno
  • 1 Breadboard
  • Resistors, Jumper cables
  • Ping pong balls
  • Dryer sheets
  • Cotton-like material for impression of smoke

Code:

/*
Smoke cylinder by Ganesh Iyer
*/

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 colorValRed = 0;
int colorValBlue = 0;
int colorValGreen = 0;

int redPin = 11; // Red LED, connected to digital pin 9
int greenPin = 9; // Green LED, connected to digital pin 10
int bluePin = 10; // 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, 0); // set them all to mid brightness
analogWrite(greenPin, 0); // set them all to mid brightness
analogWrite(bluePin, 0); // set them all to mid brightness
Serial.println("Use the r, g and b keys to manipulate and mix colors!");
}

void loop () {
// clear the string
memset(serInString, 0, 100);
//read the serial port and create a string out of what you read
readSerialString(serInString);

colorCode = serInString[0];
if (colorCode == 'r'){
serInString[0] = 0;
if (colorValRed == 255){
colorValRed = 0;
analogWrite(redPin, colorValRed);
}
else{
colorValRed = colorValRed + 20;
}
if (colorValRed < 255){ analogWrite(redPin, colorValRed); } else{ colorValRed = 255; analogWrite(redPin, colorValRed); } Serial.print("RGB( "); Serial.print(colorValRed); Serial.print(", "); Serial.print(colorValGreen); Serial.print(", "); Serial.print(colorValBlue); Serial.print(" )"); Serial.println(); } if (colorCode == 'g'){ serInString[0] = 0; if (colorValGreen == 255){ colorValGreen = 0; analogWrite(greenPin, colorValGreen); } else{ colorValGreen = colorValGreen + 20; } if (colorValGreen < 255){ analogWrite(greenPin, colorValGreen); } else{ colorValGreen = 255; analogWrite(greenPin, colorValGreen); } Serial.print("RGB( "); Serial.print(colorValRed); Serial.print(", "); Serial.print(colorValGreen); Serial.print(", "); Serial.print(colorValBlue); Serial.print(" )"); Serial.println(); } if (colorCode == 'b'){ serInString[0] = 0; if (colorValBlue == 255){ colorValBlue = 0; analogWrite(bluePin, colorValBlue); } else{ colorValBlue = colorValBlue + 20; } if (colorValBlue < 255){ analogWrite(bluePin, colorValBlue); } else{ colorValBlue = 255; analogWrite(bluePin, colorValBlue); } Serial.print("RGB( "); Serial.print(colorValRed); Serial.print(", "); Serial.print(colorValGreen); Serial.print(", "); Serial.print(colorValBlue); Serial.print(" )"); Serial.println(); } // if( colorCode == 'r' || colorCode == 'g' || colorCode == 'b' ) { // colorVal = atoi(serInString+1); // Serial.print("setting color "); // Serial.print(colorCode); // Serial.print(" to "); // Serial.print(colorVal); // Serial.println(); // serInString[0] = 0; // indicates we've used this string // if(colorCode == 'r') // analogWrite(redPin, colorVal); // else if(colorCode == 'g') // analogWrite(greenPin, colorVal); // else if(colorCode == 'b') // analogWrite(bluePin, colorVal); // } 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; } if (Serial.available() > 0) {
strArray[i] = Serial.read();
}
}

Smoke cylinder

Leave a Reply