Strange voltage readings using my potato

I am using an arduino uno with a wireless sd shield to measure galvanic skin response.
The setup uses two tens machine style electrodes, and measures the voltage coming into an analog input. The whole thing is portable and powered by a 9v duracel battery.
It is designed to take a voltage reading every 2 seconds, and print that to a micro sd card, so that it can take continuous readings over many hours.

I finally got the whole thing working and measured the voltage with the two electrodes placed about 2 inches apart on my chest over several hours. The graph of the readings shows a steady increase in the readings from about 40 to about 160 over about one and a half hours then a flatter range of between around 140 to around 180 over the next two hours. Basically a linear increase for two hours followed by sideways movement for two hours. I suspected this might be due to sweat build up under the electrodes slowly increasing conductivity, until they became saturated after 2 hours. (Attached image 1).

I decided to test the setup on a potato for several hours. If the graph shape was solely due to sweat, then since potatoes don't sweat the graph shape should be basically flat. Unfortunately the potato gave an even more extreme graph. It first shows a very rapid increase in measurement from about 270 to 350 over 15 minutes, followed by a more gentle linear increase from around 350 to around 410 over the next 2-3 hours. (Attached image 2).

The potato readings are clearly not due to sweat. This was done on a wooden table with no other interference. Inside a dry room in a warm house.
The wires used to take readings are fully insulated so that no bare copper is exposed.

The smaller fluctuations between readings are to be expected, but the general graph shape seems to suggest an underlying problem with the sensor setup.
Does anyone have any idea what might be causing these readings? Could it be something to do with the ground?
(I have no experience with electronics before this project!)

(The setup has:
9v battery going into the power jack, with proper 9v connector soldered to jack having positive on the inside.
3.3v going to first electrode via resistor.
Second electrode going back to arduino with the wire split so that one end goes into an analog input and the other end goes to a ground pin via a resistor.
An RTC with its own battery powered from the 5v output, with a ground wire going into another spare ground on the arduino, and info wires going into two more analog pins.
The arduino is fully sealed inside a plastic tub. Only the battery and electrodes are outside the tub.
I am using foam to cushion the arduino inside the tub, and the foam is touching many parts of the electronics, but I don't think it is conductive.)

The potato is acting like a battery. What material are the electrodes?

2 diff metals in a sour is in essence a battery.

Does the potato get a colour around (one of) the electrodes (blue/brown?)

Now that you mention it, I remember something about potatoes being used as batteries ... I was just looking for something which would be slightly conductive without shorting the circuit.

There does not appear to be much colouration on the potato. There is a very, very slight brown hue under the electrode which goes to the ground. I did notice that the arduino light was not on when I came back to it. I assumed the battery had gone flat. I haven't actually tried turning the arduino back on again yet. I do hope I haven't bricked my arduino ... with a potato.

Could there be a problem a floating ground? I thought perhaps excess charge might be building up over time, or something, which is causing the gradually higher readings. I have tried to look up about floating grounds and whether it might be a problem for arduinos in general or my setup in particular, but I have not been able to find enough information on it to diagnose whether it is even relevant in this situation.

I assumed the battery had gone flat.

You could have tried a potato :wink:

Could there be a problem a floating ground?

I expect that chemical reactions took place forming substances that increased the conductivity. If a cell of potato burst, the inner fluids come out.
There might even be a bit of heat build up, (causing your battery to drain faster?)

Redoing the experiment with more controlled conditions could shed some light on it.

Your body and the potato are effectively the electrolyte in a simple battery and the electrodes are becoming polarised over time since they are monitoring using a DC circuit. You can prevent such polaristation by periodically reversing the polarity of the electrodes by either an h-bridge type device or a DPDT relay.

prevent such polarisation by periodically reversing the polarity of the electrodes by either an h-bridge type device or a DPDT relay

Awesome. I have never heard of these things before, but they sound cool enough to fix it. I'll look them up, thanks!

Thankfully my arduino still seems to work, and strangely the 9v battery also seems to be working again. I did notice that the RTC module went haywire in the last few minutes of the test as well, and started spewing out random times. It seems that strange things happen when potatoes get involved.

Thank you both very much for your help. I probably would never have found those answers on my own!

Try connecting the top end of the 3K3 resistor to an Arduino PWM pin instead of to +5V, and connect a 1uF ceramic capacitor in series with the electrode. Connect the analog input pin to the junction of the capacitor and the resistor. Set the PWM output to 50%. Take analog readings both when the PWM output is high and when it is low (you can read the state of the PWM pin using digitalRead), and take the difference between the two readings. This way, you will be feeding AC to the electrodes, avoiding electrolysis.

To make a "battery" you would need two different metals for the electrodes.

I am a bit unclear what you are actually trying to do ?

When you put the electrodes on your chest, were you trying to measure a voltage generated
by your chest ? Or were you applying a voltage from the arduino to your chest and trying
to measure the conductivity or resistance of your chest ?

Try connecting the top end of the 3K3 resistor to an Arduino PWM pin instead of to +5V, and connect a 1uF ceramic capacitor in series with the electrode. Connect the analog input pin to the junction of the capacitor and the resistor. Set the PWM output to 50%. Take analog readings both when the PWM output is high and when it is low (you can read the state of the PWM pin using digitalRead), and take the difference between the two readings. This way, you will be feeding AC to the electrodes, avoiding electrolysis.

Thank you. I shall try this. It might take me a while to sort it out, and I will need to buy the ceramic resistor, but I am keen to try it.

When you put the electrodes on your chest, were you trying to measure a voltage generated
by your chest ? Or were you applying a voltage from the arduino to your chest and trying
to measure the conductivity or resistance of your chest ?

I am applying 5v from the arduino (itself powered from a 9v battery) across my chest (or any other body part) to measure conductivity/resistance. I think galvanic skin response refers to the minute changes in sweat secretions from sweat glands which cause changes in skin surface conductivity. It is basically a lie detector test, although I am not interested in it for that purpose. I am trying to get a general measure of the physical stress someone is under, over an extended period of time. I'm not interested in the minute fluctuations that would be used for a lie detector test. I am only interested in the larger changes over hours or days. That is why the graph shapes I have so far created are causing a problem.

Am I correct in thinking that using the usb connector to power the arduino, rather than the 9v battery, would produce an AC current across the skin? Or does the arduino somehow only provide DC current out of the 3.3v or 5v pins? If the usb connector is AC then I could at least use that to test the effectiveness, even if I will have to implement one of the proper solutions offered above for the portable battery operated operation.

I originally thought this was a problem with the arduino setup I had, but now that it has been pointed out to me that it is a polarization problem it is clear that this is a problem with gsr sensing in general.

This issue already seems to have been partly covered by an earlier post, for any who are interested:

I remember something about potatoes being used as batteries

There are examples of using potato / tomato / apple / etc. to power your mcu.

kayle:
1)
Thank you. I shall try this. It might take me a while to sort it out, and I will need to buy the ceramic resistor, but I am keen to try it.

