Arduino Nano - Upload Error

I am having trouble getting this code to upload to the Arduino Nano. I have many comments in my code including a header section which lists the hardware I am using. I have tried using ATmega328P (Old Bootloader), ATmega328P, and ATmega168. The attempt using ATmega328P did get stuck in uploading, whereas none of the other attempts produced this effect. Given my post was too long with the code and all three error messages, I have attached my code and only included the error message using ATmega328P.
Here is the error message with ATmega328P.

C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\Nicholus\Documents\Arduino\libraries -fqbn=arduino:avr:nano:cpu=atmega328 -vid-pid=0000_0000 -ide-version=10812 -build-path C:\Users\Nicholus\AppData\Local\Temp\arduino_build_818450 -warnings=none -build-cache C:\Users\Nicholus\AppData\Local\Temp\arduino_cache_149845 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino5.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA-1.3.0.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose C:\Users\Nicholus\Desktop\arduino sketches\Project Sketches\Proj01 - Under Bed Path Illumination\Proj01_REV00\Proj01_REV00.ino
C:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\Nicholus\Documents\Arduino\libraries -fqbn=arduino:avr:nano:cpu=atmega328 -vid-pid=0000_0000 -ide-version=10812 -build-path C:\Users\Nicholus\AppData\Local\Temp\arduino_build_818450 -warnings=none -build-cache C:\Users\Nicholus\AppData\Local\Temp\arduino_cache_149845 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino5.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA-1.3.0.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose C:\Users\Nicholus\Desktop\arduino sketches\Project Sketches\Proj01 - Under Bed Path Illumination\Proj01_REV00\Proj01_REV00.ino
Using board 'nano' from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr
Using core 'arduino' from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr
Detecting libraries used...
"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/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=10812 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\variants\\eightanaloginputs" "C:\\Users\\Nicholus\\AppData\\Local\\Temp\\arduino_build_818450\\sketch\\Proj01_REV00.ino.cpp" -o nul
Generating function prototypes...
"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/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=10812 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\variants\\eightanaloginputs" "C:\\Users\\Nicholus\\AppData\\Local\\Temp\\arduino_build_818450\\sketch\\Proj01_REV00.ino.cpp" -o "C:\\Users\\Nicholus\\AppData\\Local\\Temp\\arduino_build_818450\\preproc\\ctags_target_for_gcc_minus_e.cpp"
"C:\\Program Files (x86)\\Arduino\\tools-builder\\ctags\\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\\Users\\Nicholus\\AppData\\Local\\Temp\\arduino_build_818450\\preproc\\ctags_target_for_gcc_minus_e.cpp"
Compiling sketch...
"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/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=10812 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\variants\\eightanaloginputs" "C:\\Users\\Nicholus\\AppData\\Local\\Temp\\arduino_build_818450\\sketch\\Proj01_REV00.ino.cpp" -o "C:\\Users\\Nicholus\\AppData\\Local\\Temp\\arduino_build_818450\\sketch\\Proj01_REV00.ino.cpp.o"
Compiling libraries...
Compiling core...
Using precompiled core: C:\Users\Nicholus\AppData\Local\Temp\arduino_cache_149845\core\core_arduino_avr_nano_cpu_atmega328_0c812875ac70eb4a9b385d8fb077f54c.a
Linking everything together...
"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-gcc" -w -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections -mmcu=atmega328p -o "C:\\Users\\Nicholus\\AppData\\Local\\Temp\\arduino_build_818450/Proj01_REV00.ino.elf" "C:\\Users\\Nicholus\\AppData\\Local\\Temp\\arduino_build_818450\\sketch\\Proj01_REV00.ino.cpp.o" "C:\\Users\\Nicholus\\AppData\\Local\\Temp\\arduino_build_818450/..\\arduino_cache_149845\\core\\core_arduino_avr_nano_cpu_atmega328_0c812875ac70eb4a9b385d8fb077f54c.a" "-LC:\\Users\\Nicholus\\AppData\\Local\\Temp\\arduino_build_818450" -lm
"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-objcopy" -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 "C:\\Users\\Nicholus\\AppData\\Local\\Temp\\arduino_build_818450/Proj01_REV00.ino.elf" "C:\\Users\\Nicholus\\AppData\\Local\\Temp\\arduino_build_818450/Proj01_REV00.ino.eep"
"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-objcopy" -O ihex -R .eeprom "C:\\Users\\Nicholus\\AppData\\Local\\Temp\\arduino_build_818450/Proj01_REV00.ino.elf" "C:\\Users\\Nicholus\\AppData\\Local\\Temp\\arduino_build_818450/Proj01_REV00.ino.hex"
"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-size" -A "C:\\Users\\Nicholus\\AppData\\Local\\Temp\\arduino_build_818450/Proj01_REV00.ino.elf"
Sketch uses 1146 bytes (3%) of program storage space. Maximum is 30720 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.
C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude -CC:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf -v -patmega328p -carduino -PCOM4 -b115200 -D -Uflash:w:C:\Users\Nicholus\AppData\Local\Temp\arduino_build_818450/Proj01_REV00.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 "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"

         Using Port                    : COM4
         Using Programmer              : arduino
         Overriding Baud Rate          : 115200

