SunFounder 3in1 Kit
By the way, if you don’t use Serial.read() to get characters from the incoming stream, the characters from the in-
coming stream will be stacked together. For example, if you type A followed by AB, the incoming stream will accumulate
7 characters.
4.5.13 5.13 Interrupt
If you use some delay() in a project that uses sensors, you may find that when you trigger these sensors, the program
may have no effect. This is because the delay statement will cause the program to suspend, and the program will not
be able to obtain the signal sent by the sensor to the main control board.
In this case, interrupt can be used. Interrupt allows the program not to miss a pulse.
In this chapter, we use the active buzzer and buttons to experience the process of using interrupt.
In the loop() function, delay(1000) is used to count seconds. Put the button to control the buzzer into the ISR, so
that it will not be disturbed by the delay and complete the task smoothly.
Note: ISRs are special kinds of functions that have some unique limitations most other functions do not have. An
ISR cannot have any parameters, and they shouldn’t return anything. Generally, an ISR should be as short and fast
as possible. If your sketch uses multiple ISRs, only one can run at a time, other interrupts will be executed after the
current one finishes in an order that depends on the priority they have.
Required Components
In this project, we need the following components.
It’s definitely convenient to buy a whole kit, here’s the link:
Name ITEMS IN THIS KIT LINK
3 in 1 Starter Kit 380+
You can also buy them separately from the links below.
COMPONENT INTRODUCTION PURCHASE LINK
Arduino Uno R4 Minima -
Breadboard
Jumper Wires
Resistor
Button
Buzzer -
Schematic
182 Chapter 4. Basic Projects