you could use a 9v power adapter that fits in the black socket and plug it in the wall I do it all the time and it works perfectly because when I download the program to the arduino it saves it to the flash which is non-volatile meaning that it will be saved on the chip even after a power off and also here is some code I wrote a while ago that uses one wire for a therium like thing just one note: I have looked at what happens to a wire when you move your hand closer to a long wire and it looks like a square and when you move your hand closer the peak gets taller however my code just gets the median of a sample because I wrote this code before doing that and forgot to rewrite it.Also as you can tell by the program I did NOT write the median algorithm and also this contains alot of commented code but lacks of actual comments so sorry about that.
//1 wire insterment
/*
* This Quickselect routine is based on the algorithm described in
* "Numerical recipes in C", Second Edition,
* Cambridge University Press, 1992, Section 8.5, ISBN 0-521-43108-5
* This code by Nicolas Devillard - 1998. Public domain.
*/
#define ELEM_SWAP(a,b) { register unsigned int t=(a);(a)=(b);(b)=t; }
unsigned int quick_select(unsigned int arr[], int n)
{
int low, high ;
int median;
int middle, ll, hh;
low = 0 ; high = n-1 ; median = (low + high) / 2;
for (;;) {
if (high <= low) /* One element only */
return arr[median] ;
if (high == low + 1) { /* Two elements only */
if (arr[low] > arr[high])
ELEM_SWAP(arr[low], arr[high]) ;
return arr[median] ;
}
/* Find median of low, middle and high items; swap into position low */
middle = (low + high) / 2;
if (arr[middle] > arr[high]) ELEM_SWAP(arr[middle], arr[high]) ;
if (arr[low] > arr[high]) ELEM_SWAP(arr[low], arr[high]) ;
if (arr[middle] > arr[low]) ELEM_SWAP(arr[middle], arr[low]) ;
/* Swap low item (now in position middle) into position (low+1) */
ELEM_SWAP(arr[middle], arr[low+1]) ;
/* Nibble from each end towards middle, swapping items when stuck */
ll = low + 1;
hh = high;
for (;;) {
do ll++; while (arr[low] > arr[ll]) ;
do hh--; while (arr[hh] > arr[low]) ;
if (hh < ll)
break;
ELEM_SWAP(arr[ll], arr[hh]) ;
}
/* Swap middle item (in position low) back into correct position */
ELEM_SWAP(arr[low], arr[hh]) ;
/* Re-set active partition */
if (hh <= median)
low = ll;
if (hh >= median)
high = hh - 1;
}
}
#undef ELEM_SWAP
#define speaker 3
#define wire 0
//#define outlier_low 250
//#define outlier_high 800
#define sample_size 32
unsigned int sample_data[sample_size];
unsigned int loop_avg;
unsigned int pitch_temp;
//#define uled
//uled=using led
#define led_green 8
#define led_red 7
void setup()
{
#ifdef uled
pinMode(led_green, OUTPUT);
pinMode(led_red, OUTPUT);
#endif
Serial.begin(9600);
}
void loop()
{
//get wire value
unsigned int pitch;
for (loop_avg=0;loop_avg <= sample_size ;loop_avg++)
{
#ifdef uled
digitalWrite(led_green, LOW); // sets the LED off
digitalWrite(led_red, LOW); // sets the LED off
#endif
re_read2:
pitch_temp=analogRead(wire);
#ifdef outlier_low
if (pitch_temp < outlier_low)
{
//Serial.println("pitch too low");
#ifdef uled
digitalWrite(led_green, HIGH); // sets the LED on
#endif
goto re_read2;
}
#endif
#ifdef outlier_high
if (pitch_temp > outlier_high)
{
// Serial.println("pitch too high");
#ifdef uled
digitalWrite(led_red, HIGH); // sets the LED on
#endif
goto re_read2;
}
#endif
// pitch=pitch_temp;
sample_data[loop_avg]=pitch_temp;
// pitch/=2;
}
//now sort array
pitch=quick_select(sample_data, sample_size);
tone(speaker,pitch);
}