Using HC-SR501 Motion Sensor with relay and Arduino code to turn ON AC bulb

แชร์
ฝัง
  • เผยแพร่เมื่อ 21 พ.ค. 2024
  • This video explains how to control AC bulb or alarm system with HC-SR501 motion sensor using Arduino
    I will reply to all Subscriber's 🔔 questions. So make sure to Subscribe.😊
    Please like 👍 the video and type simple word in the comment. It helps me a lot.
    Get the code and resources for this video: bit.ly/relay-motion
    ** Purchase HS-SR501 from **
    Amazon USA: amzn.to/3dvyUOm
    Amazon Canada: amzn.to/3dy0WJ3
    Amazon Europe (All Europe): amzn.to/3dAbkzK
    00:00 Start
    00:35 Hardware explained
    04:35 Relay power rating
    06:00 Wiring explained
    07:53 Arduino Code Explained
    09:48 Demonstration of this project
    Tutorial by Ahmad Shamshiri form Canada
    ****************************
    Learn Arduino from a proven instructor with 100s of projects, code, wiring diagram in structured course in one place. Purchase Arduino Course at Udemy.com : robojax.com/L/?id=153
    ****************************
    If you found this tutorial helpful, please support me so I can continue creating contents like this. Here is PayPal link paypal.me/robojaxTV
    Get early access to my videos by becoming my Patreon and and have your name mentioned at end of very videos I publish on TH-cam: robojax.com/L/?id=97
    If you want to learn Arduino from proven instructor on **Udemy**: bit.ly/rj-udemy
    Follow me on Facebook robojaxTV
    Follow me on Twitter: / robojaxtv
    Follow me on Instagram: / robojax
    Tutorial by Robojax.com
    Get other projects code and learn Arduino
    robojax.com/learn/arduino
    #robojax #robojax_HC-SR501
  • วิทยาศาสตร์และเทคโนโลยี

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

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

    Another great project. thanks

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

    It's very most use full at home

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

    thank you very much Gustavo ..

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

      You are welcome.

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

    Can you make tesla meter for the number of design wind turbines .. I need it very much and I have a lot of waiting

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

    الله ينور عليك يسطا

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

      شکرا و ایا کم.

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

    Thanks for support

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

    nice one

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

      Thanks.

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

    Hi Robojax. Amazing videos. I would say that the code would be almost the same if I substitute the motion sensor with a vibration sensor (SW-420 Vibration Sensor ).

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

      Hi, Thank you. Yes most sensors work the same way except pins are labeled differently or they are located in different location.

  • @barbarasilva675
    @barbarasilva675 3 ปีที่แล้ว +2

    Hello, thanks for the video tutorial! I was wondering if you can connect multiple PIR sensors to trigger the same relay? If yes, would you be able to tell me what would be the code line for that? Regards, Fernando

    • @robojax
      @robojax  3 ปีที่แล้ว +1

      Hello, I have explained this line by line and what it does. So if you play the code section 2,3 or more time you should easily understand and turn the same relay on.

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

    please make a video using 2 or more pir"s with one bulb
    it will be more helpful to me

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

      I can provide you with the code and all the information

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

      it should work the same, (connect new sensor's ground and power pins) and just connect the signal to another pin number, and in your code, you test for that pin number too (besides the previous sensor's pin).

  • @Rebius
    @Rebius 3 ปีที่แล้ว +1

    Hi, great video. I was just wondering, could you connect the PIR sensor directly to the relay?

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

      Hello, yes you can.

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

    It can be used to make a sanitizing tunnel for covid 19,just connect pump istead of lamp

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

    Hey, great video btw. I used exactly what you used and it works great. I do have some concerns though: is this risky at all? I intend to keep it running 24/7. Will the arduino overheat or the relay have problems ? because I heard the relays tend to fire up frequently on voltage change and such? Do I have to worry? It's inside an electrical box right outside the house with all the components inside that box.

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

      Hey, I have not tested the reliability of components. there are tones of different brands producing components. But for Arduino and relay you can add 200mA fuse on the 5V power line so would never allow extra current that might cause fire. Try get relay from Digikey or some other reliable store and make your own module. here is how you can drive a 5V relay using Arduino th-cam.com/video/N-fFk51Eb8s/w-d-xo.html Arduino itself should be good quality if you purchase Authentic Arduino from Amazon amzn.to/2KApAwK it should be more reliable. Good luck and stay safe.

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

      @@robojax Thanks for replying, I'm sorry I'm not really good with these stuff. Does the fuse have to be 200mA? because the least I could find from local stores are 1A. And what exactly causes the fire or what is more risky should I say? the AC 220V on the relay connected to the outlet or the 5V from Arduino?

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

      @@robojax I'm using the official Arduino Uno - R3 btw

    • @robojax
      @robojax  3 ปีที่แล้ว +1

      anything I say here will be used against me. This is DIY project. You should know to be careful and take precaution. . Ask a professional to assist you. For myself I trust the relay like I do trust tones of other electronics devices I have. But for you I mentioned the fuse to be safe incase court asks me to come and answer. These relays are used widely in lots of electronic devices.

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

    I wonder if you can help (great video thanks!) I have this sensor but would like a small unit without the arduino. I have it linked with simple single LED and transistor to test. It's working.. but whatever I set the RIGHT wheel for delay to, it keeps randomly lighting with gaps in power. So it will light for 3 seconds, then stop, then light again even though I keep moving it switches off. ?

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

      You are welcome. Please watch the video again. There is jumper and two controller. You have experiment and find solution for yourself. The jumper is very important. Have patience and play with it and write down on paper what you did in each step and then compare the results.. this device is very good and it should work for almost any situation. When finding and testing, your single motion will change everything so make sure you sty still if you want no trigger happen.

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

      Robojax I’ve moved jumper. It doesn’t continually light through motion. Just resets. . Many thanks.

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

    Hi Robojax. The pir works fine with arduino with your code, however I don't understand why it is 'digitalWrite LOW' to turn on the relay and the opposite to turn off? When I use the pir with the relay running from 5v dc supply (not through arduino)then the light is always on. Do you know why it is like that, looks like the pir doesn't trigger. Thanks

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

      Hello, your question took me so long to look at videos and codes to find something even though I have explained it in other multiple videos but see this video 15:44 th-cam.com/video/JMBgGO07YLM/w-d-xo.html it is the trigger type. depending on your relay. please don't forget to subscribe. you lose nothing.

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

    Hello,
    Can you use the power cord from the lightbulb to power the arduino if you step down the voltage? I would like to only use one cable

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

      No you can't. AC light bulb is AC and Arduino needs DC .

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

    HI! great introduction video. still new to Arduino, but how might I go about having 16 relays go on at random times from 1 motion sensor?

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

    Hi
    Love your video and explanation
    I would like to simply turn on and off a 5V DC laser light that has a simple on off switch which I would like to control by the Audrino & PIR sensor
    Can it be done without a relay ?
    Can you suggest a solution ?

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

      Hi, I don't know for what reason you want to avoid using relay but we need a switch to turn ON/OFF the load. If your laser light needs up to 30mA maximum yes you could use Arduino without relay. if you don't like relay, then you can use solid-state switch like mosfet shown here th-cam.com/video/17vqLv508Uw/w-d-xo.html

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

    If I wanted to set up four different motion detectors, each to a different color, could I do it all onto the same arduino board or would I need four different boards? For sensing in four different directions.

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

      Hello, yes you could.

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

    can this setup work in a way where the bulb is glowing when there is movement and it gets switched off when there is no movement? basically it should be switched on for the entire time when there is movement instead of giving a timer for 6 sec or 300 sec as you explained in the video. my project is stuck because of this issue. i would be thankful if you can help me out.

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

      this will be affected by light.

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

      what i meant was that instead of getting switched off automatically after few seconds it should get switched off only when there is no movement

  • @Axel-zg8yc
    @Axel-zg8yc 5 ปีที่แล้ว

    Hello, Sir.
    I am interested in hooking up and 8 channel relay with a motion sensor. Do you have a video on that?

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

      Hi,
      I have 4 channel Solid State relay which you can use the Motion sensor with th-cam.com/video/3EZecphNdAI/w-d-xo.html

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

    hello sir! in our project, we have used ADXL335 accelerometer sensor to detect vibrations. We planned to add an automatic light switching using a 5 volts relay. can u please help me out with the codes to interface the accelerometer, relay and arduino to switch on a dc bulb

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

      Hello, use you can use the code and this video th-cam.com/video/58XWVDnB7Ss/w-d-xo.html good luck

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

    How about i change a bulb to l298n to move the dcmotor?

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

    Hi, Can you guys tell me why if the motion is detected, the relay is low and it will turn on?? #respect

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

    Thank you for the vedio .
    Is there a way to do this motion with the relay without the arduino ?
    What I want to do is to connect this to a Halloween props and I want the motion to trigger the relay and the relay will be connected to a small motor that will move the props ?!

    • @robojax
      @robojax  2 ปีที่แล้ว +1

      introduction to motion sensor video th-cam.com/video/piuUfGVafC0/w-d-xo.html and see if the time you can set is enough for your application. then yes you can use it with the relay. The relay shown in this video is LOW Level trigger meaning it turns ON with LOW (or zero volt) level signal. see the high level trigger signal relay th-cam.com/video/58XWVDnB7Ss/w-d-xo.html

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

      @@robojax thank you for the reply,but this vedio is for arduino ?
      What I want is to use the motion sensor with a relay without the arduino ? So is there a relay that can do that or do you have a vedio for that ?

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

    How would you use a NANO Arduino board it has only 1 x 5V pin out ?
    Can you simply piggy back from the one pin?

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

      Hi, yes you can connect multiple items to the same 5V using a bread board

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

    Hey I'm a bit confused so I want to ask something, still studying here.. if you connect Relay to normally open, why would you write LOW to turn on the relay? Thank you

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

      Hi, perhaps you missed what I've explained. this relay is LOW level trigger. meaning it will turn ON when it receives zero or LOW and turn OFF when it receives 5V or anything about 2V.

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

      @@robojax okay thank you very much for the explanation

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

    Can i connect motion sensor and bluetwooth module both at a same time?

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

      Yes you can

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

    If you move your hand out and wait for light to stop, then move hand back in, it doesn't lit up, does it ? It has a 4-5 seconds delay to re-trigger?
    Is that normal ?

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

      it should. I have shown how to adjust it. Watch it carefully. There is adjusting and position of object or something.

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

    Would you please add any buzzer to this circuit

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

      This bulb is buzzer, speaker alarm or whatever you want. Light is just example and demonstartion.

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

    How to use 2 pir senser in 1 aurdiuno plz help

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

      I will make the video in the future, but you can get the idea from this video th-cam.com/video/WQ3oFyF5qeY/w-d-xo.html

  • @LeNguyen-yy1qi
    @LeNguyen-yy1qi 5 ปีที่แล้ว

    You can replace relays with other components

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

      Yes you can use any other relay you want. But you need Arduino (any arduino) and the HC-SR501 sensor.

    • @LeNguyen-yy1qi
      @LeNguyen-yy1qi 5 ปีที่แล้ว

      @@robojax Ohh... Can you make this circuit in combination with the mechanical switch

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

      The possibilities are endless.

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

    your tutor is very interested but the code for arduino is not RUN, please say someting

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

      thanks i got it my error, keep it up sir!

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

      you are welcome and good luck.

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

    hello , what is the Arduino function in that ?

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

      you can have time control on how long the light or alarm can be ON or OFF or you can do more thing. This is just opening the opportunity to do more.

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

      @@robojax I need power supply circuit in that , can you help me ? motion sensor with arduino n power supply circuit 🙏

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

    So If you want that relay to stay on for 10 seconds you need to increase delay time, but when loop gets to that delay it cant trigger relay because of that delay...

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

      first if you want it to stay for 10 seconds, then all other triggers should be ignored. Isn't it? Yes there is solutions. We can use millis() which will not keep the loop waiting. see my two videos in that topic th-cam.com/users/robojaxTVsearch?query=millis

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

      @@robojax so if the motion still there , the relay will always be triggered if millis() is used, right? And that will make the lamp always On?

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

    THE MOTION SENSOR WORKS IN WHAT i DID.. BUT THE GREEN LIGHT ON THE RELAY IS NOT LIGHTING.. THE SAME THING HAPPEN TO MY AC BULB.. WHAT SHOULD I DO TO MAKE THE RELAY WORK SIR

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

      check the wiring. Do not modify the code first.

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

    is it working on uno?

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

      Have you see the video?

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

      @@robojax from this vid, this arduino board have 2 5V Pins. but for my board, which is UNO. it only have 1 pin

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

      see this video th-cam.com/video/omyIFd1FqCI/w-d-xo.html to make additional 5V or GND pins

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

    Hii sir can u help us

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

    where can i get the coding

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

      I mentioned in the first 45 seconds of video. Every video on youTube has description text which is under the video. I have so many important link for the video under the video in the description. Please check it.

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

    Can we set upto 10 minutes?

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

      It is just a number you can do even 100 hours

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

      No reply? Did you set it to 10 minutes?

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

      @@robojax where to set f ex 10 minutes? This part : delay(500); ?

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

    I have only one 5v port in arduino

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

      then in make one of the pin as output. like this
      in the setup() put this for example pin 5
      pinMode(5, OUTPUT);
      digitalWrite(5,HIGH);
      and now pin 5 will always be HIGH which is 5V and you can use it as 5V source for small items like relay or sensor.

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

      @@robojax Please more explanation please

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

      @@robojax HI CAN YOU MAIL ME MORE DESCRIPTION ON THIS ONE

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

      @@robojax you can use female header connect the two 5v to one 5v in arduino right?

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

    Relay board name

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

      I am sorry I did not understand if this is statement or question. If this is question, then the relay module is called "5V Relay module"

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

    Send me code

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

      snag.gy/EG4O2l.jpg and snag.gy/AHhRpV.jpg

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

    Hii sir can u help us