Aluminum foil Capacitive Touch Pumpkin Candy Bucket – lights up

advertisement

Capacitive Touch Pumpkin Candy Bucket – lights up when you reach in!

10Ω

22pF

+5V

16MHz

22pF

+5V

100pF

10MΩ

Aluminum foil

Bill Of Materials

vendor per capacitive proximity sensing pumpkin bucket: solderless bread board mouser red leds mouser

5V regulator mouser

0.1uF caps mouser

1uF caps mouser

22pF ceramic caps mouser

16MHz resonating crystal mouser arduino uno bootloaded ATmega325 mouser

100pF ceramic cap mouser

9V battery clip mouser

9V battery mouser pumpkin bucket dollar store part#

383-Q50

604-WP710A10SRD/F

512-LM7805CT

140-REA0R1M2ABK0511P

140-XRL160V1.0-RC

140-50N2-220J-RC

815-ABL-16-B2

782-A000048

581-SA102A101JAR

12BC311-GR

658-6LR61XWA/C

CODE

/*capacitive sense using aluminum foil

*code referenced from http://forum.arduino.cc/index.php/topic,8609.0.html

* set up: pin 8 > high resitor > one wire to foil, one to pin 9

*Led set up pin 5 > led >grnd

* ajust if statment to fit resistor, currently using a 10Mohm

*/ int highcap = 2150; // cap reading when almost touching int i; int ledPin = 5; unsigned int x, y; float accum, fout, fval = .07; // these are variables for a simple low-pass (smoothing) filter - fval of 1 = no filter - .001 = max filter byte brighntess; void setup() {

pinMode(ledPin, OUTPUT);

Serial.begin(9600);

DDRB=B101; // DDR is the pin direction register - governs inputs and outputs- 1's are outputs

// Arduino pin 8 output, pin 9 input

// preceding line is equivalent to three lines below

// pinMode(8, OUTPUT); // output pin

// pinMode(9, INPUT); // input pin

// pinMode(10, OUTPUT); // guard pin

digitalWrite(10, LOW); //could also be HIGH - don't use this pin for changing output thoug

} void loop() {

y = 0; // clear out variables

x = 0;

for (i=0; i < 4 ; i++ ){ // do it four times to build up an average - not really neccessary but takes out some jitter

// LOW-to-HIGH transition

PORTB = PORTB | 1; // Same as line below - shows programmer chops but doesn't really buy any more speed

// digitalWrite(8, HIGH);

// output pin is PortB0 (Arduino , sensor pin is PortB1 (Arduinio 9)

while ((PINB & B10) != B10 ) { // while the sense pin is not high

// while (digitalRead(9) != 1) // same as above port manipulation above - only 20 times slower!

x++;

}

delay(1);

// HIGH-to-LOW transition

PORTB = PORTB & 0xFE; // Same as line below - these shows programmer chops but doesn't really buy any more speed

//digitalWrite(8, LOW);

while((PINB & B10) != 0 ){ // while pin is not low -- same as below only 20 times faster

// while(digitalRead(9) != 0 ) // same as above port manipulation - only 20 times slower!

y++;

}

delay(1);

}

fout = (fval * (float)x) + ((1-fval) * accum); // Easy smoothing filter "fval" determines amount of new data in fout

accum = fout;

Serial.println( (long)fout, DEC); // Smoothed Low to High

if( ( (int)fout) > highcap)

{

digitalWrite(ledPin, 255);

}

else

{

digitalWrite(ledPin, 0);

}

} delay(10);

Download