Skip to content

GIT Workshop: Wearable Tech

Part 1: Wearable Tech basics

LED or light emitting diode, lights up when electricity passes through it. For an LED it matters which lead is connected to the positive or negative side of a battery.

LED

To tell which lead of a LED is positive or negative we look at the length of each lead. The positive lead will be slightly longer than the negative LED. Lets test this with a 3v battery.

P1030032

Place the battery between the LED legs so that the positive lead touches the the battery side marked with a +.

You have just created a circuit. A circuit  allows a path for electricity to flow.

electricity can only flow between power and ground.
If a circuit is open, electricity won’t flow and the LED won’t light.

There are many ways to complete the same circuit. We can add other conductive objects like alligator clips, magnets or other house hold items to achieve  this circuit.

AlKeyFab

In this workshop we will be connecting our circuits with conductive thread.
Connect positive LED leg to D3 on Squarewear and the negative side to GND
641-05
Tips on Sewing with Conductive thread

nolossP1030065

Part 2: Wearable Tech with Mirco controller

IMG_3655

About Workshop:

                    SquareWear microcontroller — how do we use it?

Think of Microcontrollers as the brain to your project. If we wanted your LED (light emitting diode) to react to our environment a microcontroller is the part of the project that takes in that information and then relays a response with an LED.

SquareWear was designed to create wearable tech easily. Its flat and compact design allows the designer to easily incorporate SquareWear into textiles. SquareWear is built on the Arduino platform, but offers many more onboard components than the Arduino Uno.

Materials needed

  • SquareWear microcontroller
  • USB cable

 SquareWear’s built-in components:

Tri-color LED (output)

Digital pins 8 (red), 13 (green) and 12 (blue)

Photoresistor (input)

Analog pin 0 (A0)

Temperature sensor (input)

Analog pin 1 (A1)

Buzzer (output)

Digital pin 9

Push-button (input)

Digital pin 4

SquareWear is also equipped with a rechargeable 3.6v coin battery;

it will charge whenever the USB cable is plugged in. There is also the option for using an external LiPo battery.

If your battery has lost its charge, you will be unable to Upload a sketch to your SquareWear. Leave it plugged in for around 30 minutes to get enough charge.

Never have both the onboard coin battery and external LiPo batteries plugged in at the same time! Choose exactly one power source.




Let’s get Started!

Plug your SquareWear in to a usb port on your computer using a micro usb cable. Once your SquareWear in plugged in we can now set up your SquareWear!

stickers_logo_text

Now that your SquareWear is all set up lets upload some example code!

In the menu, go to File -> Examples where you will see a list of different kinds of sample code. Select 01. Basics -> Blink.

exampleCode

Upload the code using the button at the top of the window.

upload

You should be able to see a LED on the SquareWear blink green!

Lets modify this code

The LED on the SquareWear is actually a tri-LED. This means it can display red, green and blue lights.

Each of these colors are controlled by a different [pin].

12 = Blue
13 = Green
8 = Red

Lets test this:

Edit the Blink sketch to replace 13 with 12.
Screen Shot 2015-10-15 at 12.16.49 PM
*Note depending on your version of Arduino you may have a [variable] which is holding the value 13 or you may have 13 written through out your code as you see in our example

Upload the sketch.
You should now see that the blinking light has turned from green to blue!

Now edit the Blink sketch to replace 12 with 8.

Upload the sketch
You should now see that the blinking light has turned from blue to red.

Now let’s try to flash the colors one after the other. We can do this by adding [variables] to hold the pins for each color.

Copy the following code into a new Sketch (File-> New) and Upload it.

int redLED = 8;
int blueLED = 13;
int greenLED = 12;

// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(redLED, OUTPUT);
pinMode(blueLED, OUTPUT);
pinMode(greenLED, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
digitalWrite(redLED, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(redLED, LOW); // turn the LED off by making the voltage LOW
delay(1000); //wait for a second
digitalWrite(blueLED, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(blueLED, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
digitalWrite(greenLED, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(greenLED, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}

Let’s get familiar with the LED by writing some simple code.

  • Modify the Blink code so that pin 13 LED to constantly shine solid blue.

Screen Shot 2015-10-15 at 12.45.46 PM

Edit and upload the sketch to make the blue (13) LED shine with the green (12) LED.

Screen Shot 2015-10-15 at 12.46.54 PM

If done correctly, you should be able to see light blue/cyan!



Now try having both red (8) and blue (13)

Screen Shot 2015-10-15 at 12.49.26 PM

Now you should see magenta /purple!

What color do you get if you mix red and green?

What if you mix all of the colors?

Now that you have had some practice working with the built in LED let’s take a look at other on board and off board features.

Photocell (Light) and Temperature
Buzzer
Neopixel

 

*
Sound sensor

Written by Shani Mensing, edited by Audrey St. John

Circuit: microphone VCC connected to 3.3V, OUT to analog input A0
*/

// hook up the out of the mic to analog input A0
#define MIC_IN 2
#define LED_1 3
#define LED_2 5
#define LED_3 2
#define LED_4 11
#define LED_5 7
// Sample window width in milliseconds (50 ms = 20Hz)
int sampleWindow = 50;

/**
* Initialization code
**/
void setup()
{
// open serial port and set data rates to 9600 bps (bits-per-second)
// this lets us communicate to/from the arduino
Serial.begin(9600);

pinMode( LED_1, OUTPUT );

digitalWrite( LED_1, LOW );

pinMode( LED_2, OUTPUT );
digitalWrite( LED_2, LOW );

pinMode( LED_3, OUTPUT );
digitalWrite( LED_3, LOW );

pinMode( LED_4, OUTPUT );
digitalWrite( LED_4, LOW );

pinMode( LED_5, OUTPUT );
digitalWrite( LED_5, LOW );
}

/**
* Main program loop happens constantly.
**/
void loop()
{
// read the analog sensor as volts
double soundSensed = sampleSoundPeak();

Serial.println( soundSensed );
// print out the range it falls in, dividing into 5 parts
//Serial.println(rangePart( soundSensed, 5 ) );

// turn on LEDs based on the range
//lightLEDs( rangePart( voltsSensed, 5 ) );

// a higher number of parts will make this more sensitive
lightLEDs( rangePart( soundSensed, 10 ) );
}

/////////////// Our own methods
/**
* For 5 different LEDs, light up
* all LEDs <= maxLED, where maxLED is [0,5)
**/
void lightLEDs( int maxLED )
{

// first set them all to low
digitalWrite( LED_1, LOW );
digitalWrite( LED_2, LOW );
digitalWrite( LED_3, LOW );
digitalWrite( LED_4, LOW );
digitalWrite( LED_5, LOW );

// then, light them depending on the range
switch ( maxLED )
{
case 5:
digitalWrite( LED_5, HIGH );
Serial.println(LED_5);
case 4:
digitalWrite( LED_4, HIGH );
Serial.println(LED_4);
case 3:
digitalWrite( LED_3, HIGH );
Serial.println(LED_3);
case 2:
digitalWrite( LED_2, HIGH );
Serial.println(LED_2);
case 1:
digitalWrite( LED_1, HIGH );
Serial.println(LED_1);
}
Serial.println(“end!!!!”);
}

/**
* Given a value between 0 and 1024,
* determine which part of the range it falls in,
* dividing the range into n equal parts
**/
int rangePart( double value, int n )
{
// first divide the range
double partSize = 1024 / n;

// now see how many parts in the value
return floor( value / partSize );
}

/**
* Sense biggest input difference are being input from the analog MIC sensor
* over a certain “window” of time.
* Values returned are in the range 0 – 1024.
**/
double sampleSoundPeak()
{
// record start time
double startMillis = millis();

// this will be the highest peak, so start it very small
int signalMax = 0;

// this will be the lowest peak, so start it very high
int signalMin = 1024;

// will hold the current value from the microphone
int sample;

// collect data for 50 ms
while ( (millis() – startMillis) < sampleWindow )
{
// read a value from mic and record it into sample variable
sample = analogRead( MIC_IN );

// toss out spurious readings
if (sample < 1024)
{

// if the current sample is larger than the max
if (sample > signalMax)
{
// this is the new max — save it
signalMax = sample;
}
// otherwise, if the current sample is smaller than the min
else if (sample < signalMin)
{
// this is the new min — save it
signalMin = sample;
}
}
}

// now that we’ve collected our data,
// determine the peak-peak amplitude as max – min
int peakDifference = signalMax – signalMin;

// give it back to the caller of this method
return peakDifference;
}