InterruptExample

This Lab simply shows how to use an interrupt to make a buzzer beep and and LED switch on and off

Step 1: Attach Power and Buzzer

For this test I used an active buzzer. Be sure to attach a 100 ohm resistor to the buzzer to prolong the buzzer's life span.
1. Connect the 5v pin to the hot rail and the GND pin to the ground rail.
2. Connect the buzzer to the GND and hot rails.

Step 2: LED's and Button

The button is what we use to trigger the interrupt to occur.
1. Connect the LED's to the GND rail and then with a 220 ohm resistor connect them to their pins on the Arduino. For this I used pins 7 & 8.

2. Connect a 220 ohm resistor to the buttons ground then the ground to the GND rail.

3. Connect power to the hot rail

4. Connect the control pin to the opposite pin from the ground into pin 2 for the interrupt attach

CODE!

int Green = 9;

int Red = 8;

int Buzzer = 12;

int Button = 2;

int Sound = 1000;

volatile byte Blink = LOW;

void setup() {

Serial.begin(9600);

pinMode(Red, OUTPUT);

pinMode(Green, OUTPUT);

pinMode(Button, INPUT);

pinMode(Buzzer, OUTPUT);

digitalWrite(Green, HIGH);

attachInterrupt(digitalPinToInterrupt(Button), Buzz, RISING);

}

void loop() {

digitalWrite(Green, Blink);

digitalWrite(Red, LOW);

delay(1000);

Blink = !Blink;

Serial.println(Blink);

}

void Buzz(){

digitalWrite(Green, LOW);

Serial.println("Start");

digitalWrite(Red, HIGH);

tone(Buzzer, 1500, 500);

Serial.println("END");

}

Share

    Recommendations

    • Trash to Treasure

      Trash to Treasure
    • Arduino Contest 2019

      Arduino Contest 2019
    • Tape Contest

      Tape Contest

    Discussions

    0
    None
    Swansong

    1 year ago

    That's a neat setup :) Do you have any photos of the finished project?