GSR, standing for galvanic skin response, is a method of measuring the electrical conductance of the skin. Strong emotion can cause stimulus to your sympathetic nervous system, resulting more sweat being secreted by the sweat glands. Grove – GSR allows you to spot such strong emotions by simple attaching two electrodes to two fingers on one hand, an interesting gear to create emotion related projects, like sleep quality monitor.

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 AnalogIn gsr(A0);
00004 DigitalOut buzzer(D5);
00005 
00006 float gsrValue = 0;
00007 float baseline = 0;
00008 int on = 1, off = 0;
00009 
00010 // calculate baseline to compare against
00011 void Get_Baseline(void)
00012 {
00013     double sum = 0;
00014     buzzer = off;
00015     wait(1);
00016     for(int i=0; i<500; i++) {
00017         gsrValue = gsr;
00018         sum += gsrValue;
00019         wait(0.005);
00020     }
00021     baseline = sum/500;
00022     printf("baseline = %f\n\r", baseline);
00023 }
00024 
00025 // main loop, compare against baseline
00026 // sound buzzer if a >5% change happens
00027 int main()
00028 {
00029     float delta;
00030     Get_Baseline();
00031     while(1) {
00032         gsrValue = gsr;
00033         printf("gsrValue = %f\n\r",gsrValue);
00034         delta = baseline - gsrValue;
00035         if(abs(delta) > 0.05) { // check for > 5% change
00036             gsrValue = gsr;
00037             delta = baseline - gsrValue;
00038             if(abs(delta) > 0.05) { // double check
00039                 buzzer = on;
00040                 printf("YES!\n\r");
00041                 wait(3);
00042                 buzzer = off;
00043                 wait(1);
00044             }
00045         }
00046     }
00047 }