Can you recommend additional features or change the function?

I'm working on my project now.
it is a bending sensor and a manipulator with an Arduino attached to a hand protector was designed. For more precise control prior to design, approximate formulas were obtained by measuring the sensor values.
As a result, sensor value is only varied by the angle of the bending sensor. Bending sensors can be used to control the speed according to the bending angle of the user's fingers on the basis of theory, and the signal is transmitted to the motor by a Bluetooth sensor. The mechanism of the manipulator was designed to stop when the fingers were extended and to accelerate as the fingers were bent.
All the system is considered for the situation of spreading fingers for safety when the user falls down on the ground. And it is designed that do not accelerate or decelerate rapidly even if the user suddenly stretches or grasps hands.

I need to make an additional feature on it or I want to use 'map function' to control it in more detail.

Can you please help me?

slave.ino (953 Bytes)

The code that you posted does not appear to be the complete program

What features do you want to add and where do you see the map() function being useful ?

You could map() the values of flex to a much smaller range of values starting at zero and use an array to hold the corresponding position values. That would provide finer control using less code.

Some form of failsafe would also be useful in case extreme values are received or no value is received with a time period

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html . Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom.. :slight_smile:

UKHeliBob:
The code that you posted does not appear to be the complete program

What features do you want to add and where do you see the map() function being useful ?

You could map() the values of flex to a much smaller range of values starting at zero and use an array to hold the corresponding position values. That would provide finer control using less code.

Some form of failsafe would also be useful in case extreme values are received or no value is received with a time period

Hi, I wanna change this code to using map() function.
Could you please help me?
I just made a code map() "pos=map(flex,800,900,90,190)" and I'll try it tomorrow.
I don't know it is perfect code or not, I have no idea now.
Teach me please if you have another good idea instead of code I made.

Servo bldc ; 
int get_F_sen;
int pos=0;

void setup()
{
  Serial.begin(9600);
  BT.begin(9600);
  bldc.attach(9);
}

String str = "";
int flex = "";

void loop()
{
  if(BT.available())
  {
    char data = (char)BT.read();

    if(data != '/')
    {
      str += data;
    }
    else if(data == '/')
    {
      BT.read();
      flex = str.toInt();
      str = "";
    }
  Serial.println(flex);
  bldc.write(pos);
  }

 if(flex>=810&&flex<825)
  {
    pos = 110;
  }
    else if(flex>=825&&flex<840)
  {
    pos = 130;
  }
  else if(flex>=840&&flex<860)
  {
    pos = 150;
  }
  else if(flex>=860&&flex<880)
  {
    pos = 170;
  }
  else if(flex>=880)
  {
    pos = 190;
  }
  else
  {
    pos=90;
  }

Teach me please if you have another good idea instead of code I made.

What are the highest and lowest input values from the sensor ?
What are the highest and lowest output values that you require and in how many steps ?

UKHeliBob:
What are the highest and lowest input values from the sensor ?
What are the highest and lowest output values that you require and in how many steps ?

I divided a code 'pos value' as a value of a flex sensor.
As you see a code, The BLDC motor operates at a flex value of approximately 790-800, and the maximum speed of the motor, pos = 190, is when it has obtained the flex sensor value of about 900.
I want to try to make the speed of it from 0 to maximum.
you told me, map() function would provide finer control using less code.
That is what I want.

As an example, let's assume that the motor runs when the pos value is between 100 and 200 and that the corresponding flex values are between 800 and 900

Using the map() function you could do something like thispos = map(flexValue, 800, 900, 100, 200);so for of an input range of 800 to 900 we get an output range of 100 to 200. I was thinking earlier about using an array to hold the output values indexed using the input value but this is not needed.

When using the map() function care is needed to ensure that the input values are in the mapped range before using map() but that is easily done by testing the input and either ignoring it or setting the output to a sensible safe value

Hi,
The map function does not constrain its values, it will work for values outside your input parameters.

You may need to use this as well;

Tom... :slight_smile: