The finger sensor can be used for various functions. Grabbing an egg or a bottle needs different pressures. Shaking a human hand needs also to detect the pressure applied. There is many ways to do touch sensors, I have done two versions, both are extremely low cost. The version with the hall sensor is much more accurate then the original foam version.

 

Summary :

  • ELECTRONIC (2 versions)
  • SETUP
  • UTILISATION

ELECTRONIC  WITH HALL SENSOR


-This version is done with a hall sensor and a magnet.

-When the magnet comes closer to the hall sensor, the value is measured by the sensor.

-The value is sent  to the analog Arduino pin.

-The assembly of the sensor on the finger is explained in the hand tutorial.


ELECTRONIC WITH FOAM SENSOR


-The original version of finger sensor was done with 2 copper plates connected to a piece of antistatic foam.

-When the foam is compressed, the current flows stronger between the 2 copper plates.

-The analog Arduino pin detects the variation.

-The assembly of the sensor on the finger is explained in the hand tutorial.


SETUP


Open InMoov/config/service_J_SensorFinger.config and setup like below.

[MAIN]

rightHandSensorActivated=True
rightHandSensorArduino=right

right_thumb_Psi_min=544Put here the max value when the sensor is NOT pressed
right_thumb_Psi_low=545In average cases take the min value and add +1 if using a AH3503 Hall Sensor
right_thumb_Psi_mid=547In average cases take the min value and add +4
right_thumb_Psi_max=550In average cases take the min value and add +7

right_index_Psi_min=538
right_index_Psi_low=539
right_index_Psi_mid=542
right_index_Psi_max=545

Add the values for each finger sensor…

To check if the finger sensors are worky and to see their values, you can type in the python window and execute:

sensorTimerStart()

And see the result in the python tab.

You can turn off the sensorTimer with:

sensorTimerStop()


UTILISATION


We have three options:

1-If you have set the sensor config file, some gestures will automatically use the sensors.

2-Test with a code directly on the Arduino.

3-Test with a python code in MyRobotLab.(if you are not running START_INMOOV)

First option:

The gesture shakehands() will automatically use the sensors when the hand closes itself.

You can adjust the desired pressure for a gesture between 0 to 3. When the sensor reach the desired pressure the finger servo stops its position and disables.

if rightHandSensorActivated:
    rightHandSensorON()
    sleep(1.5)
    rightThumbPressure=1 # Pressure range between 0-3
    rightIndexPressure=1
    rightMajeurePressure=1
    rightRingFingerPressure=1
    rightPinkyPressure=1
    i01.rightHand.moveTo(79,170,180,180,180,180)
    sleep(2)
    rightHandSensorOFF()
else:
  i01.rightHand.moveTo(79,90,140,130,122,180)

Second option:

-Upload this code to your Arduino board:

// A small script to test one servo and one sensor.

// Connect one sensor cable to the PIN A0, and the other cable
// to the 5V of your Arduino.
// The servo will be connected to your power supply (Gnd,Vcc)
// and to the PIN 2 of your Arduino.
// Set the serial of your Arduino at 57600 in device manager
// More detail on connection here https://inmoov.fr/test-your-finger-sensor
    
#include <Servo.h>

const int servoPin = 2;
const int sensorPin = A0;
int sensorReading;

int position;

Servo myservo;

void setup(){
  Serial.begin(57600);
  myservo.write(30);  // Closed claw.
  position = 30;
  myservo.attach(servoPin );
}

void loop(){
  sensorReading = analogRead(sensorPin);
    Serial.print("Analog reading = ");
    Serial.print(sensorReading); // the raw analog reading
    // We'll have a few threshholds, qualitatively determined
    if (sensorReading < 25) {
    Serial.println(" - No pressure");
    } else if (sensorReading < 30) {
    Serial.println(" - Light touch");
    } else if (sensorReading < 50) {
    Serial.println(" - Light squeeze");
    } else if (sensorReading < 110) {
    Serial.println(" - Medium squeeze");
    } else if (sensorReading < 200) {
    Serial.println(" - Big squeeze");
    }
    delay(1000);
  openClaw();
  delay(3000);
  closeClaw();
  delay(3000);
}

void openClaw() {
  for (; position < 130;  position++) {
    myservo.write(position);
    if(analogRead(sensorPin) > 30)
      break;
  }
}

void closeClaw() {
  myservo.write(30);  // Go to open position
  position = 30;
}

 

-Connect your sensor (illustrated by a FSR sensor) and your servo motor. Some servo draw too much Amp current to be directly powered by the Arduino. If your servo motor jitters or move erraticaly, plug an extra power source for your servo and make sure to ground the Arduino to that extra power source as shown below:

-When the power is applied, the finger will close slowly by itself, if the sensor detects a pressure it will display in the Arduino.exe monitor an information.

-You may need to change the values of the sensor in the code to reach a better adjustement.

For to do that, check  the results on the monitor and change these values directly in the code to your need:

(sensorReading < 25)
(sensorReading < 30)
(sensorReading < 50)
(sensorReading < 110)
(sensorReading < 200)

 

 

