In order to later be able to produce a light output on the costume with flex/bend sensors on a special movement, that we observed at the dancers’ rehearsal, I worked on connecting more than oneĀ of these sensors to the LilyPad Arduino. I also added an LED to the circuit to better be able to write the code, especially regarding possible adjustments, that might need to be made for each individual wearing the costume.
As this looks quite messy as a circuit, I found it necessary to make a Fritzing sketch of it:
The code I wrote is easily adjustable to different dancers who all might have different postures. Here it is:
//Program lights LED, if 3 Flex/Bend Sensors are being bent
int led = 5;
void setup()
{
pinMode(led, HIGH);
// initialize serial communications
Serial.begin(9600);
}
void loop()
{
int sensor0, degree0, sensor1, degree1, sensor2, degree2;
// read amount of flexing/bending from input
sensor0 = analogRead(A0);
sensor1 = analogRead(A1);
sensor2 = analogRead(A2);
// map sensor input to approximate angle between 0 and 90 degree
//attention: these values are not an exact angle at all!
degree0 = map(sensor0, 528, 730, 0, 90);
degree1 = map(sensor1, 528, 730, 0, 90);
degree2 = map(sensor2, 480, 713, 0, 90);
//if all 3 sensors are bend in positive direction
//and reach an angle of min 50 degree, led turns on
if(degree0 >= 50)
{
if(degree1 >= 50)
{
if(degree2 >= 50)
{
digitalWrite(led, HIGH);
}
else
{
digitalWrite(led, LOW);
}
}
else
{
digitalWrite(led, LOW);
}
}
else
{
digitalWrite(led, LOW);
}
// print out the result
Serial.print("analog input A0: ");
Serial.print(sensor0);
Serial.print(" degree 0: ");
Serial.println(degree0);
//delay(500); //CAREFUL: DELAY ALSO AFFECTS LED!
Serial.print("analog input A1: ");
Serial.print(sensor1);
Serial.print(" degree 1: ");
Serial.println(degree1);
//delay(500); //CAREFUL: DELAY ALSO AFFECTS LED!
Serial.print("analog input A2: ");
Serial.print(sensor2);
Serial.print(" degree 2: ");
Serial.println(degree2);
// pause before taking the next reading
//delay(1000); //CAREFUL: DELAY ALSO AFFECTS LED!
}