Upload
colleen-morgan
View
410
Download
0
Embed Size (px)
DESCRIPTION
The final workshop in the ThreadTech series. In this workshop participants used sensors with the Lilypad Arduino. These sensors included a light sensor, a temperature sensor and an accelerometer.
Citation preview
threadtech 3where fashion meets technology
The Edge | Colleen Morgan | Digital Visual Arts Catalyst
TimelineIntroduction to workshop materials
Take a look at some examples
Light Sensor
Temperature Sensor
Accelerometer
Other fun, useful links
Workshop Materials
conductive thread
lilypad light emitting diodes(LEDs)
Lilypad Pro Kit
Jumper Leads
Light Sensor
Temperature SensorAccelerometer
Examples
http://vimeo.com/20567677
Examples
http://www.youtube.com/watch?v=wgGWcFdDEws&feature=player_embedded
VJacket
Examples
http://www.youtube.com/watch?v=3q66T_x0Z7c
Electric Dress in Snow - Accelerometer and LEDs
Examples
http://www.youtube.com/watch?v=gaeYc0Iyt0k
LED Pants - Accelerometer and LEDs
Examples
http://www.youtube.com/watch?v=VG6NVdtaKKo&feature=related
Bono’s Laser Jacket
Examples
http://www.electricfoxy.com/zip/
Electricfoxy - ZIP
Control Your music with your zip
The Lilypad
An Arduino Micro Processor designed to be sewn.
Designed by Leah Buechley from MIT and SparkFun Electronics.
Can be programmed with the Arduino Software (Opensorce)
Is Washable!! (by hand)
The Lilypad
positive power supply(anode)
negative power supply
(cathode)
ResetButton
Digital I/O Pins1 - 13
Analog Input Pins
6 Pins For The FTDI Basic
Breakout Board
Arduino Software
Arduino is an opensource software
Free to download
Based on the C programming language and Processing Software
Runs on Windows, Mac OS and Linux
http://arduino.cc
Arduino Setup
1. Select Board: Lilypad Arduino w/ ATMega 328
2. Select Serial Port:
Mac will look something like this: /dev/tty.usbserial....
PC will look something like this: com1
http://arduino.cc
Tools Menu
Arduino Software
Text EditorFor Writing
Code
Toolbar
Debugging Text
Arduino ToolbarVerify/CompileChecks Code for Errors
Stop Open Sketch Upload
Serial MonitorSave SketchNew Sketch
Sketch Setup
sample code from arduino library
Light Sensor
Lilypad Light Sensor
20mm in Diameter
Light Sensor
The Lilypad Light Sensor uses an Analog Output value to sense Light. The sensor outputs values from 0 to 5V.
With exposure to bright light the sensor will output 5V. In total darkness the sensor will output 0V.
In normal indoor light contexts the sensor will output between 1 and 2V
Light Sensor
The Hardware Set Up
Analog Pin 0A0
Light SensorNow that we can see the values our sensor is spitting out we can start to use those values to control lights
We start off by defining some variables that we will use later on in our code.
Then in the setup procedure we begin the communication between the sensor and the computer. This is what the Serial.begin(9600) is all about. By doing this we are setting the Baud to 9600 which means we are communicating with the computer at a rate of 9600 bits per second.
In the loop procedure we then read the value the sensor is outputting and ask the computer to print it out for us so we can see it. We use the Serial.print function to get the computer to write the values for use to see.
Light SensorNow lets start on some code so that we can us the sensor values from the light sensor to control lights. First we need to define a couple of pins that we will attach LEDs to:
Now in our loop procedure we will write an if statement to get lights to switch on at different light values.
This if statement says: if the sensor value is less than 120 and greater than 70 then turn the LED attached to pin 13 on.
And it also has another possibility (the else if): if the sensor value is less than 50 and greater than 30 then turn the LEDs attached to pin 13 and 12 on.
Using these if and else if statements we are getting more lights to come on as it gets darker.
Light SensorWe can write the code in a slightly different way, so that it has the same effect on lights, but is easier to tweak depending on the type of light the garment will be in. We will start by defining some threshold values:
Now in our loop procedure we can change our if and else if statements to be based on the thresholds we have just defined.
Light SensorNow lets have a go at fading lights depending on light. We will write some code so that one LED fades in and one LED fades out as it gets darker. Lets take a look at the code:
Light SensorWe have a few interesting things going on in this code. Firstly we have a constraint so that we can determine the maximum and minimum readings of the light sensor depending on the light we are in at the moment.
Constraining the values to the maximum reading in the current light allows us to calibrate the light sensor to the current conditions in the room.
The next interesting thing is a map function. A map function allows us to re-map values from one range to another. The general form of a map function is:
map(value, fromLow, fromHigh, toLow, toHigh)
We are using a map function to convert the sensor readings to a value range between 0 and 255. We are doing this because we want to fade the LEDs so we need to make sure the values we are getting from the sensor can be ‘mapped’ within the Pulse With Modulation range of 0 - 255.
This is the map function we write to get the lights to fade out as it gets darker:
Light SensorTo get the lights to do the opposite, ie. to get the lights to fade in as it gets darker, we have to swap our toLow and toHigh values around. By doing this we are telling the computer that we want the lights to be at the brightest when the the light is as dark as it can get, and the lights to be at their dimmest when the light in the room is as bright as it can get.
Temperature Sensor
Lilypad Temperature Sensor (MCP9700)
20mm Diameter
Detects temps between -40C and +125C
Temperature Sensor
The Lilypad Temperature Sensor senses ambient temperature in a very simple and effective way.
The analog voltage it outputs is directly proportional to the temperature. (the analog voltage is independent of the power supply.)
We can use two very simple formulas to convert the voltage to temperature:
Voltage (in mV) = sensor reading * 3300.0/1024
Temp in °C = [voltage - 500] /10
Temperature Sensor
The Hardware Set Up
Analog Pin 0A0
Temperature SensorLets start by writing some code to read the values from our Temperature sensor:
This code allows us to print out the values from our sensor, both in raw analog values and in degrees celsius. We write float before our two formulas because we want to return values that are not necessarily whole numbers. Instead of writing ‘int’ which is short for integer or a whole number. We write ‘float’ to indicate that a number has a decimal point or is a floating point number. Floats can have up to 7 decimal points.
Temperature SensorNow that we can see what the temperature is we can write some code to get lights to come on at different temperature readings. Start by attaching two LEDs to the lilypad board and make sure you declare them as outputs in your setup procedure.
I have written some code so that a green light is on at the ambient temperature of the room and a red lights comes on when the temperature sensor is touched. With this code, your shirt could glow red when you get a hug from your friends!
As long as you are in a room that is cooler than 26 degrees that is!!
Remember you can tweak the code for different contexts.
Temperature SensorTo make our temperature readings a little more accurate we can do something called ‘Smoothing’. Smoothing is a technique of gathering a number or sample readings from the sensor and averaging it out to get an average reading. We will start by defining the variables we will need to do the smoothing.
int readings[sensorReadings]; is what we write to declare an array. An array is collection of variables that are accessed with an index number. We are using this array to store 5 readings from the temperature sensor.
We will then add each of the readings together an divide it by the number of readings in the index to get an average reading.
Temperature SensorHere is the code we need to write to make the smoothing happen:
Now our temperature readings and light changes will be a bit more accurate!!
Motion Sensor (Accelerometer)
Lilypad Accelerometer Sensor (ADXL335)
20mm Diameter
A three-axis accelerometer
Detects movement x, y and z axis.
Can be used to detect tilt and acceleration
The Hardware Set Up
Analog Pin 0
Analog Pin 1
Analog Pin 2
Motion Sensor (Accelerometer)
Motion Sensor (Accelerometer)We will start by writing some code to get readings from our accelerometer.
We have to declare some variables first and in our setup procedure we have to open the serial port to start communication between our sensor and the Lilypad and set our LED pins as outputs:
Motion Sensor (Accelerometer)In our loop procedure we can read each of our axes and send the values to the computer.
When you open your serial monitor you should see something a little like this:
When your sensor is flat you should get readings close to: X: 512, Y: 512, Z: 612
Motion Sensor (Accelerometer)Now that we can see the values we are getting from our accelerometer we can start to figure out how to write some code for lights to respond to the movement of the sensor.
The first sketch we are going to write will detect the tilt of the sensor on the x and y axis and fade LEDs accordingly. In order to write this code we need to figure out what values we get when we tilt the sensor. These are some approximate values that I came up with:
Tilt x-axis away = 370 (minimum value)Tilt x-axis towards = 630 (maximum value)
Tilt y-axis left = 370 (minimum value)Tilt y-axis right = 630 (maximum value)
Now we can use these values to write some code.
Motion Sensor (Accelerometer)The first thing we are going to do is write a function to constrain the sensor values we want to use:
To stay on the safe side I have made the maximum and minimum values inside the maximum and minimum values I identified earlier.
Now we want to map these constrained maximum and minimum values to the PWM range (between 0 and 255):
Now all we have to do is write those PWM values to our LEDs for each axis and add a delay that will give us a good balance between movement and glow:
Motion Sensor (Accelerometer)Now lets write a new sketch to detect the acceleration of the sensor on each of the three axes.
Acceleration is a measure of how fast the speed of something is changing.
Accelerometers provide an output voltage proportional to the linear acceleration in each axis. Zero acceleration (or zero-g offset) is usually defined as an output voltage equal to half the supply voltage. The Lilypad provides a supply of 3.3V, so this would be a zero-g offset equal to 1.65V or 1650mV. Voltages above 1.65V indicate a positive acceleration. Voltages below 1.65V indicate a negative acceleration.
The magnitude of the acceleration is typically expressed in units of g. 1g = the Earths gravitational acceleration (gravity). So when an accelerometer is still the z axis (up-down has a force of 1g.
Acceleration is caculated by finding the difference between the measured output and the zero-g offset then dividing by the sensitivity of the accelerometer (expressed in V/g or mV/g). The sensitivity of the ADXL355 accelerometer, the one we are using today is 300mV/g or 0.300V/g.
So acceleration can be calculated using the following two formulas:
voltage = (reading from pin)*3300 / 1024aaccelration = (voltage - 1650V) / (300V/g)
Motion Sensor (Accelerometer)Lets start on the code. We will start by writing the code to read the values for each axis, just like we did in the last sketch:
Motion Sensor (Accelerometer)Now it we need to introduce a couple of things in order to detect acceleration. We will use the formulas we identified earlier.
First up lets declare a couple of variables and define the Pins we will attach our LEDs to for each axis:
Motion Sensor (Accelerometer)Now for the code that puts the formulas into play. We will start with the x axis:
The first two lines print our the analog reading of the x axis.
The third line is our formula for calculating voltage from the analog reading of the x axis. The forth and fifth lines tells the computer to print out this information for us to see.
The sixth line is our formula for calculating acceleration from the voltage reading we just calculated. The seventh and eighth line tell the computer to print out this information for us to see.
Motion Sensor (Accelerometer)Now we can write this code again to calculate the acceleration on the y and z axes.
Motion Sensor (Accelerometer)Now that we can see the acceleration values or g force of each axis, we can write some if statements to get the LEDs to light up as the sensor detects movement on each of the axes. Here are the if, else if and else statements I wrote for the x and y axes:
Motion Sensor (Accelerometer)The statements I wrote for the z axis is slightly different. The g force of the z axis is different due to gravity.
Useful LinksHardware
LittleBird Electronics - littlebirdelectronics.com.au
Jaycar - jaycar.com.au
Sparkfun - sparkfun.com (america)
Inspiration
Fashioning Technology - fashioningtech.com
Diana Eng - fashionnerd.com
Talk2MyShirt - talktomyshirt.com
Useful LinksInnovative Artists to WatchHussein Chalayan - www.husseinchalayan.com
Electricfoxy - www.electricfoxy.com
Moon Berlin - www.moon-berlin.com
Other Fun...Materials
Pressure Sensors & Flex sensors
Speakers
Switches
Wireless Communication - Live data feeds
Workshop
Making Things Sense Workshop - 7th & 8th May
What Next...Making Things Sense Workshop - 7th & 8th May