Arduino Tutorial 34: Simplest Way to Use a Pushbutton Switch

Поделиться
HTML-код
  • Опубликовано: 30 июл 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
  • НаукаНаука

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

  • @apoorvaditya9010
    @apoorvaditya9010 4 года назад +29

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

  • @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!

  • @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 RUclips I can follow and understand, you teach in an excellent way.

  • @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.

  • @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

  • @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.

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

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

  • @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 10 месяцев назад

      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 3 месяца назад

      @@nobleforks8911 Can also use command INPUT_PULLUP

  • @olegvelichko1659
    @olegvelichko1659 4 года назад +30

    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!

  • @wouterbaptist8522
    @wouterbaptist8522 3 года назад +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!

  • @kuravani1963
    @kuravani1963 4 года назад +5

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

  • @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);
    }

  • @malcolmsnow4799
    @malcolmsnow4799 Год назад +1

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

  • @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.

  • @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

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

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

  • @thelocal911
    @thelocal911 Год назад +1

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

  • @autocrosser10
    @autocrosser10 5 месяцев назад

    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!

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

    Short but informative lesson. Thanks again Paul.

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

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

  • @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.

  • @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().

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

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

  • @andrewwilksch
    @andrewwilksch Год назад +1

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

  • @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

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

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

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

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

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

    Boom!! Thanks for another great tut, Paul.

  • @NothingToShoutAbout
    @NothingToShoutAbout 10 месяцев назад

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

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

    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)

  • @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!!

  • @billlaird7332
    @billlaird7332 10 месяцев назад

    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  10 месяцев назад

      Wonderful!

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

      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.

  • @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 😀😀😀😀

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

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

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

    Thanks for the hard work.

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

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

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

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

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

    Thanks for this tip to use the Pushbutton Switch.

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

    Bosco - Awesome series thank you very much!!

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

    Nice little corner cutting method. Thanks.

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

    great tip Paul, really simplifies the use of buttons!

  • @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!

  • @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 10 месяцев назад

      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.

  • @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.

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

    Awesome as always

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

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

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

    Paul, you are the best!!

  • @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);

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

    Thank you. This was cool!

  • @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 :-)

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

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

  • @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.

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

    This Tutorial is short but informative.

  • @handywijaya11
    @handywijaya11 8 месяцев назад

    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?

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

    Love Your Videos. Keep it UP!

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

    Thanks Paul.

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

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

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

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

  • @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.

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

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

  • @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.

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

    Another great tutorial! Practical method.

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

    Thank you very much Mr. Genius 😁

  • @samwain8713
    @samwain8713 6 месяцев назад

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

  • @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!

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

    Thanks, great tutorial :-)

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

    I do the exact same using the D0 pin in a NodeMCU8266 and the read is 1 at the begining, if press it, it goes to 0, but then if i release the button it stays at 0, why is that?

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

    When he says this is just a quick and dirty version what are the disadvantages of doing it this way? Does it damage the circuit in some way?

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

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

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

    like the tutorial, nice feature

  • @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.

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

    Paul, Where can I get the basic instruction of what the commands mean & the syntax that should be used when compiling a sketch. I'm always confused as to how you just know in what sequence to write your code without breaking stride. I'm always struggling to understand, what tells what to do what & why and what will the outcome of commands be? ?

  • @gilmertugahan
    @gilmertugahan 7 месяцев назад +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.

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

    Thank you very much!

  • @rupert310
    @rupert310 6 месяцев назад

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

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

    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)?

  • @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

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

    Great tip...thanks again!

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

    How does the Arduino Serial.x library work? How does it do the UART and printing?

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

    How do you take care of switch debouncing?

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

    Thank you very much best teacher in the world .

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

    Hi Paul, I had one doubt that what am I doing wrong if I write,
    pinMode(buttonPin,OUTPUT);
    Because the results are similar..

  • @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.

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

      thanks for the insight! less is more =)

  • @nexbedwars7408
    @nexbedwars7408 2 месяца назад

    Paul I am not able to fit my switch because the curved leads which are facing each other is lengthier than my breadboard itself(columnwise)!

  • @pouyanrouzbahani5419
    @pouyanrouzbahani5419 2 месяца назад

    5:58 We say pull_up next to the INPUT or this. Are there any differences?

  • @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...)

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

    This is cool, again!

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

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

  • @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!

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

    Can you use internal resistor as a pull-down?

  • @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

  • @DiMas-kt8jk
    @DiMas-kt8jk 6 месяцев назад

    is this trick will work with toggle switch?

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

    Can I pull the switchpin low internally????

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

    What is the Graphing command for serial Monitor?

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

    how to incorporate push button in infared thermal scanner project?

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

    Thank you

  • @thebrewsterblock
    @thebrewsterblock 4 месяца назад

    Another great video. Now I am a bit confused. I have used both this: "pinMode(buttonPin,INPUT);" as per your code or this: "pinMode(buttonPin,INPUT_PULLUP);" both with "digitalWrite(buttonPin,HIGH);". They both work. Don't know the syntax well enough. Is ",INPUT_PULLUP" assumed by just ",'INPUT"?

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

    Why can I not just put 5v on one side of the switch and connect the other side to pin 2 and make pin 2 an input?