Handshake

Description

We must have heard people defining various intensities of handshakes. Some say that a handshake was “mellow” and some say it was “warm”. Well, these terms sound pretty vague as they are subjective. It’s time to bring in a device that actually measures how strong was your handshake. I used a Force Sensitive Resistor on a glove to measure how hard the handshake was. The way people would be able to measure this “hardness” is by seeing the color change of the LED on the glove and the sound of the speaker. The harder the handshake, the higher the frequency. It was a difficult task to find out the exact spot on the hand that would measure the intensity appropriately. Light handshakes might not involve the touch of palms, so the FSR had to be placed somewhere, where there is a definite contact. I figured it out to be the tip of the index finger.

Components

  • 1 Arduino Uno R3
  • 1 Piezo Speaker
  • 1 Force Sensitive Resistor
  • 3 LEDs
  • 1 Glove (woolen)

Code

 

// The three primary colour LEDs, driven as analogue outputs (actually PWM, but
// close enough for our analogue eyes).

const int ledPinRed = 11; // Red LED connected to analogue out pin
const int ledPinGrn = 10; // Green LED connected to analogue out pin
const int ledPinBlu = 9; // Blue LED connected to analogue out pin
const int piezoPin = 7;

// The Brightness potentiometer goes on an analogue pin, taking the pin from
// 0V to 5V.

const int fsr = 1;

// Constants to define the ranges.

const int hueRedLow = 0;
const int hueRedHigh = 255;
const int hueBlue = 170;

// The size of the angle of one sector (1/6 of a colour wheel), and of a complete
// cycle of the colour wheel.

const int angleMin = 0;
const int angleSector = 60;
const int angleMax = 360;

const int brightMin = 0;
const int brightMax = 255;

//constants to define the range of beats
const int beatsMin = 40;
const int beatsMax = 220;

// Work variables.

// The hue potentiometer value is mapped to the range 0 to 360 (degrees).
int fsrValueHue;

//The brightness potentiometer value is mapped from 0 to 255 (full brightness)
int fsrValueSound;

int hue, brightness;

const int saturation = 255;

// The brightess of each LED (0 to 255).

unsigned int r, g, b;

void setup() {
// Still need to set a baud rate, even for USB.
Serial.begin(9600);

// Set LED pins to output.
pinMode(ledPinRed, OUTPUT);
pinMode(ledPinGrn, OUTPUT);
pinMode(ledPinBlu, OUTPUT);
pinMode(piezoPin , OUTPUT);

// Poteniometer analogue pin is an input.
pinMode(fsr, INPUT);
}

void loop() {

// fsr values are mapped to create a color based on the intensity of the handshake
fsrValueHue = map(analogRead(fsr), 0, 1023, angleMin, angleMax);
// fsr values are mapped to create sound of a particular frequency based on the intensity of the handshake. Lower the intensity, lower the frequency
fsrValueSound = map(analogRead(fsr), 0, 1023, 75, 10000);

// Colour wheel mode (red to red, wrapped around in a cycle).
hue = map(fsrValueHue, angleMin, angleMax, hueRedLow, hueRedHigh);

// Do the conversion.
HSBToRGB(hue, saturation, brightness, &r, &g, &b);

analogWrite(ledPinRed, r);
analogWrite(ledPinGrn, g);
analogWrite(ledPinBlu, b);
digitalWrite(piezoPin , fsrValueSound);
}

// This function taken from here:
// http://eduardofv.com/read_post/179-Arduino-RGB-LED-HSV-Color-Wheel-

void HSBToRGB(
unsigned int inHue, unsigned int inSaturation, unsigned int inBrightness,
unsigned int *oR, unsigned int *oG, unsigned int *oB )
{
if (inSaturation == 0)
{
// achromatic (grey)
*oR = *oG = *oB = inBrightness;
}
else
{
unsigned int scaledHue = (inHue * 6);
unsigned int sector = scaledHue >> 8; // sector 0 to 5 around the color wheel
unsigned int offsetInSector = scaledHue - (sector << 8); // position within the sector unsigned int p = (inBrightness * ( 255 - inSaturation )) >> 8;
unsigned int q = (inBrightness * ( 255 - ((inSaturation * offsetInSector) >> 8) )) >> 8;
unsigned int t = (inBrightness * ( 255 - ((inSaturation * ( 255 - offsetInSector )) >> 8) )) >> 8;

switch( sector ) {
case 0:
*oR = inBrightness;
*oG = t;
*oB = p;
break;
case 1:
*oR = q;
*oG = inBrightness;
*oB = p;
break;
case 2:
*oR = p;
*oG = inBrightness;
*oB = t;
break;
case 3:
*oR = p;
*oG = q;
*oB = inBrightness;
break;
case 4:
*oR = t;
*oG = p;
*oB = inBrightness;
break;
default: // case 5:
*oR = inBrightness;
*oG = p;
*oB = q;
break;
}
}
}
 

gloves