Help with sampling using analog port (noise from finger)

...

Just plug a patch wire into the analogue pin and grab the other (bare) end with your fingers.
Don't try soldering it to your finger as it will hurt a lot and not work :smiley:

http://playground.arduino.cc/Code/PwmFrequency

sandersen_sleg:
4) Repeat measurement with input from static voltage from analog output (PWM)

Maybe there is something I do not understand? How do i go about doing this?

Make one of the pin output PWM and connect analog port to that pin.

Riva:
Don't try soldering it to your finger as it will hurt a lot and not work :smiley:

Good practical advice there. Do you work for the Health and Safety Executive? :slight_smile:

sandersen_sleg:

  1. pick up: 500 sample readings from an analog port (noise from finger) as an array.
  2. plot the data as simple ascii grafics
  3. Test and measure the max possible sample frequenzy.
  4. Repeat measurement with input from static voltage from analog output (PWM)
  5. change the samplefrequenzy so the PWM square is visible

Here are my suggestions and recommendations… not in any particular order… and I’m writing this assuming you know how to do beginner level C programming:

  • Use an Arduino MEGA2560 board. It has 8K (8192 bytes) of static ram (which is used for variable storage and C++ internals). To support assignment #1, you need to record 500 16 bit readings. That’s 1000 bytes, plus other variables in your code and you may exceed 2048 bytes (2K) which is what the smaller Arduino UNO has. In other words, using an Arduino UNO, you MAY run really close to your SRAM size limit. Using a MEGA 2560 removes that worry.

  • To input random electrical noise from your finger, you can simply stick a short piece of wire or a resistor into an analog input pin and then touch it. You will get rail to rail noise… lots of it (and mostly 60 cycle powerline noise and it’s harmonics at 120 and 180 hz). To avoid static zapping the input, FIRST touch a ground point on the board with your finger (the square metal USB jack is ideal), then take your finger off and touch the analog input, then record your data.

  • To record your analog data (assignment #1), you need to declare a 500 element int and a counter variable:

int array [500];
int x;
unsigned long int time;

Setup a “for loop” and record your samples, You may also wish to use another variable and the “millis()” function to record how long it takes to record 500 samples. In other words, you would do this:

time = millis(); // record start time
for x = 0 to x < 500 {
    store analog reading to array [x]
}
time = millis() - time; // time now equals how many milliseconds it took. derive the sample rate from this info

To extract the data for graphing:

char buffer [32];
for x = 0 to x < 500 {
    sprintf (buffer, "%d, %d\n", x, array[x]);
    Serial.print (buffer); // prints comma delimited X and Y axis (sample and analog value) data to serial port
}

Capture this data to a text file using your terminal program, or let it print to the Arduino serial monitor and copy/paste it into Excel or whatever you use to graph stuff.

Assignment #3 is completed because you know how long 500 samples take… figure out the rest.

#4 is merely a matter of connecting a PWM output pin to an analog input pin and setting an analog output (PWM) value. Note that this is NOT DC, but a variable pulse width 0/5 volt square wave.

#5 - the only way to change your sample rate is to make it slower by adding a delay between each sample in the loop. Note that doing an analog read via high level commands (i.e. “analogRead()”) is a LOT slower than machine level register access.

Search the web for sample machine level analog sampling (hint: the Sparkfun digital voltmeter kit code has a snippet you can use: http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Kits/Multimeter%20Kit%20v18.zip ). Use the parts that setup the registers, then the part that begins the analog conversion and returns the reading.

If your sample rate is too low (I assume you know what a Nyquist limit is?), the data will contain bogus information (called “aliasing”) which is the same effect as a car tire seeming to rotate backwards when illuminated by 60 hz pulsating street lamps.

You will need to know the Arduino PWM frequency (look it up, or measure it with an oscilloscope), then compare that to your sample rate. It the sample rate is 2X the PWM frequency or less, you’re going to get Nyquist aliasing. In fact, to get “decent” data, you need to sample 5 to 10 times as fast as the highest frequency. Your report should say this, as well as whether or not it’s POSSIBLE to do it the way an Arduino is setup.

Hope some of this helps.