Arduino Tutorial 34: Simplest Way to Use a Pushbutton Switch

แชร์
ฝัง
  • เผยแพร่เมื่อ 23 พ.ค. 2024
  • You guys can help me out over at Patreon, and that will help me keep my gear updated, and help me keep this quality content coming:
    / paulmcwhorter
    In this lesson we show you a simply hack that will allow you to utilize a pushbutton switch on the arduino without using an external pull up resistor. Works like a charm and is simple to implement.
    You can get the kit I am using for this series at the following link:
    amzn.to/2I7N4Ek
    Follow these lessons on our WEB site:
    toptechboy.com/arduino-tutori...
    [Disclosure of Material Connection: I am a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to amazon.com. This means if you visit the link and purchase the item, I will receive an affiliate commission. Regardless, I only recommend products or services I use personally and believe will add value to my readers.]
    #Arduino
  • วิทยาศาสตร์และเทคโนโลยี

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

  • @apoorvaditya9010
    @apoorvaditya9010 4 ปีที่แล้ว +27

    Paul, your enthusiasm for electronics has made me a fan of you

  • @olegvelichko1659
    @olegvelichko1659 4 ปีที่แล้ว +29

    ButtPin... BWAHAHAHAHA!!! Got a good giggle out of that one! Hey, doing a whole video in one shot takes skill! Thank you, sir, for the great content. When’s my next fix coming? This was too little of a dose!

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

    You made me learn pull up and pull down resisters knowing full well, all along, that this existed!?!? Well played, sir.

  • @mightythimble4942
    @mightythimble4942 4 ปีที่แล้ว +9

    No secret word?? Have you gone MAD?? lol this video filled in a very important piece of the puzzle for a project I've been building. Many thanx, Paul! Would love to see a tutorial on shift registers with the kind of detail you put into videos. It's been an real treat to keep up with these.

  • @TheSgrizli
    @TheSgrizli 3 ปีที่แล้ว +14

    Am I the only one who binge watches these? Day 3 and I'm already at 34...

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

      I am with you bro, day 4 and already at 34.

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

      Indeed; playback speed at 2x, and ready to blaze all the way through in a week.

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

      @@WhirlwindCK 1.5 here, so I can write notes ^.^ Can't wait til I know it all and can start on my project for real

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

      Day 3? can you say 2. ups, even tho ive started late yesterday.

  • @SamFromSpaceOfficial
    @SamFromSpaceOfficial 2 ปีที่แล้ว +17

    Mr. Paul, your tutorials have really helped me to understand and learn Arduino. Your teaching style is like no other. Please keep posting Arduino tutorials!

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

    I watched this video about 5 times, love it, please never stop Paul!

  • @daveharkin4731
    @daveharkin4731 4 ปีที่แล้ว +9

    thank you Paul for your time and effort you put into these videos, I really appreciate them. Please keep them coming. When you get the time could you do a video about interrupts and switch, case programming. you seem to be the only person on TH-cam I can follow and understand, you teach in an excellent way.

  • @kuravani1963
    @kuravani1963 4 ปีที่แล้ว +5

    Paul, Thanks for a nice simple understandable tutorial.....

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

    Short but informative lesson. Thanks again Paul.

  • @wouterbaptist8522
    @wouterbaptist8522 2 ปีที่แล้ว +4

    I always prefer to have the value read "0" when the button is not pressed and "1" when it is pressed so I tried connecting the button to 5V and pin 2 and to write "LOW" to pin 1 to see if that would work as a pull down resistor. And it did :)
    Thanks for this neat trick Paul!

  • @philnewman1110
    @philnewman1110 11 หลายเดือนก่อน

    I aim getting hooked on these tutorials Paul, really enjoying the series, thank you!

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

    BOSC O - I've watched them all - can't wait till you get into interrupts and multitasking. Thanks Mal

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

    Thanks, You used this with brief explanation in previous, without mentioning the internal pull up resistor. Much clearer now as to what is going on.

  • @MarvPerk3
    @MarvPerk3 3 ปีที่แล้ว +7

    Halfway Home... lesson 34 of 68! Loving learning new tech at my age, 70. Loving coding again, which I did a bunch before I retired. I still don't quite understand how a pull up resistor is introduced by setting an input pin to HIGH... but I'll go back and watch again. That confused me in the last lesson, too, no fault of yours.

    • @nobleforks8911
      @nobleforks8911 8 หลายเดือนก่อน

      Its the same idea as putting the resistor to +5VDC, when the button is pushed it creates a path to ground so pulls the pin low by creating a low impendence circuit to ground.

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

      @@nobleforks8911 Can also use command INPUT_PULLUP

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

    Nice little corner cutting method. Thanks.

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

    BOSCO, Hi Paul, this is the second time I've followed these tutorials and got to this point. First time stopped due to work commitments, this time determined to see it through until the end.
    Very new to coding and electronics, but learning all the time. Thanks

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

    This tutorial is very helpful for better understanding the 33rd tutorial.
    Thank you for explaining briefly sir.

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

    So much easier this way! And makes complete sense how it works now!! Thanks Paul!!

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

    I just finished tutorial 34. I am writing the code for your projects before watching you do it. Thanks for doing these videos. I will utilize an Arduino to control an arcade shooting gallery that was made in 1969. When manufactured, the game was controlled by a custom 8 track tape player. I have been unable to get the tape player to function reliably so I will have an Arduino take over the game control. This shooting gallery was been rescued from the trash and completely restored. An Arduino will allow me to finish this restoration. Your tutorials enable this to happen.

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

    A clever man. I'm learning as we go. Some is over my head but I'm getting there. Andy.

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

    You did that in lesson 32 and I was wondering about doing a digitalWrite to an INPUT device. Now I know why. Thanks

  • @NothingToShoutAbout
    @NothingToShoutAbout 8 หลายเดือนก่อน

    I’m so grateful for you. You are an amazing teacher.

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

    Paul, This trick helps me greatly in my project. You are amazing...

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

    Great way to use internal components. Thank a again Paul.

  • @autocrosser10
    @autocrosser10 3 หลายเดือนก่อน

    Watched this one prior to lesson 32. I think it helped to do this before you taught us how to use the joystick.
    Half way done with the new lessons and I'm still here watching to the end and doing all the math. Your doing something right!

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

    that answers my question from one of the previous videos. Thanks

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

    Thank you Mr. McWorther, I love this, now it's much easier for me to create pull up switches, also I decided to do a bit of neat formatting, so I added two if functions to say wether my button is on or off in the serial monitor. Here is the code.
    int buttonPin=12;
    int buttonVal;
    int dt =100;
    void setup() {
    // put your setup code here, to run once:
    Serial.begin(9600);
    pinMode(buttonPin,INPUT);
    digitalWrite(buttonPin,HIGH);
    }
    void loop() {
    // put your main code here, to run repeatedly:
    buttonVal=digitalRead(buttonPin);
    Serial.print("Your button is");
    if(buttonVal==1){
    Serial.println(" off");
    }
    if(buttonVal==0){
    Serial.println(" on");
    }
    delay(dt);
    }

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

    I've played with Arduino for ~1 year. This video is THE MOST IMPORTANT lesson that I've learned. YES, external pull-up resistors are OLD SCHOOL!!! (yet everyone continues to use them)

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

    Thank you for this tip Sir Paul!
    I have to agree with the earlier comments, that using the parameter INPUT_PULLUP
    seems more natural and intuitive as it eliminates the need to write digitalWrite inside the void setup().

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

    Boom!! Thanks for another great tut, Paul.

  • @gilmertugahan
    @gilmertugahan 5 หลายเดือนก่อน +1

    The new IDE already has an INPUT_PULLUP feature. I think the IDE you were using doesn't support that. But, it's good to know that it can still work by doing a digitalWrite. It is useful for me because most Arduino micros I've bought doesn't support the new IDE. Thanks so much Sir.

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

    Your every video is very important to me to learn Arduino programming. Thank you.

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

    As far as I know instead of using 2 lines of code for making that pull-up resistor you can use 1 line of coffee that is pinMode(buttonPin, INPUT_PULLUP);

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

    Thanks for this tip to use the Pushbutton Switch.

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

    i cant believe that this actually works. thx for showing me this trick and love the tutorials i have learned a lot from you. thank you

  • @samwain8713
    @samwain8713 3 หลายเดือนก่อน

    Bosco very cool method of checking if people are getting the most out of your videos

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

    great tip Paul, really simplifies the use of buttons!

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

    Once again, another great lesson! Simple but very useful. Thank You!!

  • @michaelw24401
    @michaelw24401 3 ปีที่แล้ว +12

    Hardware pull-up or pull-down resistors, this method and INPUT_PULLUP; we have options. I like the idea of using the Arduino internal pull-up because of it's simplicity but I wonder in what applications hard-wired PU resistors may be to our advantage.

    • @nobleforks8911
      @nobleforks8911 8 หลายเดือนก่อน

      Less work for the MCU, INPUT_PULLUP or setting the same pin as INPUT and HIGH at the same time utilizes the limited power output of the board. This is the reason to use resistors; resistors just get rid of stray current(could be generated by as simple as your fingers close to the button or stray EMF in the air) to be grounded.

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

    That saves some Dupont wires and resistor, very cool indead, we used this trick already for the Joystick push button if i am not mistaking 😀😀😀😀

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

    thanks paul I'm so excited when Watch this lesson.

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

    Epic video Paul! Been testing it out by making a program to let program be run once with 1 click. Having a blast with it! Thanks for your inspiration!!

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

    Bosco - Awesome series thank you very much!!

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

    Got it right first time around. Even remembered to set up the serial begin.
    I feel smarter than shit!

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

    Paul, you are the best!!

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

    Thanks for the hard work.

  • @billlaird7332
    @billlaird7332 8 หลายเดือนก่อน

    I have become addicted to this series and particularly your teaching style. I understand that you went through the whole push button using pull up and pull down resistors in lesson 33 so that we understood the theory. I really like how you integrate the hardware, software, and physics. I am already looking forward to your raspberry pi series after I finish the arduino.

    • @paulmcwhorter
      @paulmcwhorter  8 หลายเดือนก่อน

      Wonderful!

    • @eparizi
      @eparizi 4 หลายเดือนก่อน

      am I missing something in lesson 33 or you meant lesson 27? I don't see anything about buttons in 33. And I still don't understand why this method works. so far this has been the lesson I struggled most with.

  • @rupert310
    @rupert310 4 หลายเดือนก่อน

    tried it first on my own and got horrible feedback. Your method worked great. good tip.

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

    This Tutorial is short but informative.

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

    Hello Sir, I really love your lessons but would love it and wish we could do advanced stuff like in your first tutorial. I am sure many people would like this as well.

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

    Paul, your videos are absolutely amazing! Thank you sooo much, I have learned gobs. Have you ever made a video where a single button has multiple possible outputs based on how many times the button has been pressed? I am in need of a circuit that reads how many times a single button has been pressed (up to 3 consecutive times) and based on that input performs one of three different functions. Thanks Paul!

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

    Thank you. This was cool!

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

    Awesome as always

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

    i was going nuts trying to understand why this was done during the joystick code. now it makes sense.

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

    Love Your Videos. Keep it UP!

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

    Another great tutorial! Practical method.

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

    I love it that you have to fiddle with the PCB microswitch the same why I do. It seems that they only work marginally well with breadboards.

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

    Boom, I also programmed internal LED (pin 13) as an indicator to show switch status (saving having to wire external LED/resistor). Works a treat :-)

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

    Thanks Paul.

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

    NO SECRET WORD? Its ok Paul, your videos are amazing! Thanks for this tip, it makes push buttons so much easier to make!

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

    Thank you sir, I learn a lot from you...make more and more video sir....

  • @alirezabayat6388
    @alirezabayat6388 2 หลายเดือนก่อน

    hey mr. McWhorter, glad you're still reading comments and before anything i want to thank you for this series, you're an excellent teacher. i have ran into a problem with this technique, if i don't use a resistor and don't do the "original" way of wiring a button, the button value goes up and down by itself and ignores my input. same thing happened with tilt sensor which i fixed it by using a pull up/down resistor. do you have any idea what's going on? i guess it's worth mentioning that i'm using a no-name brand UNO R3, which seems to be working fine everywhere else!

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

    No WORD? Please, say hi to Bosco and pet Indigo for me anyway. This was a short and clear lesson, I feel like things are really starting to click now. Thank you once again!

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

    Thank you very much best teacher in the world .

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

    Great video, maybe Bosco should sell coffee and call it Indigo. :)

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

    Paul,
    Thank you for showing us this trick. This was a great video. I just had two quick follow-up questions.
    1) Why the heck do we even use pull-up resistors at all? Is it that this trick just isn't known or is it that there are stability issues. Because I noticed you mentioned theoretically that it was stable.
    2) Is the internal pull-up resistor internal to the ATMega328P chip or internal to the surrounding circuitry on the Arduino board?
    I ask because I use the standalone ATMega328P circuitry in a project with a push-button wired up to it. Being able to eliminate a component/installation step with a few lines of code would be great.
    Granted after watching your series I am considering replacing the pushbutton with a potentiometer to give me finer control on my program.

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

    Wow...this is a great hack for simplifying the pull up resistor switch scenario. That's three ways I've learnt now...(1) Using the actual external resistor set up...(2) Using this excellent method...........and (3) using the pinMode(buttonPin,INPUT_PULLUP) method. Like the old saying goes..."There's more than one way to skin a cat." I would think that it's real handy to know all three...and there are probably others out there too; I'm sure that given a certain situation, at a more advanced level, each method could come in useful, having that little advantage over the other in that particular application. Thanks again, Paul. Stay safe, mate....and best wishes and regards to yourself and family. Cheers....Grumpy LImey.

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

    Even without a secret word, Thanks a lot, Obrigado!

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

    Thank you

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

    Once again, a wonderful/informative video!!
    Question, I have been playing with interrupts (both HW & SW) and wonder if this simple way would work with that - so that when you press the button, the interrupt would trigger.
    Thanks!

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

    Thank you very much Mr. Genius 😁

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

    Thank you very much!

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

    Thanks, great tutorial :-)

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

    Wow that is Sooo much easier. Thanks !!!!!! :-)

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

    Great tip...thanks again!

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

    like the tutorial, nice feature

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

    present, thank you

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

    This is cool, again!

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

    Hi Paul, I've been watching a few tutorials to help me understand this concept better and I thought I did until I watched this... Does your method without any resistor not short out the supply with ground?

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

    Paul, you anticipated my question about asking why you could do this in the previous videos for the joystick switch. If I correctly understand, the pin2 output driver impedence replaces the 330 Ohm pullup resistor? No reliablity problems in shorting the IC outputs? Thanx.

  • @fahimabrar8141
    @fahimabrar8141 9 หลายเดือนก่อน

    Just realized I am half way through!

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

    Fantastic sir 👌👌😊.

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

    Hej Paul
    My first comment : Bosco.
    Thanks fo a good step by step course and present looking to start #35.
    Regards

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

    Much Nicer. Thanks.

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

    Hi Paul! I really enjoyed and having a lot of fun with all of your videos. I was wondering if you can make a video of connecting or integrating esp8266 12e module with arduino uno and connecting it with amazon Alexa. Many thanks and more power to you!

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

    very nice!

  • @handywijaya11
    @handywijaya11 5 หลายเดือนก่อน

    Hi Paul,good job. I put a marker at the end of program that on and off the internal led. Sometime my servo get hang while running for a while,and so that the internal led not blink anymore.Any suggest?

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

    Very nice video. Is it possible to do a PULL-DOWN with just code?

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

    Paul, why did you choose to use :
    pinMode(buttonPin, INPUT);
    digitalWrite(buttonPin, HIGH);
    as opposed to.
    pinMode(buttonPin, INPUT_PULLUP);
    to set the internal pull-up resistors? (yes, both do the same thing as others have noticed...)

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

    nice arduino tutorials Mr. Paul, please I need your advise in a project, if I want to make a drone using NRF24 what I need to know in the arduino software?
    thank you

  • @jonwebb5395
    @jonwebb5395 2 ปีที่แล้ว +9

    I am in the process of learning how to use Arduino board and love these tutorials. However, while watching this tutorial and reading through the Arduino instructions, it appears there may be a simpler way to write this but I am not sure if it applies here. Instead of instantiating the pinMode as INPUT, can we instead instantiate it as INPUT_PULLUP and then get rid of the need for the digitalWrite(buttonPin, HIGH) line?

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

      Yes - that is what I am doing too.

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

      thanks for the insight! less is more =)

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

    BOSCO! Love your tutorials! I recently discovered the 'map' function -might have been useful in this application? :) Ciao!

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

    So, when building a project, is this method better than the other method? Also, would this work with the smaller Arduinos (nano, pro mini, etc)?

  • @Matthew-lp4vr
    @Matthew-lp4vr ปีที่แล้ว

    Thanks!

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

      Thanks, I really appreciate that!

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

    Made to Bosco and I am also mounting a laser that will be turn on with the joystick.

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

    I believe the Arduino site someone mentioned that an internal app. 30k resistance is used.
    This should prevent arcing switch contacts. Probably the shortest lesson.

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

    thanks again :)

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

    I'm just curious is it possible to do this the other way around like "digitalWrite(buttonPin, LOW)", will this cause a short circuit?

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

    Hi Paul I have an 8 digit 7 segment display with the Max 7219 chip. I want to make it show scoring points on a pinball machine using an arduino Nano or Uno.
    Not sure if you have something already on one of your videos would require push buttons to change the score preferably one to change ones, another to change tens and another for one hundreds?
    Any help would be appreciated Maybe even a good course to do if not already
    Regards
    Pb