I can't manage to upload my code to my Ardino Uno!

I have a finished code ready to be used on my Arduino Uno beginners set but when I try to upload it the system always comes up with: Error: Request upload failed with message: 2 UNKNOWN: exit status 1. Someone, please explain to me how I fix this. I also already have a selected board and port and I am using MacBook.

Please post the full error message.
Note that the IDE has a control that allows you to copy the error message(s)

Which exact kit is this? Is it a genuine UNO?

Does your sketch verify, but not upload?

What version of OS x are you using, and which version if the Arduino IDE?

a7

Compilation error: Error: 2 UNKNOWN: exit status 1
that is the full error and i am using the newest Arduino IDE version
I am using the Arduino starter kit

Hi @leo_777 In order to gather more information that might help us to troubleshoot your problem, I'm going to ask you to post the full output from the upload when in verbose mode.

Please do this:

  1. Select File > Preferences from the Arduino IDE's menus.
  2. Uncheck the checkbox next to Show verbose output during: compilation
  3. Check the checkbox next to Show verbose output during: upload.
  4. Click the OK button.
  5. Attempt an upload, as you did before.
  6. After the upload fails, right click on the black "Output" pane at the bottom of the Arduino IDE 2.x window.
  7. From the context menu, click Copy All. This copies the full output to the clipboard.
  8. Open a forum reply here by clicking the Reply button.
  9. Click the </> icon on the post composer toolbar. This will add the forum's code block markup (```) to your reply to make sure the error messages are correctly formatted.
    Code block
  10. Press Ctrl+V. This will paste the error output from the upload into the code block.
  11. Move the cursor outside of the code tags before you add any additional text to your reply.
  12. Click the Reply button to post the output.
void setup() {
  pinMode(3,OUTPUT);
  pinMode(4,OUTPUT);
  pinMode(5,OUTPUT);
  pinMode(2,INPUT);
}
void loop(){}
switchState = digitalRead(2);

if (switchState == LOW) {}
//the button is not pressed
digitalWrite(3, HIGH); //Green LED
digitalWrite(4, LOW); //red LED)
digitalWrite(5, LOW); //red LED)
}
else { //the button is pressed
digitalWrite(3, LOW); 
digitalWrite(4, LOW); 
digitalWrite(5, HIGH); 
delay(250); // Wait a quater second
// toggle the LEDS
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
delay(250); // wait for a quarter second
}
} // go back to begging of loop



Using board 'uno' from platform in folder: /Users/leoabbott/Library/Arduino15/packages/arduino/hardware/avr/1.8.2
Using core 'arduino' from platform in folder: /Users/leoabbott/Library/Arduino15/packages/arduino/hardware/avr/1.8.2
Detecting libraries used...
/Users/leoabbott/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino5/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -I/Users/leoabbott/Library/Arduino15/packages/arduino/hardware/avr/1.8.2/cores/arduino -I/Users/leoabbott/Library/Arduino15/packages/arduino/hardware/avr/1.8.2/variants/standard "/var/folders/3m/jy3txs2x47d13z6gxb0csmp80000gn/T/arduino-sketch-F5A2B25491F2D77D966C7AF222F9620E/sketch/Spaceship sketch.ino.cpp" -o /dev/null
Generating function prototypes...
/Users/leoabbott/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino5/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -I/Users/leoabbott/Library/Arduino15/packages/arduino/hardware/avr/1.8.2/cores/arduino -I/Users/leoabbott/Library/Arduino15/packages/arduino/hardware/avr/1.8.2/variants/standard "/var/folders/3m/jy3txs2x47d13z6gxb0csmp80000gn/T/arduino-sketch-F5A2B25491F2D77D966C7AF222F9620E/sketch/Spaceship sketch.ino.cpp" -o /var/folders/3m/jy3txs2x47d13z6gxb0csmp80000gn/T/arduino-sketch-F5A2B25491F2D77D966C7AF222F9620E/preproc/ctags_target_for_gcc_minus_e.cpp
/Users/leoabbott/Library/Arduino15/packages/builtin/tools/ctags/5.8-arduino11/ctags -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives /var/folders/3m/jy3txs2x47d13z6gxb0csmp80000gn/T/arduino-sketch-F5A2B25491F2D77D966C7AF222F9620E/preproc/ctags_target_for_gcc_minus_e.cpp
Compiling sketch...
/Users/leoabbott/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino5/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -I/Users/leoabbott/Library/Arduino15/packages/arduino/hardware/avr/1.8.2/cores/arduino -I/Users/leoabbott/Library/Arduino15/packages/arduino/hardware/avr/1.8.2/variants/standard "/var/folders/3m/jy3txs2x47d13z6gxb0csmp80000gn/T/arduino-sketch-F5A2B25491F2D77D966C7AF222F9620E/sketch/Spaceship sketch.ino.cpp" -o "/var/folders/3m/jy3txs2x47d13z6gxb0csmp80000gn/T/arduino-sketch-F5A2B25491F2D77D966C7AF222F9620E/sketch/Spaceship sketch.ino.cpp.o"
/Users/leoabbott/Documents/Arduino/Spaceship sketch/Spaceship sketch.ino:9:1: error: 'switchState' does not name a type
 switchState = digitalRead(2);
 ^~~~~~~~~~~
