Social Body Process Work

For the Social Body project, I focused more of the exploratory design process as to further my learning in regards to proximity sensor input and audio output.  I had planned on also studying servo/motor output but the audio/melody/tone testing gobbled up so much of my time.

I wanted to create the base mechanics for a garment which would mediate and deter strangers from approaching or standing too close to the wearer while riding the TTC.

Most of my time on this project was spent researching how proximity sensors and audio outputs worked, since I had never worked with either of those mediums before. First, I played with the proximity sensor and a analog input – serial output code which included an LED for further indication.  I was happy with the immediate results that I received from the proximity sensor, and I found that very encouraging.

Social Body Project – Prox Sensor Test
Hilary Hayes 2011
Sourced from buts of Analog Input, Serial Output and Proximity Sensor code samples found on Arduino.cc
Modified and built by Hilary Hayes
Reads an analog input pin, prints the results to the serial monitor and
modifies the LED luminosity, mapping the returned values from 0 to 255 (using PWM)
*/
int ledPin =  9;            // LED connected to digital pin 9
int sensorPin = 2;        // value read from the sensor
int outputValue = 0;        // value output to the PWM (analog out)
void setup() {
Serial.begin(9600);
}
void loop() {
// read the analog input
int analogValue = analogRead(sensorPin);
// NOTE: you should modify following script in according with your project goals, resistors and used sensors.
// Sensors return values from 0 until 1023 but I mapped them from 250 to 900 to get a better visual result.
// The map() method will return us a value from 0 to 255, good PWM values to turn on my LED
outputValue = map(analogValue, 250, 900, 0, 255);
// Some sensors, when their value is near to zero, return a variable value between 2 and 3, creating a loop
// that could generate bad visual effects. To avoid this issue I always turn off the LEd when sensor value is < 5
if (outputValue<5)
analogWrite(ledPin, 0);
else
analogWrite(ledPin, outputValue);
// print the result to the serial monitor
Serial.print(analogValue);
Serial.print(” : “);
Serial.print(outputValue);
Serial.println(“—-“);
// wait 10 milliseconds for the analog-to-digital converter
delay(10);
}

And this:

/*Social Body Project- Proximity sensor code sample

*/

int sensorPin = 0;    // input pin for the sensor

int barPin[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11};

int barPinCount = 10;

int volt = 0;  // variable to store the value coming from the sensor

int zeit = 100; // *10 = Gesamtzeit – total time

void setup() {

Serial.begin(9600);

int thisPin;

// the array elements are numbered from 0 to (pinCount – 1).

// use a for loop to initialize each pin as an output:

for (int thisPin = 0; thisPin < barPinCount; thisPin++)  {

pinMode(barPin[thisPin], OUTPUT);

}

}

void loop() {

int volt = 0;

for(int i=0; i<10; i++)

{

volt += analogRead(sensorPin);

delay(zeit);

}

volt /= 10;

Serial.println(volt);

int litCount = 0;

if (volt <= 82) {

// >= 80cm

litCount = 1;

} else if (volt <= 92) {

// >= 70cm

litCount = 2;

} else if (volt <= 102) {

// >= 60cm

litCount = 3;

} else if (volt <= 123) {

// >= 50cm

litCount = 4;

} else if (volt <= 154) {

// >= 40cm

litCount = 5;

} else if (volt <= 184) {

// >= 30cm

litCount = 6;

} else if (volt <= 266) {

// >= 20cm

litCount = 7;

} else if (volt <= 328) {

// >= 15cm

litCount = 8;

} else if (volt <= 461) {

// >= 10cm

litCount = 9;

} else if (volt > 461) {

// < 10cm

litCount = 10;

}

for(int b=0; b<10; b++)

{

if(b < litCount)

digitalWrite(barPin[b], HIGH); // Turn the bar on

else

digitalWrite(barPin[b], LOW); // Turn the bar off

}

}

I started playing around with programming audio and running a few modified sample codes, but that work was very slow and frustrating. I got a few melodies to work, but it mas very time consuming and really, what I needed to do was to work with an MP3 Trigger, which would require further research and learning, that would be more difficult since I was not able to afford any further materials.
My plan was to get each part of the code working so that I could understand each input and output, and then combine them.
/* Play Melody
* ———–
*
* Program to play melodies stored in an array, it requires to know
* about timing issues and about how to play tones.
* Updated by Hilary Hayes
* The calculation of the tones is made following the mathematical
* operation:
*
*       timeHigh = 1/(2 * toneFrequency) = period / 2
*
* where the different tones are described as in the table:
*
* note frequency period PW (timeHigh)
* c 261 Hz 3830 1915
* d 294 Hz 3400 1700
* e 329 Hz 3038 1519
* f 349 Hz 2864 1432
* g 392 Hz 2550 1275
* a 440 Hz 2272 1136
* b 493 Hz 2028 1014
* C 523 Hz 1912 956
*
* (cleft) 2005 D. Cuartielles for K3
*/
int ledPin = 13;
int speakerOut = 9;
byte names[] = {
‘c’, ‘d’, ‘e’, ‘f’, ‘g’, ‘a’, ‘b’, ‘C’};
int tones[] = {
1915, 1700, 1519, 1432, 1275, 1136, 1014, 956};
byte melody[] = “2d2a1f2c2d2a2d2c2f2d2a2c2d2a1f2c2d2a2a2g2p8p8p8p”;
// count length: 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
//                                10                  20                  30
int count = 0;
int count2 = 0;
int count3 = 0;
int MAX_COUNT = 24;
int statePin = LOW;
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
analogWrite(speakerOut, 0);
for (count = 0; count < MAX_COUNT; count++) {
statePin = !statePin;
digitalWrite(ledPin, statePin);
for (count3 = 0; count3 <= (melody[count*2] – 48) * 30; count3++) {
for (count2=0;count2<8;count2++) {
if (names[count2] == melody[count*2 + 1]) {
analogWrite(speakerOut,500);
delayMicroseconds(tones[count2]);
analogWrite(speakerOut, 0);
delayMicroseconds(tones[count2]);
}
if (melody[count*2 + 1] == ‘p’) {
// make a pause of a certain size
analogWrite(speakerOut, 0);
delayMicroseconds(500);
}
}
}
}
}
This project was largely a very positive research and learning experience. While I am not pleased that I was not able to create a functioning prototype in time to meet the deadline, I am very happy with how much I learned and I look forward to the Final Project.

Leave a Reply

A sample text widget

Etiam pulvinar consectetur dolor sed malesuada. Ut convallis euismod dolor nec pretium. Nunc ut tristique massa.

Nam sodales mi vitae dolor ullamcorper et vulputate enim accumsan. Morbi orci magna, tincidunt vitae molestie nec, molestie at mi. Nulla nulla lorem, suscipit in posuere in, interdum non magna.