 Arduino GSR sensor

For my graduation project, the Happiness Cube, I wanted to add some biofeedback features. Answering questionnaires is a good indication for results but in order to create safer results I decided to measure arousal. Since GSR sensors are expensive, I decided to make one by myself based on an Arduino board. Here are the components that I used:

1 Arduino Diecimila
1 0.1uF capacitor
1 10K resistor
some aluminum foil
a few meters of wire
some Velcro tape (with one adhesive side)
Arduino IDE
Processing IDE

The GSR sensor is measuring arousal, which fluctuates according to how much you are sweating between the two points where the electrodes are placed. Two electrodes are strapped usually around two fingers, the middle finger and the index finger, but you can also place the electrodes in the thenar and hypothenar eminences of your palm (that is the lower left and right part of your palm). When I built the Arduino GSR, one of the wires was connected to the 5V of the board and the other to one of the analog 0/I and the to the GND. The concept of the GSR sensor is based on the fact that our body is used as a resistor. According to what you are measuring, the data that you get, show how easy (Skin Conductance) or how difficult (Skin Resistance) it is for the current to pass through your body. Of course it is understandable that since Conductance and Resistance are reciprocal, when the resistance data are transformed into conductance data and then visualized the two graphs for resistance and conductance will show opposite trends. As resistance increased, conductance decreases and vice versa.

The equation for resistance is:

R= V/I

and since resistance is opposite to conductance then:

G= 1/R

These two equations might be handy if you want to transform resistance to conductance and vice versa.

And some science that I learned afterwards…. According to Boucsain (Book: Electrodermal Activity), 0.5Volts is enough for measuring electrodermal activity.

In order to make the electrodes, I stripped the wire, put it on the sticky side of the Velkro tape and on top I put some aluminum foil. The picture that follows gives some extra information.

The original picture with dimensions given in inches can be found here .
After the electrodes were made, they need to be connected to the Arduino. I believe that this picture explains better, which goes where.

It is essential to use a capacitor and a resistor, otherwise you will be getting a lot of noise. Later I understood that this is a capacitive hardware based low pass filter. I might be wrong though. You can read more about low pass filtering here.

As for the code… The idea was to capture raw GSR data every second, the data would be sent to Processing and saved in a .txt file. Then it would have been easy to create the graphs in Excel.
Here is the code that you have to write in Arduino. The code sends one reading/second over the serial port. For more accurate data you can count how many readings can the arduino send over the serial port per second and then apply a Low Pass Filtering which is basically averaging the readings you get per second. So for example if the arduino sends 10 readings per second a Low Pass filtering would be LPF= reading1+ reading 2…. reading10/ 10. By applying a Low Pass Filter you can smooth your data and reduce the noise.

// GSR sensor variables
int sensorPin = 0; // select the input pin for the GSR
int sensorValue; // variable to store the value coming from the sensor

// Time variables
unsigned long time;
int secForGSR;
int curMillisForGSR;
int preMillisForGSR;

void setup() {
// Prepare serial port
Serial.begin(9600);
secForGSR = 1; // How often do we get a GSR reading
curMillisForGSR = 0;
preMillisForGSR = -1;
}
void loop() {
time = millis();

curMillisForGSR = time / (secForGSR * 1000);
if(curMillisForGSR != preMillisForGSR) {
// Read GSR sensor and send over Serial port
Serial.print(sensorValue, BYTE);
preMillisForGSR = curMillisForGSR;
}
}

And here is the code you have to write in Processing:

// Communicating with Arduino
// Creating a txt file

import processing.serial.*;

Serial serialPort;
int counter;
String[] data;

void setup() {
//println(Serial.list()); // To see the ports
serialPort = new Serial(this, Serial.list(), 9600);
counter = 0;
data = new String;
}

void draw() {

// If there is some input print it
if(temp != -1) {
println(counter + ” ” + temp);
data

0Happy Users
= counter + “,” + temp;
counter++;
}

// if we reached 20min save text and exit
if(counter == 1300) {
saveStrings(“thesis_data.txt”, data);
exit();
}
}

After the .txt file was created, I entered the data in OpenOffice calc and I generated the graphs. Here is one example. X axis represents time (in secs.) and Y axis raw GSR data.

Good luck playing with the Arduino and Processing!

Epilogue

If you found what you read helpful or inspiring, the least you can do out of academic or research courtesy is to refer to my website or my name when using the code or information from here. Intellectual Property licences can also create problems to opensource and the project is all opensource so I would prefer not to get one.

I would like to thank my friend Dunya Kirkali for helping me with the code.

EXTRAS
Recently I found this example for adding a low pass filtering in Processing. I haven’t tried it. But if you are interested, you can give it a go. You can find the example here.
If you want to create the graphs in real time, Che-Wei Wang has created a sketch in Processing, that you can find here.

Categories: Projects