Monday, October 19, 2009

First Working Prototype

INPUT: Aluminum foil EM resistance sensor
PROCESSING: Change the speed of the blinking LED based on how much resistance (EM) is present
OUTPUT: Led which blinks quicker as you get closer.


Our board setup, with wires leading to the aluminum foil and the LED plugged straight into the digital output pins and ground.



Our 'sensor' - a big piece of aluminum foil with current across it. The aluminum foil is folded over twice so it's four layers thick, about 9"x6". The thickness and size of the metal (and even our wiring up to it!) significantly effect the range of values we observed. Our 'resistance' values range from 0-60 (arbitrary units). We get value 60 for touching or up to about 1" away from the metal, to 0 about 10-12" away. Shifting scales with this assembly will definitely be challenging, but this works for now!

The final prototype. You can see the distance range to change the (out of focus in the background) blink rate of the LED.



This shows the blinking LED better:




Our Arduino code is a simple modification of the CapSense library from the Arduino website:

#include

/*
* CapitiveSense Library Demo Sketch
* Paul Badger 2008
* Uses a high value resistor e.g. 10M between send pin and receive pin
* Resistor effects sensitivity, experiment with values, 50K - 50M. Larger resistor values yield larger sensor values.
* Receive pin is the sensor pin -
try different amounts of foil/metal on this pin
*/


CapSense cs_4_2 = CapSense(4,2); // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired

int ledPin = 13; // LED connected to digital pin 13
int blinkDelay = 0; // Counter to control blink

void setup()

{

cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF); // turn off autocalibrate on channel 1 - just as an example
Serial.begin(9600);

// initialize the digital pin as an output:
pinMode(ledPin, OUTPUT);

}

void loop()
{
long start = millis();
long total1 = cs_4_2.capSense(30);

Serial.print(millis() - start); // check on performance in milliseconds
Serial.print("\t"); // tab character for debug windown spacing

Serial.println(total1); // print sensor output 1

if(total1 >= 45) { // how long to blink based on resistance
blinkDelay = 250;
}
else if(total1 >= 15) {
blinkDelay = 500;
}
else {
blinkDelay = 1000;
}

digitalWrite(ledPin, HIGH); // blink on

delay(blinkDelay); // delay

digitalWrite(ledPin, LOW); // blink off

delay(blinkDelay); // delay
}


No comments:

Post a Comment