Third option:

Here we assume you already have installed MyRobotLab and know a little bit how to use it, if not go first to this page.

-Launch MyRobotLab by double clicking the “myrobotlab.jar” from your MRL directory.

-Make the same connections between your Arduino and servo motor as the image in the first option tutorial.

-Copy and paste this python script to the python tab in MyRobotLab.

#This simple sensor InMoov script is tested on MyRobotLab version 1.0.2693
#The result can be seen in the Oscope and with the finger action.
#Connect one sensor cable to the PIN A0, and the other cable to the 5V of your Arduino.
#Servo will be connected to pin 2 of the Arduino.
#Change the COM port in the code according to your Arduino board.

leftPort = "COM10"

Voice="US-English_Matthew"
mouth = Runtime.createAndStart("i01.mouth", "NaturalReaderSpeech")
#mouth.installComponentsAcceptLicense(Voice)
mouth.setVoice(Voice)
mouth.setRate(-10)

i01 = Runtime.createAndStart("i01", "InMoov")
i01.startMouth()
leftHand = Runtime.create("i01.leftHand","InMoovHand")
i01.startLeftHand(leftPort)
i01.leftHand.index.map(0,180,25,165)

left=Runtime.create("i01.left", "Arduino")
left.setBoard("atmega2560")
left = Runtime.start("i01.left", "Arduino")
left.connect("COM10")

 
def publishPin(pins): 
    for pin in range(0, len(pins)):
        print pins[pin].address, pins[pin].value
        if pins[pin].value<=540:
          print "No pressure"
        if pins[pin].value>=541 and pins[pin].value<=542:
          print "Low pressure"
        if pins[pin].value>=543 and pins[pin].value<=544:
          print "Soft pressure"
          FingerGoesBack()
        if pins[pin].value>=545:
          print "High pressure"
          FingerGoesBack()
          i01.mouth.speak(u"OUCH, that hurts") 
 
left.addListener("publishPinArray","python","publishPin")
sleep(5)
left.enablePin(54,1) # 54 is pin A0, Number 1 is how many polls/second

i01.leftHand.setAutoDisable(True)

def moveFingerSlowly():
    i01.leftHand.index.enable()
    i01.leftHand.index.setVelocity(25)
    sleep(2)
    i01.leftHand.index.moveTo(180)

def FingerGoesBack():
    i01.leftHand.index.enable()
    i01.leftHand.index.setVelocity(-1)
    i01.leftHand.index.moveTo(0)
#This simple sensor InMoov script is tested on MyRobotLab version 1.1.812
#The result can be seen in the Oscope and with the finger action.
#Connect one sensor cable to the PIN A0, and the other cable to the 5V of your Arduino.
#Servo will be connected to pin 2 of the Arduino.
#Change the COM port in the code according to your Arduino board.


Voice="Mark"
i01_mouth = Runtime.start("i01.mouth", "MarySpeech")
#i01_mouth.installComponentsAcceptLicense(Voice)
i01_mouth.setVoice(Voice)

i01_left=Runtime.create("i01.left", "Arduino")
i01_left.setBoard("atmega2560")
i01_left = Runtime.start("i01.left", "Arduino")
i01_left.connect("COM3")

i01 = Runtime.start("i01", "InMoov2")
i01.startMouth()
i01_leftHand = Runtime.start("i01.leftHand","InMoov2Hand")
i01_leftHand_index.map(0.0,180.0,0.0,180.0)
i01_left.attach("i01.leftHand")

 
def publishPin(pins): 
    for pin in range(0, len(pins)):
        print pins[pin].address, pins[pin].value
        if pins[pin].value<=540:
          print "No pressure"
        if pins[pin].value>=541 and pins[pin].value<=542:
          print "Low pressure"
        if pins[pin].value>=543 and pins[pin].value<=544:
          print "Soft pressure"
          FingerGoesBack()
        if pins[pin].value>=545:
          print "High pressure"
          FingerGoesBack()
          i01.mouth.speak(u"OUCH, that hurts") 
 
i01_left.addListener("publishPinArray","python","publishPin")
sleep(5)
i01_left.enablePin(54,1) # 54 is pin A0, Number 1 is how many polls/second

i01_leftHand.setAutoDisable(True)

def moveFingerSlowly():
    i01_leftHand_index.enable()
    i01_leftHand_index.setSpeed(25)
    sleep(2)
    i01_leftHand_index.moveTo(180)

def FingerGoesBack():
    i01_leftHand_index.enable()
    i01_leftHand_index.setSpeedy(250)
    i01_leftHand_index.moveTo(0)

 

-When the power is applied, the finger will close slowly by itself, if the sensor detects a pressure it will display in the python monitor an information and will stop to close and say something related to the pressure he felt.

-You may need to change the values of the sensor in the code to reach a better adjustement.

For to do that, check  the results on the monitor and change these values directly in the code to your need:

value<=540
value>=541
value<=542
value>=543
value<=544
value>=545