

The main advantage of Interrupts in Arduino (or any microcontroller or processor on that note) is that the processor doesn’t have to continuously poll with the devices whether they need any attention. Interrupt is a mechanism through which the processor is informed to stop the current execution of instructions, execute a special event or process and then return back to the original execution. Here comes the concept of Interrupts to the rescue. The main problem with this approach is that the controller is continuously engaged in an activity (checking the status of the button in this case) and cannot perform any other tasks. This method of checking whether a device or pins needs service from the processor (the microcontroller) is called as Polling. In this scenario, the Arduino (or the ATmega328p Microcontroller, to be specific) keeps on checking for the state of the button in the loop function. push once for turning the LED ON and push again for turning it OFF. In this simple sketch, I am interfacing a push button with Arduino in order to toggle the status of the LED i.e. Now, consider the same situation with interfacing a button with Arduino. In this code, the setup function will run only once when the Arduino is powered ON and will initialize the Digital I/O Pin 12 as an OUTPUT pin.Īrduino will now enter into the loop function, where it turns ON the LED, waits for a second, turns OFF the LED, waits for a second and repeats the process. This mechanism is well and good if you just want your Arduino to execute a series of instructions sequentially like this simple Blinking of LEDs. We have implemented this method in all our Arduino projects right from Blinking LEDs to Controlling a Robotic Arm with an Android Phone. the code written in void setup function is executed over-and-over again. All the Arduino Projects that we have implemented so far are pretty straightforward i.e.