You can try using an electrolytic capacitor instead of a ceramic capacitor, even a higher value such as 10uF or 100uF, and that should help a lot. However, the leakage current of an electrolytic capacitor will still result in a small amount of direct current, so you will still get some (very slow) electrolysis.

kayle:
3)
Am I correct in thinking that using the usb connector to power the arduino, rather than the 9v battery, would produce an AC current across the skin? Or does the arduino somehow only provide DC current out of the 3.3v or 5v pins? If the usb connector is AC then I could at least use that to test the effectiveness, even if I will have to implement one of the proper solutions offered above for the portable battery operated operation.

Two points:

  1. Powering the Arduino from the USB connector will make no difference, either way your present arrangement will feed DC to the electrodes, causing electrolysis.

  2. Connecting yourself to something that is connected to mains ground (such as an Arduino powered from the USB port) is a bad idea, because if you touch anything live, your body will provide a direct path to ground. Medical devices having patient electrodes are always battery powered, or else the electrodes are isolated from ground (the standard calls for several thousand volts of isolation, I forget the exact figure).

Connecting yourself to something that is connected to mains ground (such as an Arduino powered from the USB port) is a bad idea

Good point. Thanks. I was focused so much on the problem itself, that I forgot I would be connecting myself up to the mains. :astonished:

Try connecting the top end of the 3K3 resistor to an Arduino PWM pin instead of to +5V, and connect a 1uF ceramic capacitor in series with the electrode. Connect the analog input pin to the junction of the capacitor and the resistor. Set the PWM output to 50%. Take analog readings both when the PWM output is high and when it is low (you can read the state of the PWM pin using digitalRead), and take the difference between the two readings. This way, you will be feeding AC to the electrodes, avoiding electrolysis.

Thanks for describing this. I have tried to draw a circuit diagram of what I understand this description to mean. I have attached the circuit diagram as a jpeg below.
Have I drawn this circuit correctly?

I'm not really sure what the capacitor is doing. Is this really feeding AC to the electrodes, or just pulsing the current on and off without reversing it?

circuit diagram.jpg

Yes, that's correct. The capacitor will feed AC to the electrodes when you generate a square wave at the PWM pin.

OK. I set the circuit up as shown in the circuit diagram I posted in my last posting (February 03, 2013, 05:05:04 PM). The only difference is that I am using a 10uF electrolytic capacitor instead of a 1uF ceramic capacitor.

