IoT-project: Minimalistic GSR monitor

By: Mikko Maja, Reija Pekkinen, Laura-Maaria Penttilä

The project

In a team of 3, we took part to a 5-day IoT workshop hosted by Tero Karvinen at Haaga-Helia University where we were to create an IoT device prototype of our liking. None of us had previous experience of building embedded systems and very little experience with electrical components so there was much to learn.

Our initial goal was to make a wristband that monitors the user’s heart rate, and reacts to abnormalities such as a panic attack or a heart attack. If the user’s heart rate is higher than normal, the wristband would blink a blue LED and start uploading data to the Botbook API. If the user’s heart rate got alarmingly high, the wristband would start vibrating and flash a red LED.

original plan

Our original planning for the heart rate monitor.

However, the only “pulse sensor” that was available was the KY-039 heartbeat module which had to be connected to the user’s finger where it measures the light going through the finger using a LED and a phototransistor. We ran multiple tests with the module, but we weren’t able to get any understandable readings so the next day we decided to change our plan to make something else with the knowledge we had already gathered.

We had created a functioning alerting system, so we wanted to use it in our new plan. Laura-Maaria came up with a minimalistic GSR monitor that’s based only on jumper cables and tin foil, so we decided to give it a shot.

Heart rate belts disassembled

In search of a working heart rate sensor we disassembled a couple of heart rate belts.

The parts

1x Arduino Uno

1x Breadboard

2x LEDs, one blue, one red

1x Vibrating motor

1x 10kΩ resistor

2x 10Ω resistor

10x jumper cable

Tin foil

Velcro bands

The assembly

The GSR sensors were made from two jumper cables. We removed some plastic from the ends and covered them with tin foil. The other ends of the wires were connected to the 5V and to one of the analog 0/I and 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, shows how easy (conductance) or how difficult (resistance) it is for the current to pass through your body.

Testing the sensors

Testing the sensors

The LEDs and the vibrating motor were connected to the breadboard from the Arduino boards digital pins.

Full assembly

Full assembly

The code

We got most of the code for the GSR reading from ftmedia.eu. We added the code for the alerting sequences and Tero helped us with some errors. The alerting works with a simple logic: if the users GSR is more than 0 (the sensor is not idle), the blue led will light up. If the GSR rises to over 140, the red led starts blinking. If the GSR rises to over 160, the red led flashes more frequently and the vibrating motor vibrates in sync with the led. The GSR readings are also sent to the Botbook API for monitoring.

// GSR sensor variables
int sensorPin = 0; // select the input pin for the GSR
int sensorValue; // variable to store the value coming from the sensor
int ledPinBlue = 7; // input pin for the BLUE LED
int ledPinRed = 8; // input pin for the RED LED
int vibrPin = 9; // input pin for the VIBRATING MOTOR

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

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

  curMillisForGSR = time / (secForGSR * 1000);
  if (curMillisForGSR != preMillisForGSR) {
    // Read GSR sensor and send over Serial port
    sensorValue = analogRead(sensorPin);
    //Serial.write( byte(sensorValue));
    Serial.print("GET http://one.api.botbook.com/add/C1lH4lyZfl9/?x=");
    Serial.println(sensorValue);
    delay(1000);
    preMillisForGSR = curMillisForGSR;
    // if the sensors are not idle, light up the BLUE LED
    if (sensorValue > 0) {
      digitalWrite(ledPinBlue, HIGH);
    } else {
      digitalWrite(ledPinBlue, LOW);
      }
    // if the GSR reading is over 140, flash the RED LED twice
    if (sensorValue > 140) {
      digitalWrite(ledPinBlue, LOW);
      digitalWrite(ledPinRed, HIGH);
      delay(500);
      digitalWrite(ledPinRed, LOW);
      delay(500);
      digitalWrite(ledPinRed, HIGH);
    } else {      
      digitalWrite(ledPinRed, LOW);
    }
    // if the GSR reading is over 160, keep the RED LED on and vibrate the motor three times
    if (sensorValue > 160) {
      digitalWrite(ledPinBlue, LOW);
      digitalWrite(ledPinRed, HIGH);
      digitalWrite(vibrPin, HIGH);
      delay(300);
      digitalWrite(vibrPin, LOW);
      delay(300);
      digitalWrite(vibrPin, HIGH);
      delay(300);
      digitalWrite(vibrPin, LOW);
      delay(300);
      digitalWrite(vibrPin, HIGH);
      delay(300);
      digitalWrite(vibrPin, LOW);
      delay(300);
    } else {      
      digitalWrite(ledPinRed, LOW);
    }
  }
}

The monitoring

The GSR readings are sent to the Botbook API where the user can see a line graph of the 50 latest readings. The readings are updated via a Python script in real time.

Credits & References

http://iot.botbook.com/

http://terokarvinen.com/

Haaga-Helia University IoT-työpaja

http://ftmedia.eu/diy-gsr-sensor/

http://www.instructables.com/id/Making-Galvanic-Skin-Response-Finger-Electrodes/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s