I'm programming an ATTiny 85 using the Arduino IDE and an Arduino Nano as "Arduino as ISP" to program the ATTiny. I succeeded a week ago and now I want to program a second chip but get the 'GIMSK' was not declared in this scope error during compile.

The GIMSK is called at the start of the sleep() function. I tried adding #include <avr/interrupt.h> but continue to receive the compile error.

#include <avr/sleep.h>    // Sleep Modes
#include <avr/power.h>
#include <elapsedMillis.h>
const int hallPin = 2;     // the number of the hall effect pin
const int magnetPin =  1;      // the number of the magnet pin
const long debouncing_time = 15; //Debouncing Time in milliseconds
// variables will change:
volatile int hallState = 0;         // variable for storing the hall counter
volatile unsigned long last_micros;
elapsedMillis timer;

void setup()
  pinMode(magnetPin, OUTPUT);
  pinMode(hallPin, INPUT);
  digitalWrite(hallPin, HIGH);    // pullup enabled.
  // Attach an interrupt to the ISR vector
  attachInterrupt(0, pin_ISR, RISING); //default interupt pin is always 0 on attiny85 (physical pin 7)
  timer = 0;

void sleep()
    GIMSK |= _BV(PCIE);                     // Enable Pin Change Interrupts
    PCMSK |= _BV(PCINT2);                   // Use PB2 as interrupt pin
    ADCSRA &= ~_BV(ADEN);                   // ADC off
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);    // replaces above statement
    sleep_enable();                         // Sets the Sleep Enable bit in the MCUCR Register (SE BIT)
    sei();                                  // Enable interrupts
    sleep_cpu();                            // sleep
    cli();                                  // Disable interrupts
    PCMSK &= ~_BV(PCINT2);                  // Turn off PB2 as interrupt pin
    sleep_disable();                        // Clear SE bit
    ADCSRA |= _BV(ADEN);                    // ADC on
    sei();                                  // Enable interrupts
} // sleep

Can anyone give me a pointer? I had saved my work so I'm puzzled by the error.

Thank you.


enter image description here

Programming configuration for the ATTiny 85 via the Nano as ISP.

  • For what board are you compiling? Are you sure it was the Attiny85?
    – chrisl
    Sep 8, 2021 at 21:10
  • @chrisl, yes, ATTiny 85-20PU. I'm using the Nano plugged into a breadboard to program the bare chip. I'm using the procedure here.
    – Transistor
    Sep 8, 2021 at 21:20

1 Answer 1


In order to program the ATtiny85, you need a suitable board support package, and you have to configure the Arduino IDE in order to target that specific chip.

From the description of your issue, it sounds like you did that a week ago, and then, maybe by accident, you undid the IDE configuration. Now the IDE is targeting a type of MCU that does not have a register named GIMSK. Double check that you have the right target configured.

Another possibility would be that the Arduino.h file for the core you are using does not automatically include avr/io.h. If this is the case, add

#include <avr/io.h>

at the top of your code.

  • 1
    You were correct with the "target that specific chip" comment. The Arduino IDE doesn't seem to save these with the project or they get switched when I'm working on the Nano and switching to using the Nano as ISP. I've added a screengrab into my question which is now solved. Thank you.
    – Transistor
    Sep 9, 2021 at 19:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.