ESP32 with PIR Motion Sensor using Interrupts and Timers

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 ส.ค. 2018
  • For complete project details (schematics + source code), visit ► randomnerdtutorials.com/esp32...
    This tutorial shows how to detect motion with the ESP32 using a PIR motion sensor. In this example, when motion is detected (an interrupt is triggered), the ESP32 starts a timer and turns an LED on for a predefined number of seconds. When the timer finishes counting down, the LED is automatically turned off.
    Like my page on Facebook:
    / randomnerdtutorials
    Add me on Google+:
    plus.google.com/+RuiSantosdotme
    Follow me on twitter:
    / ruisantosdotme
    Subscribe for more projects like this!
    bit.ly/subscribeRNT
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 36

  • @RuiSantosdotme
    @RuiSantosdotme  5 ปีที่แล้ว +3

    You can find the complete project details (schematics + source code) on my blog ► randomnerdtutorials.com/esp32-pir-motion-sensor-interrupts-timers/

  • @bgable7707
    @bgable7707 2 ปีที่แล้ว

    EXCELLENT as always! I obviously had viewed this video in the past because the "thumps-up" was highlighted. Yet, watching it another time, helped solidify ISR's again. Your walking through the code line by line, explaining clearly the components use and their value brings these all together.

  • @bobapthorpe
    @bobapthorpe 5 ปีที่แล้ว +6

    I believe the variables startTimer and lastTrigger should specified as volatile since they are updated in the ISR. Also, you probably shouldn't call Serial.println() in the ISR; I understand you're doing it for the purpose of illustration, but in production code you want the the ISR to execute extremely quickly with as few side effects as possible. Otherwise this is a good, straighttforward example of how to use external interrupts; thanks for posting it.

  • @aprenderinvestirpt
    @aprenderinvestirpt 5 ปีที่แล้ว +3

    Boas rui, estou a pensar utilizar esse sensor (PIR) com um esp-01 mas preciso que seja com bateria. Que bateria/pilhas aconselhas e como fazias o circuito de modo a que durasse mais ou menos 4-6 meses ou ate mesmo um ano ? (Estando em deepsleep)

  • @davebeckham5429
    @davebeckham5429 5 ปีที่แล้ว

    Excellent information. Thanks, Rui.

    • @RuiSantosdotme
      @RuiSantosdotme  5 ปีที่แล้ว

      Thanks! I'm glad you found it helpful!

  • @alexmorales1997
    @alexmorales1997 4 ปีที่แล้ว

    VERY VERY VERY USEFUL, I RLY LIKED IT!!!!

  • @eriklaken1025
    @eriklaken1025 5 ปีที่แล้ว

    Perfect, thank you.

  • @alessandromaltese7578
    @alessandromaltese7578 5 ปีที่แล้ว

    Thank you very much :D!!
    I dont know but when the pir triggered and the LED turned on and again off, it takes to much time, until the pir detects again some motion. How can I change it?

  • @MeinElektronikHobby
    @MeinElektronikHobby 5 ปีที่แล้ว

    ... thanks for more information about the ESP family.

    • @RuiSantosdotme
      @RuiSantosdotme  5 ปีที่แล้ว

      You're welcome! Thanks for watching

  • @reiniervanderbrugge5023
    @reiniervanderbrugge5023 5 ปีที่แล้ว

    Hi i have used your sketch and tutorial and it works perfect with one pir sensor.... but i want to use 3 pirsensors to activate a relay do you know how this can be done?

  • @markroles7304
    @markroles7304 5 ปีที่แล้ว +2

    If you are having the motionSensor pin configured as a pullup, how will then the interrupt ever catch a rising signal since it will always be high then?

  • @hafzamhasan8532
    @hafzamhasan8532 5 ปีที่แล้ว

    can i use the same esp32 to add in servo motor in ur other tutorial, ? how ?

  • @EricOnYouTube
    @EricOnYouTube 2 ปีที่แล้ว

    Woohoo. It works! :) Thanks. I put mine on G13, though.

  • @gibo588
    @gibo588 3 ปีที่แล้ว

    You can also use Ticker() library which works with millis() non blocking.

  • @vigatex
    @vigatex 4 ปีที่แล้ว

    Hi,
    Can the PIR sensor as a wake up input to a board in deep sleep please?

  • @Smart3DPT
    @Smart3DPT 4 ปีที่แล้ว

    Olá boa noite com um esp consigo accionar um servo 9g através do movimento?

  • @aman5862
    @aman5862 7 วันที่ผ่านมา

    How can we send the time duration the light is on when sensed by pir on some cloud or Google sheet?

  • @norsuhaila4188
    @norsuhaila4188 5 ปีที่แล้ว

    Can i know how the wires are installed between nodes with pir

  • @mrdanker6756
    @mrdanker6756 5 ปีที่แล้ว +1

    ESP32 actually uses freeRTOS (your code runs within it), which handles threading & tasks. You can split code up into different tasks on the same core, and use delay, only having it affect one task, while the others continue to run

    • @simonmay9039
      @simonmay9039 4 ปีที่แล้ว +1

      Yes, the Arduino framework wrapped around the ESP32 + ESP-IDF maps the Arduino delay() function into a call to the FreeRTOS function vTaskDelay(). This is non-blocking, ie it gives the time taken by the delay() back to FreeRTOS for it to give to other tasks.

  • @eduardomanusse2904
    @eduardomanusse2904 4 ปีที่แล้ว

    excellent

  • @quaternion-pi
    @quaternion-pi 5 ปีที่แล้ว

    Great tutorial. What happens if an interrupt is called while the program is executing in the interrupt function? Does it interrupt the interrupt function?

    • @RuiSantosdotme
      @RuiSantosdotme  5 ปีที่แล้ว

      Thanks! When using interrupt functions, you should try to keep what they do as simple as possible (they should be executed very quickly). If an interrupt is triggered while it's still running the interrupt function, it should run it again. (Note that this PIR motion sensor holds the state HIGH for a couple of milliseconds/seconds, so it's unlikely to trigger the interrupt function too quickly)

    • @quaternion-pi
      @quaternion-pi 5 ปีที่แล้ว

      Thanks, was just wondering if Serial.println() statements should be avoided in interrupt functions - or do they execute quickly enough. Love your informative videos.

    • @RuiSantosdotme
      @RuiSantosdotme  5 ปีที่แล้ว

      Yes, they should execute fast enough. So, you can have the Serial.println() statement during your tests/debugging, but for a final project I recommend always deleting all the unnecessary Serial.println commands.

  • @sarjananganggur5546
    @sarjananganggur5546 2 ปีที่แล้ว

    Apakah anda bisa membantu saya untuk mengkoneksikan sensor pir ke database mysql

  • @Techonsapevole
    @Techonsapevole 5 ปีที่แล้ว +2

    Thanks, can you wake up the ESP in deep sleep via PIR ? Can you provide an example?

    • @GnobarEl
      @GnobarEl 4 ปีที่แล้ว

      Thats a good question!

  • @amelliamendel2227
    @amelliamendel2227 3 ปีที่แล้ว

    can you wake it from sleep when motion is detected?

  • @sahilmansoori3511
    @sahilmansoori3511 10 หลายเดือนก่อน

    Can I connect this sensor with any other ESP32?

  • @chinmayih.k.3370
    @chinmayih.k.3370 5 หลายเดือนก่อน

    I have COM3 port
    And I can open serial monitor
    What to do to open COM4 monitor

  • @barbarasales1745
    @barbarasales1745 ปีที่แล้ว

    Rui o meu não está a dar... ajuda-nos

  • @isro_iuac
    @isro_iuac ปีที่แล้ว

    code error 🙏

  • @intheshell35ify
    @intheshell35ify ปีที่แล้ว

    Lets not block code, lets poll!!!! Huh?