However, there now seems to be a problem reading the analog input when the PWM pin is on the LOW part of its cycle. I'm not sure if this is a hardware problem, or a code problem. I'll happily move this question to the code section if this is the wrong place for it - but I am guessing it is best to ask it here first, on the thread it is most associated with.

I am setting the PWM pin to < 0.5 V (because apparently skin resistance only behaves linearly below 0.5V). So the PWM is set to 20. (I have tried it at higher values as well).
I am trying to take a reading from the analog input (A0) when the PWM pin is HIGH and then again when it is LOW.
If the reading from the analog pin when the PWM pin is HIGH and when it is LOW together count as one "set" of readings, then I am trying to take a set of readings about each second or so.
To do this there is a "main" cycle which runs every second or so, and prints the results to serial at the end of each cycle.
Within this "main" cycle there are two separate (not nested within each other) mini cycles.
The first mini cycle checks to see when the PWM pin is set to HIGH, and then records the reading from the analog input at that point to an integer variable for use later.
The second mini cycle does the same for when the PWM pin is set to LOW, recording the analog input at that point to a different integer variable.

The problem is that the PWM pin never seems to be set to LOW. The cycle that checks for when the PWM pin is set to HIGH works fine, but the cycle that checks for when the PWM pin is set to LOW never completes - presumably because it is never seeing the PWM pin as LOW via digitalRead().

Also, the analog reading (taken when the PWM pin is HIGH) is always around 1020. This seems WAY too high - especially when the PWM pin is only set to 20 and there is a 3.3K resistor.

I have gone through the info on PWM, digitalRead() and analogWrite() many times, and I still have no idea why this is happening. The summary of the code I am using is:

int PWMPin = 11;
int PWMValue = 20;
int sensor_high;
int sensor_low;
int high_reading_taken;
int low_reading_taken;
int read_attempt;
int read_attempts_max = 10;

void setup{
pinMode(PWMPin, OUTPUT); 
}

void loop{

// "main" cycle
while ( x,y,z .... )
       {

        sensor_high = -1;
        sensor_low = -1;
              
        // first mini cycle, checks for when PWM pin is set to HIGH
        high_reading_taken = 0;
        read_attempt = 1;
        while ( (high_reading_taken == 0) && (read_attempt <= read_attempts_max) )
              {
              if ( digitalRead(PWMPin) == HIGH ) { sensor_high = analogRead(0); high_reading_taken = 1; }
              read_attempt++;
              }
              
        delay(100);     // delay here to allow analog pin to recover, as suggest in the documentation.
              
        // second mini cycle, checks for when PWM pin is set to LOW
        low_reading_taken = 0;
        read_attempt = 1;
        while ( (low_reading_taken == 0)  && (read_attempt <= read_attempts_max)  )
              {
              if ( digitalRead(PWMPin) == LOW ) { sensor_low =  analogRead(0); low_reading_taken = 1; }
              read_attempt++;
              } 
        
        // followed by code to print the results to serial and/or SD card.

        delay(1000); // main cycle runs roughly once per second
        }

}

The use of "attempts" to limit the cycles is only there to stop it from going into an infinite loop. I've tried it without that limit, and the problem is still there.
(I have not posted my full code because that would take me over the word limit, but I could post it if anyone would like).
I've tried using integer values of 1 or 0 respectively for the conditionals which check whether digitalRead() is HIGH or LOW.
I have also tried using different PWM pins ( such as 9 and 3). I'm using an arduino uno. Can't use pin 10 because that is reserved for SD functions. (5 and 6 apparently experience interference, so I am avoiding them).

When this code runs, it prints the "sensor_high" value as 1020 or 1021, and the "sensor_low" value as -1.
Am I making a really obvious error? Is this even a code problem?

  1. Change the PWM to 128. The whole point of the arrangement with the capacitor is to feed balanced AC to the skin electrodes, which you are not doing. If you want to restrict the voltage to 0.5V then either increase the 3.3K resistor to a higher value, or increase the 3.3K resistor to 15K and connect 3.3K from the resistor-capacitor junction to ground (this will give you a maximum of +/- 0.5V peak at the electrodes).

  2. Get rid of that delay(100) call, it isn't necessary and it's screwing up the timimg.

Thanks again!

I understand now about the PWM being set to half. I didn't twig that it needs to be that way in order to balance the voltage in both directions.
I have used the voltage divider method you described to get the voltage down, and now the analog input pin reads about 180 - which equates to about 0.88V I think.
(The resistors I am using are cheap though, and I measured the 15k resistor to be more like 14.5k, so I guess that is to be expected. I shall tweak them to get it to 0.5V).

I am still struggling to take analog readings when the PWM is outputting LOW. I shall ask that question in the programming forum http://arduino.cc/forum/index.php/topic,148353.0.html, because I'm pretty sure it is my coding error.