Color Away!
Description:
In this lab, we further explore different sensing devices as inputs to the Arduino Board. In particular we use the photocells and force sensitive resistor (FSR) as inputs and using the values recorded create a visual representation for the user using the Processing UI application.
Components Used:
- Arduino Micro-controller
- 2 10K Resistor
- Wires/Bread Board
- Sensors (FSR and Photocell)
- Paper clip and card (to create a shade for the photocell)
- Small cardboard box ( to uniformly distribute the force over the fsr)
Programming- 'Color Away':
My inspiration was the IO brush which brings the visual world closer to the real world by picking colors using the surroundings. So I decided to create "Color Away" which allows you to pick colors and change the width of the strokes by controlling physical quantities like light and force!
How it works:
The user can use the potentiometer to control the brightness of the LED which inturn affects the light sensor readings and depending on the readings , the shades/paints become darker or more colorful and brighter. Also,the user can place different objects in the cardboard box and depending on the wieght of the object the width of the stroke changes.
Design Issues : Initially I tried to use the hand to control the light sensor, however using the hand lead to shaky readings and it also required the user to hold the hand over the light sensor for a long time if they wanted dark shades. So I decided to use the potentiometer and the led instead, as it offers more control over the sensor readings and also makes the readings independent of the room lighting.
Click here to see the video: Color Away
Arduino Code:
int potPin = 0; // select the input pin for the potentiometer
int fsrPin = 1; // select input pin for fsr
int photoPin = 2; //select input pin for photocell
int ledPin = 9; // select the pin for the LED
int potVal = 0; // variables to store the values coming from the sensor
int fsrVal = 0;
int photoVal = 0;
void setup() {
Serial.begin(9600);
}
// Main program
void loop()
{
potVal = analogRead(potPin);
fsrVal = analogRead(fsrPin);
photoVal = analogRead(photoPin);
analogWrite(ledPin, potVal/4); // Control brightness of led to influence photo sensor
Serial.print('f');
Serial.println(fsrVal);
Serial.print('p');
Serial.println(photoVal);
delay(50);
}
Processing Code:
import processing.serial.*;
String portname = "COM13";
Serial port;
String buf = "";
int cr = 13; // ASCII return == 13
int lf = 10; // ASCII linefeed == 10
int x1;
int y1;
int x2 = 0;
int y2 = 1024;
int weight = 0;
float light = 0;
void setup()
{
size(800, 800);
frameRate(10);
smooth();
background(#ffffff);
noStroke();
port = new Serial(this, portname, 9600);
}
void draw() {
}
void keyPressed() {
if(key == ' ') {
background(#ffffff); // erase screen
}
else {
int x = int(mouseX);
int y = int(mouseY);
drawline(x,y, int(light));
}
}
void drawline(int x, int y, int light) {
int rand1 = int(random(light));
int rand2 = int(random(light));
int rand3 = int(random(light));
for (int i=0; i<100; i++ ) {
stroke(int(light));
strokeWeight(weight);
stroke(rand1, rand2, rand3);
line(x1, y1,x2, y2);
}
}
void serialEvent(Serial p) {
int c = port.read();
if (c != lf && c != cr) {
buf += char(c);
}
if (c == lf) {
char indicator = buf.charAt(0);
println("val="+indicator);
buf = buf.substring(1, buf.length());
println("buffer value" + buf);
if (indicator == 'f') {
weight = abs(int(buf))/ 20;
println(weight);
} else if (indicator == 'p') {
light = float(buf) / 4;
println("l" + light);
x1 = x2;
x2 = int(mouseX);
y1 = y2;
y2 = int(mouseY);
drawline(x2, y2 , int(light));
}
buf = "";
}
}