Arduino Interrupts Tutorial

Поделиться
HTML-код
  • Опубликовано: 2 окт 2024
  • Dear friends welcome to this Arduino Interrupt Tutorial. In this video we are going to learn how to use interrupts with Arduino, an advanced but extremely useful feature of the Arduino. There is a lot to cover, so without any further delay let's get started!
    But what is an interrupt? Most microprocessors have interrupts. Interrupts let you respond to external events while doing something else. Suppose you are sitting at home waiting for the new ESP32 board, you have ordered a few days ago, to arrive at your mailbox. You are very excited so you check your mailbox every ten minutes to see if the board has arrived. This procedure is called polling, and we were using this technique a lot in our projects. But what if we had told the mailman to ring the doorbell at his arrival? This way, we are free to do anything we want and at the time the board arrives at the mailbox we get notified and we can use it at once. This example explains exactly how an interrupt causes a processor to act.
    🛒 Arduino Nano: educ8s.tv/part/...
    🛒 Breadboard: educ8s.tv/part/...
    🛒 Wires: educ8s.tv/part/...
    🛒 Buttons: educ8s.tv/part/...
    💻 Code & Parts: educ8s.tv/ardui...
    Want to learn to code?
    👨‍💻 Check my new RUclips channel: bit.ly/3tku2n0
    🎮 My Android Game: bit.ly/QuizOfKn...

