# Why am I receiving “error 'Serial' was not declared in this scope” when building my Arduino sketch? [closed]

FOllowing on from this question, I'm following the tutorial for programming an ATtiny45 using an arduino.

Using v0021 of the Arduino IDE, with a Duemilanove which i've replaced the 168 chip with a 328, I'm able to upload the ArduinoISP sketch correctly. However, trying to upload the blink sketch to the Attiny results in the following error:

ArduinoISP.cpp: In function 'void setup()':
ArduinoISP.cpp:79: error: 'Serial' was not declared in this scope
ArduinoISP.cpp: In function 'void loop()':
ArduinoISP.cpp:136: error: 'Serial' was not declared in this scope
ArduinoISP.cpp: In function 'uint8_t getch()':
ArduinoISP.cpp:142: error: 'Serial' was not declared in this scope
ArduinoISP.cpp:143: error: 'Serial' was not declared in this scope
ArduinoISP.cpp:147: error: 'Serial' was not declared in this scope
ArduinoISP.cpp: In function 'void spi_init()':
ArduinoISP.cpp:164: error: 'SPCR' was not declared in this scope
ArduinoISP.cpp:165: error: 'SPSR' was not declared in this scope
ArduinoISP.cpp:166: error: 'SPDR' was not declared in this scope
ArduinoISP.cpp: In function 'void spi_wait()':
ArduinoISP.cpp:172: error: 'SPSR' was not declared in this scope
ArduinoISP.cpp:172: error: 'SPIF' was not declared in this scope
ArduinoISP.cpp: In function 'uint8_t spi_send(uint8_t)':
ArduinoISP.cpp:177: error: 'SPDR' was not declared in this scope
ArduinoISP.cpp:194: error: 'Serial' was not declared in this scope
ArduinoISP.cpp:198: error: 'Serial' was not declared in this scope
ArduinoISP.cpp:204: error: 'Serial' was not declared in this scope
ArduinoISP.cpp:209: error: 'Serial' was not declared in this scope
ArduinoISP.cpp: In function 'void start_pmode()':
ArduinoISP.cpp:263: error: 'SS' was not declared in this scope
ArduinoISP.cpp:265: error: 'SCK' was not declared in this scope
ArduinoISP.cpp:270: error: 'MISO' was not declared in this scope
ArduinoISP.cpp:271: error: 'MOSI' was not declared in this scope
ArduinoISP.cpp: In function 'void end_pmode()':
ArduinoISP.cpp:277: error: 'MISO' was not declared in this scope
ArduinoISP.cpp:278: error: 'MOSI' was not declared in this scope
ArduinoISP.cpp:279: error: 'SCK' was not declared in this scope
ArduinoISP.cpp:280: error: 'SS' was not declared in this scope
ArduinoISP.cpp: In function 'void program_page()':
ArduinoISP.cpp:348: error: 'Serial' was not declared in this scope
ArduinoISP.cpp:356: error: 'Serial' was not declared in this scope
ArduinoISP.cpp:362: error: 'Serial' was not declared in this scope
ArduinoISP.cpp:375: error: 'Serial' was not declared in this scope
ArduinoISP.cpp:387: error: 'Serial' was not declared in this scope
ArduinoISP.cpp:397: error: 'Serial' was not declared in this scope
ArduinoISP.cpp:400: error: 'Serial' was not declared in this scope
ArduinoISP.cpp:409: error: 'Serial' was not declared in this scope
ArduinoISP.cpp:412: error: 'Serial' was not declared in this scope
ArduinoISP.cpp: In function 'int avrisp()':
ArduinoISP.cpp:436: error: 'Serial' was not declared in this scope
ArduinoISP.cpp:497: error: 'Serial' was not declared in this scope


How can I fix this please? Or does anyone know if it works with a previous version of the IDE?

• Why is there no code included in this question? – Bort Feb 14 '17 at 14:17
• The very premise of this question statement is wrong. Quite obviously, the errors are in the ISP sketch, not the blink sketch. Perhaps your actual problem is that you are accidentally trying to build the ISP sketch (which should run on the ATmega you are using as a programmer) for the target ATtiny, rather than build the target blink sketch for the target. – Chris Stratton Feb 14 '17 at 15:22
• Same problem: I am using Visual Studio with Visual Micro and Arduino1.8 IDE. Solved by creating a completely blank project and copy/paste the whole code. Then, I was able to Build and Upload my code to an ATtiny85 with no problem. Never could figure out what the cause of the problem was. – Fred Cailloux Apr 1 '19 at 19:58

Doh fixed it myself. Needed to include the SoftwareSerial library in the updated blink sketch. That piece of info is missing from the tutorial linked above.

• If it's fixed, please close the question. – Toby Jaffey Oct 8 '10 at 10:19
• @Joby self answered questions cannot be marked as accepted by the OP for 2 days – fearoffours Oct 8 '10 at 10:40
• Well, I've learnt something new today. – Toby Jaffey Oct 8 '10 at 11:50
• can you be more specific in your answer? how did you include the softwareserial library in your sketch? – user391339 Dec 30 '14 at 19:15
• This answer is incorrect. The actual issue appears to arise from mixing up the ISP sketch for the ATmega with the blink sketch for the ATtiny. – Chris Stratton Feb 14 '17 at 15:28

For anyone coming after me, I ran into this problem, but no mention of SoftwareSerial was indicated. Rather (I know it sounds crazy) the answer was on this thread of the Arduino forums:

Throw some dummy code at the very top of your sketch (yes, even before includes). Mine:

char foo;


You need to include the SoftwareSerial Library in your updated sketch. In order to do this, go to the Sketch menu and scroll down through "Import Library..." to the SoftwareSerial Library, selecting it to add it.

Alternatively, add #include <SoftwareSerial.h> to the top of your sketch, the above does the same thing.