I am trying to upload a code for a useless box into my Arduino Uno....help!

The instructions say to download Arduino to your desktop then just upload it! It is not working. I keep getting errors. Are there instructions (step by step) on how to upload code to my Uno?

Here is a link to the code:

Thank you for your help
Bill

What errors? People don't just know what your problem is. When you hit that upload button, the various bits of the system spit out error messages. You are supposed to read them and attempt to understand them, not just throw your hands in the air and be like "She no work!". Maybe this sketch of yours is completely bogus. Maybe it uses libraries you haven't installed. Maybe it's fine, but you are pasting the whole web page with line numbers into your IDE (use"raw" on github. better still - learn to use git). Maybe you haven't selected the serial port and board type. Maybe you haven't plugged your arduino in, and expect the bytes to get transferred over by magic.

Please read the sticky posts on this forum. For a start, no-one is going to navigate over to that site and bother to read the code.

Well - except me. …

Yikes. I'd prefer a data-driven approach, but that's just me. At least the code is simple. Do you understand that you need to build a box pretty much exactly the same as the box that this code is meant to run on?

Anyway - there's no reason I can see why this wouldn't compile. In fact ... I just changed this sketch so that the button was INPUT_PULLUP and the if() condition was LOW rather than HIGH (because I don't have a suitably positioned toggle switch), connected a little X-Y servo setup that I have to pins 9 and 10, and the sketch seems to work beautifully. no problems there. When I touch pin2 to ground, the x/y setup does a sequence of amusing little moves.

  • plug your arduino into your computer with a USB cable

  • Select the correct board from the Tools>Board menu

  • Select the port Tools>Port menu

  • If you don't see one that says (Arduino/Genuino) or something like that, try plugging into a different USB port

  • hit the upload button

If is still won't upload, come back here and copy-paste the output from the errors widow into your message so we can baybe have a bash at what's going on. Better still - take it to "Installation and Troubleshooting".

@PMC

You walked all the way over there to look at that code and didn't bring us back a copy? :confused:

PaulMurrayCbr:
Please read the sticky posts on this forum. For a start, no-one is going to navigate over to that site and bother to read the code.

Well - except me. …

I looked at it too! LOL! :slight_smile:

Compiles fine for me. Are you sure you selected the RAW text before doing a copy and paste?

The RAW version is here:
https://raw.githubusercontent.com/vagelis-chantzis/UselessBox/master/UselessBox.ino

#include <Servo.h>

Servo doorServo;
Servo fingerServo;

int swPin = 2;               //switch on pin 2

int pos = 0;
int selectedMove = 0;             //move selector

void setup()
{
  pinMode(swPin, INPUT);
  doorServo.attach(9);           //set door servo on Pin 9 pwm
  fingerServo.attach(10);          //set finger servo on Pin 10 pwm
  doorServo.write(80);           //set door to hiding position
  fingerServo.write(0);            //set finger to hiding position
}


void loop() {

  //if the switch is on, move door and finger to switch it off
  if (digitalRead(swPin) == HIGH)
  {

    if (selectedMove > 9) {
      selectedMove = 0;
    } //when all moves are played, repeat the moves from beginning

    if (selectedMove == 0) {
      simpleClose();
    }
    else if (selectedMove == 1) {
      simpleClose();
    }
    else if (selectedMove == 2) {
      simpleClose2();
    }
    else if (selectedMove == 3) {
      crazydoor();
    }
    else if (selectedMove == 4) {
      slow();
    }
    else if (selectedMove == 5) {
      serious();
    }
    else if (selectedMove == 6) {
      trollClose();
    }
    else if (selectedMove == 7) {
      simpleClose();
    }
    else if (selectedMove == 8) {
      matrix();
    }
    else if (selectedMove == 9) {
      sneak();
    }

    selectedMove += 1;         //swith to next move

  }
}



// Moves

// basic move
void simpleClose()
{
  //Moving door
  for (pos = 80; pos < 155; pos += 3)
  {
    doorServo.write(pos);
    delay(15);
  }

  //Moving hand
  for (pos = 0; pos < 129; pos += 4)
  {
    fingerServo.write(pos);
    delay(15);
  }

  //hiding hand
  for (pos = 129; pos >= 0; pos -= 4)
  {
    fingerServo.write(pos);
    delay(15);
  }

  //hiding door
  for (pos = 155; pos >= 80; pos -= 3)
  {
    doorServo.write(pos);
    delay(15);
  }
}

// open and wait, then move finger and wait, then switch of and hide
void simpleClose2()
{
  //Moving door
  for (pos = 80; pos < 155; pos += 3)
  {
    doorServo.write(pos);
    delay(15);
  }
  delay(800);
  //Moving hand
  for (pos = 0; pos < 100; pos += 4)
  {
    fingerServo.write(pos);
    delay(15);
  }
  delay(1000);
  for (pos = 100; pos < 129; pos += 4)
  {
    fingerServo.write(pos);
    delay(15);
  }

  //hiding hand
  for (pos = 129; pos >= 0; pos -= 5)
  {
    fingerServo.write(pos);
    delay(15);
  }

  //hiding door
  for (pos = 155; pos >= 80; pos -= 3)
  {
    doorServo.write(pos);
    delay(15);


  }

}

//open door then close it many times, wait, then quickly reopen, switch off and hide.

void crazydoor()
{

  //Moving door
  for (pos = 80; pos < 125; pos += 3)
  {
    doorServo.write(pos);
    delay(15);
  }

  //hiding door
  for (pos = 125; pos >= 80; pos -= 5)
  {
    doorServo.write(pos);
    delay(15);
  }
  //Moving door
  for (pos = 80; pos < 110; pos += 3)
  {
    doorServo.write(pos);
    delay(15);
  }

  //hiding door
  for (pos = 110; pos >= 80; pos -= 15)
  {
    doorServo.write(pos);
    delay(15);
  }
  delay(700);
  //Moving door
  for (pos = 80; pos < 125; pos += 3)
  {
    doorServo.write(pos);
    delay(15);
  }
  delay(700);
  //hiding door
  for (pos = 125; pos >= 80; pos -= 5)
  {
    doorServo.write(pos);
    delay(15);
  }

  //Moving door
  for (pos = 80; pos < 155; pos += 8)
  {
    doorServo.write(pos);
    delay(15);
  }

  //Moving hand
  for (pos = 0; pos < 129; pos += 3)
  {
    fingerServo.write(pos);
    delay(15);
  }

  //hiding hand
  for (pos = 129; pos >= 0; pos -= 3)
  {
    fingerServo.write(pos);
    delay(15);
  }

  //hiding door
  for (pos = 155; pos >= 80; pos -= 15)
  {
    doorServo.write(pos);
    delay(15);
  }

}


//open door,move finger very slowly forward and back to hiding very slowly, then quickly close door
void slow()
{

  //Moving door
  for (pos = 80; pos < 155; pos += 1)
  {
    doorServo.write(pos);
    delay(30);
  }

  //Moving hand
  for (pos = 0; pos < 129; pos += 1)
  {
    fingerServo.write(pos);
    delay(30);
  }

  //hiding hand
  for (pos = 129; pos >= 0; pos -= 1)
  {
    fingerServo.write(pos);
    delay(30);
  }

  //hiding door
  for (pos = 155; pos >= 125; pos -= 1)
  {
    doorServo.write(pos);
    delay(30);
  }
  delay(100);
  for (pos = 125; pos >= 80; pos -= 4)
  {
    doorServo.write(pos);
    delay(15);
  }


}

//serious

void serious() {

  //Moving door
  for (pos = 80; pos < 155; pos += 3)
  {
    doorServo.write(pos);
    delay(15);
  }

  //Moving hand
  for (pos = 0; pos < 70; pos += 1)
  {
    fingerServo.write(pos);
    delay(15);
  }
  delay(800);


  //hiding door
  for (pos = 155; pos >= 130; pos -= 3)
  {
    doorServo.write(pos);
    delay(15);
  }

  //hiding door
  for (pos = 130; pos < 155; pos += 3)
  {
    doorServo.write(pos);
    delay(15);
  }
  //hiding door
  for (pos = 155; pos >= 130; pos -= 3)
  {
    doorServo.write(pos);
    delay(15);
  }
  //hiding door
  for (pos = 130; pos < 155; pos += 3)
  {
    doorServo.write(pos);
    delay(15);
  }

  fingerServo.write(40);
  delay(1000);

  //Moving hand
  for (pos = 40; pos < 129; pos += 4)
  {
    fingerServo.write(pos);
    delay(15);
  }

  //hiding hand
  for (pos = 129; pos >= 0; pos -= 4)
  {
    fingerServo.write(pos);
    delay(15);
  }


  for (pos = 120; pos >= 80; pos -= 1)
  {
    doorServo.write(pos);
    delay(15);
  }



}

void trollClose() {
  //Moving door
  for (pos = 80; pos < 155; pos += 3)
  {
    doorServo.write(pos);
    delay(15);
  }

  //Moving hand
  for (pos = 0; pos < 127; pos += 4)
  {
    fingerServo.write(pos);
    delay(15);
  }
  //hiding door
  for (pos = 155; pos >= 130; pos -= 3)
  {
    doorServo.write(pos);
    delay(15);
  }
  delay(2000);

  for (pos = 130; pos < 155; pos += 3)
  {
    doorServo.write(pos);
    delay(15);
  }

  for (pos = 155; pos >= 140; pos -= 3)
  {
    doorServo.write(pos);
    delay(15);
  }
  for (pos = 140; pos < 155; pos += 3)
  {
    doorServo.write(pos);
    delay(15);
  }
  delay(500);
  //hiding hand
  for (pos = 127; pos >= 0; pos -= 4)
  {
    fingerServo.write(pos);
    delay(15);
  }

  //hiding door
  for (pos = 155; pos >= 80; pos -= 3)
  {
    doorServo.write(pos);
    delay(15);
  }

}

void matrix()
{

  //Moving door
  for (pos = 80; pos < 155; pos += 3)
  {
    doorServo.write(pos);
    delay(15);
  }

  //Moving hand
  for (pos = 0; pos < 80; pos += 4)
  {
    fingerServo.write(pos);
    delay(15);
  }

  for (pos = 80; pos < 129; pos += 1)
  {
    fingerServo.write(pos);
    delay(30);
  }
  delay(300);

  for (pos = 129; pos >= 0; pos -= 4)
  {
    fingerServo.write(pos);
    delay(10);
  }

  //hiding door
  for (pos = 155; pos >= 80; pos -= 3)
  {
    doorServo.write(pos);
    delay(15);
  }

}

void sneak()
{
  //Moving door
  for (pos = 80; pos < 130; pos += 1)
  {
    doorServo.write(pos);
    delay(30);
  }
  delay(2000);

  //Moving hand
  for (pos = 0; pos < 40; pos += 1)
  {
    fingerServo.write(pos);
    delay(30);
  }

  delay(500);

  for (pos = 130; pos < 155; pos += 4)
  {
    doorServo.write(pos);
    delay(15);
  }
  delay(100);

  for (pos = 40; pos < 90; pos += 4)
  {
    fingerServo.write(pos);
    delay(15);
  }
  delay(500);
  //hiding hand
  for (pos = 90; pos >= 70; pos -= 4)
  {
    fingerServo.write(pos);
    delay(15);
  }
  delay(100);
  for (pos = 70; pos < 90; pos += 4)
  {

    fingerServo.write(pos);
    delay(15);
  }
  delay(100);
  for (pos = 90; pos >= 70; pos -= 4)
  {
    fingerServo.write(pos);
    delay(15);
  }
  delay(100);

  for (pos = 70; pos < 129; pos += 4)
  {

    fingerServo.write(pos);
    delay(15);
  }

  for (pos = 129; pos >= 0; pos -= 4)
  {
    fingerServo.write(pos);
    delay(15);
  }
  //hiding door
  for (pos = 155; pos >= 80; pos -= 3)
  {
    doorServo.write(pos);
    delay(15);
  }
}