Комментарии • 294

  • @Educ8s
    @Educ8s  2 года назад +5

    I hope you took away lots from this video and you managed to understand how interrupts work. Let me know below!
    PS. WANT TO LEARN CODING? CHECK MY NEW RUclips CHANNEL!
    bit.ly/3tku2n0

    • @paulpixzy5297
      @paulpixzy5297 2 года назад +1

      Please ! How can I use this one push button to turn on and off the whole system ,example inverter control board to turn on when pressed and also when off ?? Please help

    • @symontorres3952
      @symontorres3952 2 года назад +1

      Can i adjust the 10 secondd to .5 millis? Using the potentiometer of PIR

  • @theambient1
    @theambient1 6 лет назад +52

    "without any further delay let's get started!"
    I see what you did there... I see it!
    kudos to you Mr. educ8s!

  • @cw4608
    @cw4608 4 года назад +2

    ....so you check your mailbox every ten minutes. Best example of how interrupts work that I have heard. Thank you.

  • @jimstarr5840
    @jimstarr5840 6 лет назад +1

    Thank you. I’m working on my first project that is battery powered and was looking for a good way to save power. This is exactly what the doctor ordered.

  • @springwoodcottage4248
    @springwoodcottage4248 6 лет назад +1

    By far the best tutorial on interrupts I have seen & I have watched & read very many. Thank you so much for sharing this which is an extraordinary useful assistance to me.

    • @Educ8s
      @Educ8s  6 лет назад

      Thank you very much, my friend, for your kind words. I am glad it was helpful.

  • @dubbadan1
    @dubbadan1 4 года назад

    Well explained. I've not really understood the basics of interrupts till now.

  • @caffeinatedinsanity2324
    @caffeinatedinsanity2324 5 лет назад +7

    Just a little notice at the end part that you could have only used one interrupt on CHANGE mode and if the state of the interrupt pin is high, turn it on. If low, turn it off. It's a good idea to try and save the use of interrupt pins as much as possible, especially on an Uno.

  • @triac777
    @triac777 7 лет назад

    I have used timer interrupts but not hardware interrupts. The hardware interrupts are much easier and more useful. With this video there is no reason not to use them. Thank you.

  • @tbyers31
    @tbyers31 7 лет назад +14

    This is a fantastic video. Very clear and easy to follow. The pace of your teaching was perfect and the graphic illustrations some of the best to make this understandable. I will apply this technique to a water alarm I have planned. I want the moisture sensor to wake up the arduino and send an alarm via wifi or sms. Thank you!

  • @joedempseysr.3376
    @joedempseysr.3376 7 лет назад +60

    To show the true power of interrupts write a loop to blink an LED once per second. Then use the same code using the sensor to turn a second LED on or off by interrupt as you have done here. The demonstration will show how you can do two things at once using interrupts! Please show this on a future video.
    Thanks for all your good work! I thoroughly enjoy your videos! Your pace and explanations are outstanding!

  • @ValseInstrumentalist
    @ValseInstrumentalist 7 лет назад

    I recently learned to use interrupts when learning to program ATmel controllers without the help of an Arduino. It's good to see now how to use them with the Arduino.

  • @tonysicily2687
    @tonysicily2687 4 года назад

    Fast, simple clear and yummy mind PERFECT,
    This is exactly what I needed to know, not a huge monolithic project, but a simple
    Arduino is asleep
    Interrupted
    - Do action
    Go back to sleep
    Perfect 👍

  • @giannisdrompilis8509
    @giannisdrompilis8509 7 лет назад

    Grate job! Keep going.
    Interrupt have an 2 other triggers. The Change and the low. Some models also have the hi.
    You can do your project using only 1 input and look for change of input state.

  • @savage8336
    @savage8336 6 лет назад

    I LOVE THAT QUOTE AT THE BEGINNING OF THE VIDEO!!!

  • @georgekot6377
    @georgekot6377 7 лет назад +1

    Exactly what I was looking for ! A big thank you . Bravo.

  • @pauldusa
    @pauldusa 7 лет назад

    yes you can also use INT to be a counter, a water flow meter with a hall effect, or a RPM of a speed of a fan or motor, a IR car counter,,,, many many uses, Thanks for your good video's

  • @chemgreec
    @chemgreec 7 лет назад

    thats great I am building a project and I was going to look into this interrupts. I was watching your weather station project just to get the low power mode(i building an automatic cloth dryer for home) and then i needed to turn tha arduino on and of and there it is

  • @DaveBuildsThings
    @DaveBuildsThings 6 лет назад +7

    I've always had a hard time understanding how to use and program interrupts. Best description of interrupts I have seen yet. Simple and elegant. Thanks.

  • @wardmd
    @wardmd 2 года назад

    Only comment I have, is it would be good to explain/clarify why you wire the digital output of the sensor to TWO digital pins of the Arduino (as opposed detecting and handling BOTH events within the interrupt routine [with the CHANGE parameter to trigger on EITHER sensor state changes]).

  • @Torsan1977
    @Torsan1977 7 лет назад

    Very good tutorial! Thank you! I will have to try this on my battery powered projects!

  • @kfash5198
    @kfash5198 6 лет назад

    Best Interrpt video on RUclips

  • @amihaiba
    @amihaiba 6 лет назад

    Thanks for the video! as always clear and easy to follow.
    By the way the quote was originally by confucius and it was slightly different :)

  • @vikalpas
    @vikalpas 7 лет назад +9

    I am working on a digital speedometer for my motorbike and would use this to issue interrupt whenever Reed switch senses a revolution completion.

  • @brandondaniels9471
    @brandondaniels9471 7 лет назад

    Yea, I never knew this was possible. I'll defnitely use it for my projects if I can. Thanks for the excellent tips! :-)

  • @activeacommando
    @activeacommando 7 лет назад +12

    Συγχαρητήρια. Πολύ καλή και τεκμηριωμένη δουλειά!!

  • @DogRox
    @DogRox 7 лет назад +4

    Great video!! Quite informative! I knew how interrupts work I just never knew how to incorporate the knowledge into the Arduino! :-) I love your explanation comparing it to the mailbox and watching every 10 minutes that definitely sounds like me when I'm expecting hardware!! :-)

  • @Mailmartinviljoen
    @Mailmartinviljoen 2 года назад +1

    Thanks for this explanation. I successfully built an NES controller using an ESP32 that will mimic an 8-Bit shift register. It works on an actual Orgina Nintendo console.😀

  • @mohmhagras
    @mohmhagras 2 года назад

    Thank you. Excellent video

  • @donaldkormos5529
    @donaldkormos5529 3 года назад

    Good video ... I learned a lot !!!

  • @wolfy4664
    @wolfy4664 5 лет назад

    So cool,thank you, now i understand how to build the software of my new robot!

  • @benbowers3613
    @benbowers3613 6 лет назад

    Straight up educational

  • @resonance2001
    @resonance2001 7 лет назад +1

    That's another great video but may I suggest the use of digitalPinToInterrupt(pin) for the first argument to attachInterrupt for portability? It's a different story for the Arduino Due though. The pin and interrupt numbers are the same.

  • @hadihaque4547
    @hadihaque4547 6 лет назад

    very nice and to the point.Thanks for sharing.

  • @lafkihkhalid3473
    @lafkihkhalid3473 6 лет назад

    That was very helpful ! thank you so much

  • @dyer308
    @dyer308 3 года назад

    loved it!!!!!!!

  • @shivanngpuri
    @shivanngpuri 7 лет назад +7

    Hi nick!! Really thanks for all the wonderful and easy tutorial you make!!

    • @Educ8s
      @Educ8s  7 лет назад +3

      Thank you for the nice words! Cheers!

  • @michaelcostello6991
    @michaelcostello6991 7 лет назад +5

    Fantastic easy to follow interrupt demo. Thank You

  • @ahmedboudi1808
    @ahmedboudi1808 6 лет назад

    thank you very much..very nice and very clear!

  • @Lukas-qd7fy
    @Lukas-qd7fy 5 лет назад +1

    Great video! But sadly for some reason when I try, I fail. I even tried it with 2 boards.

  • @prabhatsaraswat2294
    @prabhatsaraswat2294 3 года назад

    I have a doubt. PIR sensor has only one signal output you attached it to digital pin 2 (Inturrept 0), the what is attached to pin 3 (Inturrept 1)

  • @Ammani-Yat
    @Ammani-Yat 6 лет назад

    thank you for this useful tutorial 👍

  • @blybaly
    @blybaly 7 лет назад +1

    Can you make further solid examples with different tools like lcd light control with movement?

  • @JahanZeb1976
    @JahanZeb1976 7 лет назад +11

    Excellent dear friend. Great projects discussed. This was what exactly I was looking for my projects. Keep the excellent work up.

  • @kasskon
    @kasskon 7 лет назад +2

    φιλε πολυ καλος αυτο ηταν απο τα πιο ενδιαφεροντα που εχεις κανει με την μεθοδο των διακοπών γιατι ειναι πολυ χρησιμο πολύ καλή δουλειά συνέχισε :D

  • @shvideo1
    @shvideo1 4 года назад +1

    Excellent tutorial, which is very well explained. Thank you for sharing your knowledge.

  • @omaryanas435949
    @omaryanas435949 7 лет назад

    very nice video thanks a lot, I have a question, why not ESP32?

  • @jaccosam
    @jaccosam 7 лет назад

    Very Interesting, Thank You

  • @wduraes
    @wduraes 7 лет назад +2

    Another AWESOME video. I'm learning a lot here. thank you for your channel! Keep up with the great work.

  • @paulpixzy5297
    @paulpixzy5297 2 года назад +2

    Your teaching is unique and clear see how you impact the knowledge I ve been seeking since I come across mcu's interrupt well explaned

    • @Educ8s
      @Educ8s  2 года назад +1

      Thanks!

  • @jalalbukhari1149
    @jalalbukhari1149 4 года назад

    i want to use these interrupts as a counter for fast moving objects. like seed counter. but i need to know which sensor will be most useful to detect the small grain sized particle to trigger the sensor and cause interrupt.

  • @monikachuttani6645
    @monikachuttani6645 6 лет назад

    You can also make any pin with interrupt

  • @scootergem
    @scootergem 3 года назад +1

    Excellent tutorial! Thanks

  • @TuanNguyen107bvt
    @TuanNguyen107bvt 4 года назад

    if u left the hand there forever, will LED light up forever or it just do 10s and back to sleep. then check for motion and on again ?

  • @pantoffelheld14
    @pantoffelheld14 7 лет назад

    Hello can you make a video on how to go from the breadboard to a prototype on pcbs?

  • @zerosandones7547
    @zerosandones7547 4 года назад

    what if you have delay? what will we substitute delay if we're gonna use an interrupt?

  • @MrBobWareham
    @MrBobWareham 7 лет назад +1

    Love the video as always I found it very interesting but what if when the button pressed it starts a timer to run as a one shot for 30 seconds then goes off until the next button press

  • @note9redmi17
    @note9redmi17 3 месяца назад

    Thank you for the great video. For the second PIR motion detect example, it can be simplified by using only one interrupt (digital pin 2) to control the led on/off. The following modified code works very well:
    #include "LowPower.h"
    #define PIRmotion 2
    #define LedPin 13
    void setup() {
    pinMode(LedPin,OUTPUT);
    pinMode(PIRmotion,INPUT);
    attachInterrupt(digitalPinToInterrupt(PIRmotion),OutputLED,CHANGE);
    }
    void loop() {
    LowPower.powerDown(SLEEP_FOREVER , ADC_OFF, BOD_OFF);
    }
    void OutputLED(){
    digitalWrite(LedPin,digitalRead(PIRmotion));
    }

  • @pratahsinnetamby
    @pratahsinnetamby 4 года назад

    Thanks for the great video.
    I have a questions - why do you use 2 pins for the 2 interrupts. Is it not possible to use the same pin, one when it goes HIGH and the other when it goes LOW?
    Appreciate your help.

    • @edgardodiaz8155
      @edgardodiaz8155 4 года назад

      I was reading the comments looking for someone asking or stating that, as conditions are different (Raise and fall), one pin interrupt can be used. I don't have any spare arduino now to verify this, so if any can do it, you are welcome to comment if it works or not.

  • @lastchance045
    @lastchance045 4 года назад

    I have enjoyed many of your videos and I like the possibility to see on screen your comments and I appreciate the downloads of code. This time however I got a fail when I tried to run the button sketch! Response: PROBLEM UPLOADING TO BOARD. I checked line for line in the code but can not see a problem. I see that for the second sketch a library is included. Should there have been a library for the button sketch? I note that 3 other comments write that the sketch failed. Your comment please.

    • @n3wmgmt118
      @n3wmgmt118 4 года назад

      That's not a problem of the code. Be sure that you're wiring everything up correctly and choose the right board and port.

    • @lastchance045
      @lastchance045 4 года назад

      @@n3wmgmt118 I followed your advice and re-checked. I didnt make any changes but now it seems to work. Still there is a problem. When I switch from on to off to on etc it works ok and then it fails and requires an extra switch press. Could some code change eliminate what seems to be switch jitter?

  • @chefbennyj
    @chefbennyj 7 лет назад

    Just gotta say, if it wasn't for your videos I wouldn't have been able to build my home automation motorized blinds for my home. Now, I'm wondering if I should have used interrupts with my project. Is it possible to use interrupts with nrf24 wireless modules? How would that look?

    • @1_HighDuke
      @1_HighDuke 7 лет назад

      Aren't the NRF24 modules attached to Arduino boards?

  • @gamecity7265
    @gamecity7265 6 лет назад

    I programed a stepper motor that stop 24 time in one loop.
    Would you know how to turn on an led for each stop ? So 24 blink.
    LED on while motors stops. LED off while motor rotates. Thanx for your great help

  • @MegaNonya
    @MegaNonya 7 лет назад +3

    Can you please provide breadboard layout diagram. It's somewhat obscured in the video.
    Thanks.

  • @karlsangree4679
    @karlsangree4679 Месяц назад

    Best explanation of interrupts I've heard. It's a well-done video with easy-to-follow instructions. I must admit I had to back up and turn on subtitles on in certain sections. I've worked with Arduinos for a while now and never heard the term "distal pin" before. After turning on subtitles I realized it was "digital pin" and suddenly everything made sense. 😄How is this the first time I've heard this guy? Now I have to check the rest of his videos. Good bye productive afternoon! lol

  • @Fitraj4440
    @Fitraj4440 2 года назад

    Can I use esp32 for this project

  • @SKKndS93
    @SKKndS93 3 года назад

    If I try to include the LowPower library for my Arduino Nano or Uno, it just says: "The library is not compatible with AVR boards"
    Sooooo, how does it work for you, if you are using the Uno version?

  • @bgable7707
    @bgable7707 3 года назад

    So, no de-bounce circuit needed in the first example? I'm trying to put together a device which I want to use two buttons to activate different ISRs. However, everything I have read indicates I will have trouble with the ISR firing multiple times with a button switch. Can you give some advice on this? Thanks for all your video's too!

  • @valakatz3967
    @valakatz3967 Месяц назад

    Thank you for sharing your knowlage, great video. Only one thing is missing, you should add the schematics this way it will be much more clearer, again thanks have nice day

  • @toastrecon
    @toastrecon 3 года назад

    So, what would happen if the PIR sensor was triggered any time there was motion? Maybe if it not only told you motion but also speed or distance? Would the interrupt "interrupt" itself? Say that the ISR called a function to read in the data from the PIR? Maybe if there were two PIR's?

  • @majestade2345
    @majestade2345 6 лет назад

    Hi, i have one question. If i want to use a Serial Print, what should i use instead the interrupt?
    in my case, i want to have a meter that, counts every second, and then i want to use a mobile app to connect throuhg API and get the meter value for that moment

  • @pippaknuckle
    @pippaknuckle 3 года назад

    This is really cool. What's not so great is my Arduino only has 2 interrupt pins.
    Maybe I can learn to use ESP32

  • @markschuurman4000
    @markschuurman4000 5 лет назад +1

    Excellent explanation, thnx!
    I'm wrestling this interrupt stuff for two weeks now, so I hope your basic setup will do the trick finally!

    • @markschuurman4000
      @markschuurman4000 5 лет назад

      After reading this (www.arduino.cc/en/Tutorial/DigitalPins):
      Often it is useful to steer an input pin to a known state if no input is present. This can be done by adding a pullup resistor (to +5V), or a pulldown resistor (resistor to ground) on the input. A 10K resistor is a good value for a pullup or pulldown resistor.
      I attached a 1K restistor from sensor to GND which gave an accurate result.

  • @vangeziyorum9725
    @vangeziyorum9725 2 года назад

    I made an ultrasonic height and weight measuring device. I wrote the codes with Arduino and arduino UNO. Normally everything works fine. But sometimes after waiting for an hour or two, I take a measurement, the device is measuring, it shows the numbers on the screen, but it does not print the result to the thermal printer. The numbers stay on the screen, then the device is reset with whatchdog. This is starting to get annoying. can you help me with this

  • @alanfairclough3427
    @alanfairclough3427 Год назад

    I have tried many videos of interrupt codes and always get the same error message : "buttonPressed" was not declared in this scope.
    What am I doing wrong?

  • @Johncoffee2002
    @Johncoffee2002 7 лет назад +4

    Awesome - as always !!

  • @thisoldjeepcj5
    @thisoldjeepcj5 2 года назад

    Thanks for explaining interrupts.
    I will use with photo interrupter for tachometer.

  • @tserbos2
    @tserbos2 7 лет назад +8

    μπράβο ρε φιλέ... πολύ δουλειά είχε αυτό το βίντεο!!! πρέπει να σου πήρε εβδομαδα.. με το μονταζ, σπικαζ,κτλ
    σε ευχαριστουμε που μοιραζεσαι τις γνώσεις σου δωρεάν!

    • @Educ8s
      @Educ8s  7 лет назад +7

      Όντως φίλε αυτό το βίντεο μου πήρε μια βδομάδα να το φτιάξω, αλλά πιστεύω το αποτέλεσμα άξιζε τον κόπο!

  • @Vietnamcamping89
    @Vietnamcamping89 3 года назад

    I have declared buttonPressed function but i get this errror
    "'buttonPressed' was not declared in this scope"

  • @emiltoteb
    @emiltoteb 9 месяцев назад

    Why is it just now I lean about interrupts?! That'll save me a lot of headaches in the future, thanks!

  • @mtalhakhalid1679
    @mtalhakhalid1679 2 года назад

    does interrupt reset timmer flag in Arduino as well??

  • @koltphillips6724
    @koltphillips6724 4 года назад +1

    AH! This video is terrific. I've been looking for a tutorial that combines both interrupts and sleep modes and this code is so easy and streamlined. Question though, without using a delay, how did you get the motion sensor to wait 10 seconds? Is that just the built in functionality of the sensor? Thanks for the great video.

    • @Educ8s
      @Educ8s  4 года назад +1

      Yes this functionality in built-in to the sensor

    • @koltphillips6724
      @koltphillips6724 4 года назад

      @@Educ8s Thank you. You just streamlined my project.

  • @etrockma5558
    @etrockma5558 5 лет назад

    Awesome explain 8266 interrupts !
    like & subscribe

  • @ClaudeDufourmont
    @ClaudeDufourmont 3 года назад

    Congretulations for your video, very interesting

  • @BFC24
    @BFC24 3 года назад

    How I do interrupt when signal low and interrupt break when signal is come to high

  • @mubasheer5584
    @mubasheer5584 4 года назад

    Do you have any video made up already based on interface of Arduino with sx1276 lora module..
    Helping me will be appreciated

  • @ajayanchal
    @ajayanchal 2 года назад

    great video !!! just one question. in the second example with pir sensor why there was no need for a pull up or pull down resistor?

  • @geomcc39
    @geomcc39 Год назад

    Thank you my new friend ! I like your idea of sharing and helping people learn Electronics etc .

  • @jacopo.scarpellini
    @jacopo.scarpellini 4 года назад

    Is the button in the first example a momentary button? If so, why doesn’t the led only stay on during the short time you press it but instead it stays on until you press it again?

  • @rooster443
    @rooster443 4 года назад +1

    Where have you been all this time Master! Thank you for this.

  • @tubecandle
    @tubecandle 2 года назад

    How much amazing information! Great stuff.

  • @MSuriyaPrakaashJL
    @MSuriyaPrakaashJL 4 года назад

    well in the 1st program code is arduino sleeping or what>??

  • @WiperTF2
    @WiperTF2 3 года назад

    Thank you so much, finally got an interrupt to work on my Mega 2560 board. Pretty confusing how the "0" interrupt uses pin 2, and so on...

  • @mitchellcojocariu3363
    @mitchellcojocariu3363 2 года назад

    Why do you use 2 input pins for the single sensor output? The state will be the same on both pins and it will never send different states at the same time?

  • @ecsyntric
    @ecsyntric 3 месяца назад

    arduino is sleeping but the motion sensor is always powered on

  • @OcenaSoft
    @OcenaSoft 4 года назад

    I would like to use this method to turn on a neopixel programme when the level of light in the window has reached a particular level (dark) and turn off when the level has increased (light). would I use in interrupt for this too?

  • @TheHoviat
    @TheHoviat 6 лет назад +1

    Thank you very much, that was so helpful!

  • @splashinglures
    @splashinglures 4 года назад

    can i deep sleep an arduino for 7 hours then wake up for 10 secs, then deep sleep for another 7 hours? so it loops too

  • @nolantaylor1760
    @nolantaylor1760 7 месяцев назад

    I am taking your tuition seriously. I am creating a control algorithm for an Arduino Nano that has two hardware interrupts(input from Photo_interrupter, and input from Photo Beam detector parallel with a Push_Button switch) 2 Software Interrupts(Counter resets). Thank you for the clear explanations.

  • @marcodev3375
    @marcodev3375 5 лет назад

    How about interrupt in LCD touchscreen, triggers when a button touched.

  •  6 лет назад

    Hi, I want data from the sensor once. But since the arduino is constantly powered and therefore operates, data is constantly coming from the sensor. How can I do this with an interrupt or anything? Thank you

  • @jumbo999614
    @jumbo999614 4 года назад

    Never knew 1 output pin from sensor can be attached to 2 input pin(interrupt pin). I learned something new today. Thank you.
    Anyway, what is ADC_OFF and BOD_OFF? Also What happen if the sensor output analog value (0-1023) instead of High or Low?