Archive | DIY Electronics RSS feed for this section

Adding sound and using conductive thread as a pressure sensor

6 Dec

In our last meeting we used the conductive thread as a pressure sensor that triggers sound and turns the LEDs on. Conductive thread works as a cable for transferring electricity to the circuit, but can be also used as a pressure sensor. By connecting it to an analog pin of your Lilypad and observing the incoming values in the serial monitor of your Arduino sketch and then using these values to trigger some kind of behaviour, you can add interactivity to your circuit. So we decided to use this incoming values to trigger a sound function and added a speaker (the lilypad buzzer) in order to reproduce certain notes. The melody is from Kraftwerk’ s Transeurope Express anthem ;D

Source code:

int ledPin = 6; // LEDs are connected to digital pin 6
int speakerPin = 9; // speaker connected to digital pin 9
int sensorPin = 3; // conductive thread sensor is connected to analog pin 3
int sensorValue; // variable to store the value coming from the sensor

void setup()
{
pinMode(ledPin, OUTPUT); // sets the ledPin to be an output
pinMode(speakerPin, OUTPUT); // sets the speakerPin to be an output
Serial.begin(9600); // initialize the serial port
digitalWrite(17, HIGH); // sets analog pin a2 to high
}

void loop() // run over and over again
{
sensorValue = analogRead(sensorPin); // read the value from the sensor
Serial.println(sensorValue); // send that value to the computer
if (sensorValue {
scale(); // call the scale() function
delay(1000); // delay for 1 second
}
}

void beep (unsigned char speakerPin, int frequencyInHertz, long timeInMilliseconds) // sound producing function
{
int x;
long delayAmount = (long)(1000000/frequencyInHertz);
long loopTime = (long)((timeInMilliseconds*1000)/(delayAmount*2));
for (x=0;x {
digitalWrite(speakerPin,HIGH); // turn the speaker on
delayMicroseconds(delayAmount);
digitalWrite(speakerPin,LOW); // turn the speaker off
delayMicroseconds(delayAmount);
}
}

void scale () // melody function
{
digitalWrite(ledPin,HIGH); //turn on the LEDs
beep(speakerPin,196,500); //G 3
beep(speakerPin,207,500); //Ab 3
beep(speakerPin,277,450); //Db 4
beep(speakerPin,261,500); //C 4
beep(speakerPin,196,250); //G 3
beep(speakerPin,207,450); //Ab 3
beep(speakerPin,261,250); //C 4
beep(speakerPin,233,750); //Bb 3
beep(speakerPin,196,500); //G 3
beep(speakerPin,207,500); //Ab 3
beep(speakerPin,277,500); //Db 4
beep(speakerPin,261,500); //C 4
beep(speakerPin,233,250); //Bb 3
beep(speakerPin,261,750); //C 4
digitalWrite(ledPin,LOW); //turn off the LEDs
}

Advertisements

Using a switch

22 Nov

Continuing with the experiments on our Tron-like LED bracelet we added a switch to make it more comfortable to turn the Lilypad on and off without having to touch the board.

We used alligator clips for this experiment, but you can also use conductive thread.

Start by attaching the On pin of the switch to one of the digital pins of the board (we used the pin 5) and the Off pin to the – pin of the board. Then connect your Lilypad to the computer and add the switch in your code. We kept the LEDs blinking like in the previous example.

Source code:

int ledPin = 6; // LED is connected to digital pin 6
int switchPin = 5; // switch connected to digital pin 5
int switchValue; // a variable to keep track of when switch is pressed

void setup()
{
pinMode(ledPin, OUTPUT); // sets the ledPin to be an output
pinMode(switchPin, INPUT); // sets the switchPin to be an input
digitalWrite(switchPin, HIGH); // sets the default (unpressed) state of switchPin to HIGH
}

void loop() // run over and over again
{
switchValue = digitalRead(switchPin); // check to see if the switch is pressed
if (switchValue == LOW) { // if the switch is pressed then,
digitalWrite(ledPin, HIGH); // turn the LED on
delay(1000); // wait for a second
digitalWrite(ledPin, LOW); // set the pin 6 LED off
delay(1000);
}
else { // otherwise,
digitalWrite(ledPin, LOW); // turn the LED off
}
}

Second step: a LEDs bracelet

17 Nov

Connecting the Lilypad to the cloth, with 5 white LEDs in a row and conductive thread.

Source code:

/*
Blink
Turns on a series of LEDs on for one second, then off for one second, repeatedly.

This example code is in the public domain.

Modified by smartcraftLab on 2011
*/

void setup() {
// initialize digital pin 6 as outputs.
pinMode(6, OUTPUT); // Pin 6 is connected to an LED

}

void loop() {
digitalWrite(6, HIGH); // set the pin 6 LED on
delay(1000); // wait for a second
digitalWrite(6, LOW); // set the pin 6 LED off
delay(1000); // wait for a second
}

First steps

10 Nov

In our first meeting as a group, we got familiar with the Lilypad Arduino board, its digital and analog pins and we started to experiment with LEDs. We started by connecting one white LED in our Lilypad board and then we added one more and programmed them to blink one at a time.

We experimented with the Blink example that comes with the Arduino 0.22 platform. Source code:

/*
  Blink
 Turns on an LED on for one second, then off for one second, repeatedly.

 This example code is in the public domain.

 Modified by smartcraftLab on 2011
 */

void setup() {
  // initialize the digital pins as outputs.
  pinMode(5, OUTPUT); // Pin 5 is connected to an LED
  pinMode(6, OUTPUT); // Pin 6 is connected to an LED

}

void loop() {
  digitalWrite(5, HIGH); // set the pin 5 LED on
  digitalWrite(6, LOW);  // set the pin 6 LED off
  delay(1000);           // wait for a second
  digitalWrite(6, HIGH); // set the pin 6 LED on
  digitalWrite(5, LOW);  // set the pin 5 LED off
  delay(1000);           // wait for a second
}

A introduction to Lilypad Arduino

10 Nov

The LilyPad Arduino microcontroller is a set of sewable electronic components that let you build your own soft, interactive clothes, fabrics, embroideries or even drawings if you use it with conductive ink. It is created by Leah Buechley, an MIT professor and director of the High-Low Tech Group and by Sparkfun Electronics. It is programmed with the Arduino open-source platform.

If you are interested in soft circuits and using the Lilypad, start by consulting the Setup Tutorial by Leah Buechley:http://web.media.mit.edu/~leah/LilyPad/01_computer_attach.html

And check out this cool and orientating powerpoint introduction we found on-line.
View more presentations from marrije