Sign Language Glove

Hi everyone,

I’m writing a code for translating sign language in a glove and for some reason, it can’t compile the code for me. I keep getting the error message ‘Unable to compile code to Arduino board.’ I will attach the code below, and please give me suggestions on how to fix it.

Thank you

Science_Fair_Official.ino (1.58 KB)

There is much more to the error message then that. You need to scroll up the black console window at the bottom of the Arduino IDE window and read the specific error message, which will tell you what is wrong.

Please do this:

  • When you encounter an error, you’ll see a button on the right side of the orange bar “Copy error messages” in the Arduino IDE (or the icon that looks like two pieces of paper at the top right corner of the black console window in the Arduino Web Editor). Click that button…
  • In a forum reply here, click on the reply field.
  • Click the </> button on the forum toolbar. This will add the forum’s code tags markup to your reply.
  • Press “Ctrl + V”. This will paste the error between the code tags.
  • Move the cursor outside of the code tags before you add any additional text to your reply.

If the text exceeds the forum’s 9000 character limit, save it to a .txt file and post it as an attachment. If you click the “Reply” button here, you will see an “Attachments and other settings” link.

(deleted)

You have an extra set of global variables that you don’t use and you have some extra semicolons in some bizarre places. Here is a cleaned-up version of your sketch:

const int flexpin1 = A0;
const int flexpin2 = A1;
const int flexpin3 = A2;
const int flexpin4 = A3;
const int flexpin5 = A4;


//Thumb 905 750
const int threshold1 = 750;
const int threshold2 = 905;


//Pointer 955 825
const int threshold3 = 825;
const int threshold4 = 955;


//Middle
const int threshold5 = 825;
const int threshold6 = 955;


//Ring
const int threshold7 = 825;
const int threshold8 = 955;


//Pinky
const int threshold9 = 825;
const int threshold10 = 955;


void setup()
{
  // put your setup code here, to run once:
  Serial.begin(9600);
}


void loop()
{
  // put your main code here, to run repeatedly:
  int analogValue1 = analogRead(flexpin1);
  int analogValue2 = analogRead(flexpin2);
  int analogValue3 = analogRead(flexpin3);
  int analogValue4 = analogRead(flexpin4);
  int analogValue5 = analogRead(flexpin5);


  if (threshold1 <= analogValue1 && analogValue1 <= threshold2
      && threshold3 <= analogValue2 && analogValue2 <= threshold4
      && threshold5 <= analogValue3 && analogValue3 <= threshold6
      && threshold7 <= analogValue4 && analogValue4 <= threshold8
      && threshold9 <= analogValue5 && analogValue5 <= threshold10)
  {
    Serial.println('A');
  }
  else
  {
    Serial.println("Incorrect Hand Sign, Please Try Again :)");
  }


  delay(1000); //1000 millisecond delay
}

"'Unable to compile code to Arduino board.'"

Have you gone to Tools and scrolled down to see if you have the proper board selected?

I’m guessing you are going to want to recognize other finger positions. Now would be a good time to learn about arrays. For example, rather than writing a set of ten constants and a set of ten conditional phrases for each possible hand position you can put all the data in arrays:

const byte SensePins[] = {A0, A1, A2, A3, A4};
const int DigitCount = sizeof SensePins / sizeof SensePins[0];


const int Positions[][DigitCount][2] =
{
  {{750, 905}, {825, 955}, {825, 955}, {825, 955}, {825, 955}}, // A
  {{825, 955}, {825, 955}, {750, 905}, {825, 955}, {825, 955}}, // B
};
const int PositionCount = sizeof Positions / sizeof Positions[0];


const char PositionNames[PositionCount+1] = "AB";


void setup() 
{
  // put your setup code here, to run once:
  Serial.begin(9600);
}


void loop()
// put your main code here, to run repeatedly:
{
  int readings[DigitCount];


  for (int digit = 0; digit < DigitCount; digit++)
    readings[digit] = analogRead(SensePins[digit]);


  boolean match = false;


  // Check each hand position
  for (int p = 0; p < PositionCount; p++)
  {
    match = true;
    // check each digit for a position match
    for (int digit = 0; digit < DigitCount; digit++)
    {
      if (readings[digit] < Positions[p][digit][0] || readings[digit] > Positions[p][digit][1])
      {
        match = false;
        break; // Exit the 'digit' loop
      }
    }


    // If all digit positions match...
    if (match)
    {
      Serial.println(PositionNames[p]);
      break;  // Exit the 'p' loop
    }
  }


  if (!match)
  {
    Serial.println("Incorrect Hand Sign, Please Try Again :)");
    for (int digit = 0; digit < DigitCount; digit++)
    {
      Serial.print(readings[digit]);  // Show the current position.
      Serial.print(", ");
    }
    Serial.println();
  }


  delay(1000); //1000 millisecond delay
}
1 Like