Proj01_REV00.ino (1.55 KB)

Are you certain that's the full error message? Usually we expect there to be more from avrdude.

Hi,
Are you sure this is all your code?

/* This code is for Proj01 - Under Bed Path Illumination
   By: null_set


   It uses the following equipment:
   x1 REXQualis Nano V3.0
   x3 AM312 PIR Modules (all connected to common Digital I/O pin)
   x1 Photoresistor "LDR" (50 kΩ in darkness / 500 Ω in bright light)
   x1 1k Resistor
   x1 DZS 1 Channel 5V Relay (running 3 parallel 300 SMD 3528 LED Strips in Normally Open)


   The code will read the inputs from all 3 PIRs and the photoresistor.
   If the photoresistor is reading near its highest value and any of the PIRs
   are detecting signal, the relay will be switched to ON for 1 minute.
*/


int lightPin = 0; // Set photoresistor to analog pin A0
int pirPin = 2; // Set PIR common digital I/O pin to digital pin D2
int relayPin = 3; // Set relay IN pin to digital pin D3


void setup() {
  pinMode(pirPin, INPUT); // Set pirPin to input mode
  pinMode(relayPin, OUTPUT); // Set relayPin to output mode
  delay(60000); // Delay for 1 minute while system initiallizes
}


void loop() {
  int lightreading = analogRead(lightPin); // Obtain reading from LDR (LDR = 50kΩ - 48.39Ω * lightreading)
  int lightsetpoint = 1012; // Set point for intiallizing read of pirPin (LDR = 1,029 Ω)


  if ( lightreading > lightsetpoint) {
    int pirreading = digitalRead(pirPin); // Check PIR reading state
    while ( pirreading == HIGH ) {
      digitalWrite(relayPin, HIGH); // Turn lights on if PIRs detect signal
      delay(60000); // Wait 1 minute
      int pirreading = digitalRead(pirPin); // Check for PIR reading state change
    }
  }
}

It compiled and uploaded to a Nano for me, no problems.

Can I also suggest;

int lightPin = 0; // Set photoresistor to analog pin A0

to

int lightPin = A0; // Set photoresistor to analog pin A0

Thanks.. Tom.. :slight_smile:
Win10, IDE 1.8.13

Tom,
Thanks for the reply. That is all of my code. I do not understand why it would upload for you and not me. I will try a different board and report the results.
In the meantime, I appreciate your coding suggestion but could you explain why you advise defining the analog input pin as A0? This microcontroller programming is new to me. So, I would like to understand your thought process. There are example codes that came with my starter kit which define it as I have. But, it would be good to hear your experience on this distinction.
Thanks again for your assistance.