/Users/leoabbott/Documents/Arduino/Spaceship sketch/Spaceship sketch.ino:11:1: error: expected unqualified-id before 'if'
 if (switchState == LOW) {}
 ^~
/Users/leoabbott/Documents/Arduino/Spaceship sketch/Spaceship sketch.ino:13:13: error: expected constructor, destructor, or type conversion before '(' token
 digitalWrite(3, HIGH); //Green LED
             ^
/Users/leoabbott/Documents/Arduino/Spaceship sketch/Spaceship sketch.ino:14:13: error: expected constructor, destructor, or type conversion before '(' token
 digitalWrite(4, LOW); //red LED)
             ^
/Users/leoabbott/Documents/Arduino/Spaceship sketch/Spaceship sketch.ino:15:13: error: expected constructor, destructor, or type conversion before '(' token
 digitalWrite(5, LOW); //red LED)
             ^
/Users/leoabbott/Documents/Arduino/Spaceship sketch/Spaceship sketch.ino:16:1: error: expected declaration before '}' token
 }
 ^
Compilation error: Error: 2 UNKNOWN: exit status 1
```
type or paste code here
```
```

I couldnt understand or find the black output button so i just copied it manually. But i did all the other stuff you said and it came up with the same thing

Are you still there I have done what you said

This error is not related to uploading. Your sketch code is not valid so it failed to compile (the sketch must be compiled before uploading). You can learn how to correctly write Arduino sketches by studying the Arduino Language Reference here:
https://www.arduino.cc/reference/en/

and the tutorials here:

The clue is here:

Try removing the two closing curly-bracket in these two statements -

void loop(){}


if (switchState == LOW) {}

I didn't try fixing and re-compiling, but the 1st one indicates the end of your main loop (which means you have a do-nothing main loop) and the 2nd one ends the if-statement, which again means "do nothing" if the switch state is low. If the code was able to compile you'd be stuck forever in your do-nothing loop and it would never see that if-statement.

The compiler doesn't know what the "real error" is, but it knows your code doesn't make sense...

ohhhh so I did the code wrong?

I did that but now it came up with this: Error: Request upload failed with message: 2 UNKNOWN: uploading error: uploading error: exit status 1

It has a warning sign next to my port and board selection could that be it?

Now this time it really is an uploading error. This means the sketch was able to compile successfully. Congratulations!

The "resource busy" error you are getting now could have multiple causes:

  • The port you have selected is not the port of your Arduino Uno, but instead some other port on your computer.
  • The port is the Uno but some application has it open. Only one application at a time can have a port open, so if another one has it open then it will block the Arduino IDE from uploading. This could even happen if you have the Serial Monitor running in another Arduino IDE window.

Maybe, maybe not. The warning sign is telling you that the Arduino IDE could not identify that port as an Arduino Uno. This could have two possible causes:

  • You bought a cheap Uno derivative board that uses a general purpose USB chip (e.g., CH340)
  • The port you have selected is not the port of your Uno.

Try this:

void setup() // <= You had error here, you need to put code inside {}
{
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(2, INPUT);
}

void loop() // <= You had error here, you need to put code inside {}
{
  /**
   * You had error here, you did not define switchState type
   * In Arduino LOW is the same as 0 and HIGH as 1
   * variable of type int can hold numbers, 
   * unsigned means that there are no negative numbers.
   */

  unsigned int switchState = digitalRead(2);

  if (switchState == LOW)
  {
    //the button is not pressed
    digitalWrite(3, HIGH); //Green LED
    digitalWrite(4, LOW);  //red LED)
    digitalWrite(5, LOW);  //red LED)
  }
  else
  { //the button is pressed
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
    digitalWrite(5, HIGH);
    delay(250); // Wait a quater second
    // toggle the LEDS
    digitalWrite(4, HIGH);
    digitalWrite(5, LOW);
    delay(250); // wait for a quarter second
  }
} // go back to begging of loop

Please read comments I left you.
Better option would be to use bool which can store values of true and false. They also mean 0 and 1.

oh ok ty

Does this mean anything. It does this before showing up with error

Using board 'uno' from platform in folder: /Users/leoabbott/Library/Arduino15/packages/arduino/hardware/avr/1.8.2
Using core 'arduino' from platform in folder: /Users/leoabbott/Library/Arduino15/packages/arduino/hardware/avr/1.8.2
Detecting libraries used...
/Users/leoabbott/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino5/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -I/Users/leoabbott/Library/Arduino15/packages/arduino/hardware/avr/1.8.2/cores/arduino -I/Users/leoabbott/Library/Arduino15/packages/arduino/hardware/avr/1.8.2/variants/standard "/var/folders/3m/jy3txs2x47d13z6gxb0csmp80000gn/T/arduino-sketch-F5A2B25491F2D77D966C7AF222F9620E/sketch/Spaceship sketch.ino.cpp" -o /dev/null
Generating function prototypes...
/Users/leoabbott/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino5/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -I/Users/leoabbott/Library/Arduino15/packages/arduino/hardware/avr/1.8.2/cores/arduino -I/Users/leoabbott/Library/Arduino15/packages/arduino/hardware/avr/1.8.2/variants/standard "/var/folders/3m/jy3txs2x47d13z6gxb0csmp80000gn/T/arduino-sketch-F5A2B25491F2D77D966C7AF222F9620E/sketch/Spaceship sketch.ino.cpp" -o /var/folders/3m/jy3txs2x47d13z6gxb0csmp80000gn/T/arduino-sketch-F5A2B25491F2D77D966C7AF222F9620E/preproc/ctags_target_for_gcc_minus_e.cpp
/Users/leoabbott/Library/Arduino15/packages/builtin/tools/ctags/5.8-arduino11/ctags -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives /var/folders/3m/jy3txs2x47d13z6gxb0csmp80000gn/T/arduino-sketch-F5A2B25491F2D77D966C7AF222F9620E/preproc/ctags_target_for_gcc_minus_e.cpp
Compiling sketch...
/Users/leoabbott/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino5/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -I/Users/leoabbott/Library/Arduino15/packages/arduino/hardware/avr/1.8.2/cores/arduino -I/Users/leoabbott/Library/Arduino15/packages/arduino/hardware/avr/1.8.2/variants/standard "/var/folders/3m/jy3txs2x47d13z6gxb0csmp80000gn/T/arduino-sketch-F5A2B25491F2D77D966C7AF222F9620E/sketch/Spaceship sketch.ino.cpp" -o "/var/folders/3m/jy3txs2x47d13z6gxb0csmp80000gn/T/arduino-sketch-F5A2B25491F2D77D966C7AF222F9620E/sketch/Spaceship sketch.ino.cpp.o"
Compiling libraries...
Compiling core...
Using precompiled core: /var/folders/3m/jy3txs2x47d13z6gxb0csmp80000gn/T/arduino-core-cache/core_arduino_avr_uno_73742450db2bc8ca13bf0182a0c05f46.a
Linking everything together...
/Users/leoabbott/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino5/bin/avr-gcc -w -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections -mmcu=atmega328p -o "/var/folders/3m/jy3txs2x47d13z6gxb0csmp80000gn/T/arduino-sketch-F5A2B25491F2D77D966C7AF222F9620E/Spaceship sketch.ino.elf" "/var/folders/3m/jy3txs2x47d13z6gxb0csmp80000gn/T/arduino-sketch-F5A2B25491F2D77D966C7AF222F9620E/sketch/Spaceship sketch.ino.cpp.o" /var/folders/3m/jy3txs2x47d13z6gxb0csmp80000gn/T/arduino-sketch-F5A2B25491F2D77D966C7AF222F9620E/../arduino-core-cache/core_arduino_avr_uno_73742450db2bc8ca13bf0182a0c05f46.a -L/var/folders/3m/jy3txs2x47d13z6gxb0csmp80000gn/T/arduino-sketch-F5A2B25491F2D77D966C7AF222F9620E -lm
/Users/leoabbott/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino5/bin/avr-objcopy -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 "/var/folders/3m/jy3txs2x47d13z6gxb0csmp80000gn/T/arduino-sketch-F5A2B25491F2D77D966C7AF222F9620E/Spaceship sketch.ino.elf" "/var/folders/3m/jy3txs2x47d13z6gxb0csmp80000gn/T/arduino-sketch-F5A2B25491F2D77D966C7AF222F9620E/Spaceship sketch.ino.eep"
/Users/leoabbott/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino5/bin/avr-objcopy -O ihex -R .eeprom "/var/folders/3m/jy3txs2x47d13z6gxb0csmp80000gn/T/arduino-sketch-F5A2B25491F2D77D966C7AF222F9620E/Spaceship sketch.ino.elf" "/var/folders/3m/jy3txs2x47d13z6gxb0csmp80000gn/T/arduino-sketch-F5A2B25491F2D77D966C7AF222F9620E/Spaceship sketch.ino.hex"
/Users/leoabbott/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino5/bin/avr-size -A "/var/folders/3m/jy3txs2x47d13z6gxb0csmp80000gn/T/arduino-sketch-F5A2B25491F2D77D966C7AF222F9620E/Spaceship sketch.ino.elf"
Sketch uses 1160 bytes (3%) of program storage space. Maximum is 32256 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.

--------------------------
Compilation complete.
"/Users/leoabbott/Library/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/bin/avrdude" "-C/Users/leoabbott/Library/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf" -v -V -patmega328p -carduino "-P/dev/cu.Bluetooth-Incoming-Port" -b115200 -D "-Uflash:w:/var/folders/3m/jy3txs2x47d13z6gxb0csmp80000gn/T/arduino-sketch-F5A2B25491F2D77D966C7AF222F9620E/Spaceship sketch.ino.hex:i"

avrdude: Version 6.3-20190619
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "/Users/leoabbott/Library/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf"
         User configuration file is "/Users/leoabbott/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/cu.Bluetooth-Incoming-Port
         Using Programmer              : arduino
         Overriding Baud Rate          : 115200
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x00

Please follow this procedure to verify whether the port you have selected is the Uno or not:

  1. Unplug your Arduino board from the computer.
  2. Select Tools > Port from the Arduino IDE's menus.
  3. Note the ports, if any, listed in the menu.
  4. Close the Tools menu. The ports list is only updated when the Tools menu is re-opened, so this step is essential.
  5. Plug your Arduino board into the computer.
  6. Select Tools > Port from the Arduino IDE's menus. - The new port listed in the menu is your Arduino board.

If you don't see a new port appear, then there is a problem either with the drivers, the USB cable, or the Uno itself.

1 Like

Is your arduino connected? Did you select it and the communication port?

yes it is