# temperature sensing textile with lilypad simplesnap

Hi
I'm trying to make a temperature sensing textile with a lilypad simplesnap, lilypad temperature sensor and 3 leds. When I prototyped it I had the + side of the leds on 9, 10 and 11 and - connected to - , and this worked. However when I came to sew it, that meant 4 threads (including the sensor) going to one connection and I was worried about shorts. So I connected the - on the first led to minus on the lilypad and the + on the led to 5. The other leds are + to +, and minus to 9 and 11. Here is the code:

``````float temp,tempAvg, tempA;

long previousMillis = 0;
long interval = 2000;

int count = 0;

int ledPin1 = 5;       //put the LED light on pin 5
int ledPin2 = 9;      //put the LED light on pin 9
int ledPin3 = 11;      //put the LED light on pin 11

/*int positivePin = A5;   //setting A5 to be a positive pin.*/

int brightness1 = 15;    // how bright the LED is
int fadeAmount1 = 5;    // how many points to fade the LED by

int brightness2 = 25;    // how bright the LED is
int fadeAmount2 = 5;    // how many points to fade the LED by

int brightness3 = 45;    // how bright the LED is
int fadeAmount3 = 5;    // how many points to fade the LED by

void setup() {

Serial.begin(57600);

pinMode(ledPin1, OUTPUT); //Setting LED 1 (lightPin1) to be an output. Ditto for each of the other LEDs
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);

};

void loop () {

unsigned long currentMillis = millis();

if(currentMillis - previousMillis > interval) {

temp = temp - 0.5;
temp = temp / 0.01;

Serial.print("temp: ");
Serial.println(temp);

//tempAvg = tempAvg + temp;
//count++;
//if (count > 7) {
//  tempA = tempA - temp;
//  count = 0;
//}
//
//tempA = tempAvg/8.;
//
//  Serial.print("tempA: ");
//  Serial.println(tempA);

previousMillis = currentMillis;
}

if ((temp >= 25.0) && (temp < 32.0)) {

// set the brightness of all three LEDS:
analogWrite(ledPin1, max(brightness1, 0));
analogWrite(ledPin2, max(brightness2, 0));
analogWrite(ledPin3, max(brightness3, 0));

// change the brightness for next time through the loop:
brightness1 = brightness1 + fadeAmount1;
brightness2 = brightness2 + fadeAmount2;
brightness3 = brightness3 + fadeAmount3;

} else if ((temp >= 20.0) && (temp < 25.0)) {
// do something else
void loop();

digitalWrite(ledPin1, HIGH);   // sets the LED on
delay(1000);                  // waits for a second
digitalWrite(ledPin1, LOW);    // sets the LED off
delay(1000);                  // waits for a second

digitalWrite(ledPin2, HIGH);   // sets the LED on
delay(1000);                  // waits for a second
digitalWrite(ledPin2, LOW);    // sets the LED off
delay(1000);                  // waits for a second

digitalWrite(ledPin2, HIGH);   // sets the LED on
delay(1000);                  // waits for a second
digitalWrite(ledPin2, LOW);    // sets the LED off
delay(1000);                  // waits for a second

}

else ((temp >= 25.0) && (temp < 32.0)); {
// do something else
void loop();

digitalWrite(ledPin1, HIGH);   // sets the LED on all the time
digitalWrite(ledPin2, HIGH);   // sets the LED on all the time
digitalWrite(ledPin3, HIGH);   // sets the LED on all the time

}

delay(500);

};
``````

The led on 5 is on all the time and the other ones just blink. Should I have put all the leds + to + and _ to pins 5,9,11? Or is there something else going on? The temperature sensor serial monitor is fine.

Thanks

Just connect all the led's to GND(AKA -, aka cathode ) and the other led pins(aka anodes) to the pins numbers.