UPDATE: I grabbed a new Arduino Nano and changed USB ports just in case there was an issue with the one I was using previously. The behavior changed and now I am getting the following error message using ATmega328P (Old Bootloader). I only grabbed the post-compiling portion of the error message as it exceeded 9000 characters with all of it and it compiles without issue.

C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude -CC:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf -v -patmega328p -carduino -PCOM10 -b57600 -D -Uflash:w:C:\Users\Nicholus\AppData\Local\Temp\arduino_build_712598/Proj01_REV00.ino.hex:i 
Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

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 "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"

         Using Port                    : COM10
         Using Programmer              : arduino
         Overriding Baud Rate          : 57600
         AVR Part                      : ATmega328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : Arduino
         Description     : Arduino
         Hardware Version: 2
         Firmware Version: 1.16
         Vtarget         : 0.0 V
         Varef           : 0.0 V
         Oscillator      : Off
         SCK period      : 0.1 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: reading input file "C:\Users\Nicholus\AppData\Local\Temp\arduino_build_712598/Proj01_REV00.ino.hex"
avrdude: writing flash (1146 bytes):

Writing | ################################################## | 100% 0.35s

avrdude: 1146 bytes of flash written
avrdude: verifying flash memory against C:\Users\Nicholus\AppData\Local\Temp\arduino_build_712598/Proj01_REV00.ino.hex:
avrdude: load data flash data from input file C:\Users\Nicholus\AppData\Local\Temp\arduino_build_712598/Proj01_REV00.ino.hex:
avrdude: input file C:\Users\Nicholus\AppData\Local\Temp\arduino_build_712598/Proj01_REV00.ino.hex contains 1146 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.28s

avrdude: verifying ...
avrdude: 1146 bytes of flash verified

avrdude done.  Thank you.

It seems to have been a USB port issue on my computer. I found the one it wants to use now. Thanks.

Tom, still would like to hear your thoughts on the A0 vs 0 analog pin definition though.

Hi,
Good to here, that you found the problem.
If you define 0, you are defining pin 0, which is one of the programming pins on the 328 controller.

A0 ensures you are using the analog input pin A0.

Tom... :slight_smile:

@TomGeorge, it should not matter; analogRead() will translate it correctly

From the source code, only extracted the part that is for 328P

	if (pin >= 14) pin -= 14; // allow for channel or pin numbers

So A0 (14) will translate to 0 and if one uses 0 instead of A0, it will not change. The main risk is if one decides to suddenly use digitalRead which will read the wrong pin.

It's a matter of style, I consider it neater to use A0 so it's clear from the beginning that it's intended to use an analogue pin.

I like to use A0 because that's what's marked on the board. If I see a 0, it makes me think of digital pin 0. Of course I am experienced enough to know the difference just by seeing that it's used in analogWrite(), but I want to write code that's easy for anyone to use.

    int pirreading = digitalRead(pirPin); // Check PIR reading state
    while ( pirreading == HIGH ) {
      digitalWrite(relayPin, HIGH); // Turn lights on if PIRs detect signal
      delay(60000); // Wait 1 minute
      int pirreading = digitalRead(pirPin); // Check for PIR reading state change
    }

Inside your 'while' loop you create a new 'pirreading' variable which is then never used. To keep your 'while' from hanging forever you should remove the 'int' from that line so it sets the same 'pirreading' variable that the loop is testing:

    int pirreading = digitalRead(pirPin); // Check PIR reading state
    while ( pirreading == HIGH ) {
      digitalWrite(relayPin, HIGH); // Turn lights on if PIRs detect signal
      delay(60000); // Wait 1 minute
      pirreading = digitalRead(pirPin); // Check for PIR reading state change
    }

Or save code by reading the pin state directly:

    while ( digitalRead(pirPin) == HIGH ) {
      digitalWrite(relayPin, HIGH); // Turn lights on if PIRs detect signal
      delay(60000); // Wait 1 minute
    }

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.