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 Наука
Paul, your enthusiasm for electronics has made me a fan of you
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!
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.
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.
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
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.
I watched this video about 5 times, love it, please never stop Paul!
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.
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.
@@nobleforks8911 Can also use command INPUT_PULLUP
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!
I was literally thinking the same thing LOL
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!
Paul, Thanks for a nice simple understandable tutorial.....
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);
}
BOSC O - I've watched them all - can't wait till you get into interrupts and multitasking. Thanks Mal
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.
You did that in lesson 32 and I was wondering about doing a digitalWrite to an INPUT device. Now I know why. Thanks
I aim getting hooked on these tutorials Paul, really enjoying the series, thank you!
You made me learn pull up and pull down resisters knowing full well, all along, that this existed!?!? Well played, sir.
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!
Short but informative lesson. Thanks again Paul.
So much easier this way! And makes complete sense how it works now!! Thanks Paul!!
Am I the only one who binge watches these? Day 3 and I'm already at 34...
I am with you bro, day 4 and already at 34.
Indeed; playback speed at 2x, and ready to blaze all the way through in a week.
@@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
Day 3? can you say 2. ups, even tho ive started late yesterday.
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().
that answers my question from one of the previous videos. Thanks
A clever man. I'm learning as we go. Some is over my head but I'm getting there. Andy.
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
Great way to use internal components. Thank a again Paul.
This tutorial is very helpful for better understanding the 33rd tutorial.
Thank you for explaining briefly sir.
Boom!! Thanks for another great tut, Paul.
I’m so grateful for you. You are an amazing teacher.
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)
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!!
Fantastic!
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.
Wonderful!
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.
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 😀😀😀😀
Paul, This trick helps me greatly in my project. You are amazing...
Thanks for the hard work.
Once again, another great lesson! Simple but very useful. Thank You!!
Thanks again!
Your every video is very important to me to learn Arduino programming. Thank you.
Thanks for this tip to use the Pushbutton Switch.
Bosco - Awesome series thank you very much!!
Nice little corner cutting method. Thanks.
great tip Paul, really simplifies the use of buttons!
Glad you liked it
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!
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.
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.
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.
Awesome as always
thanks paul I'm so excited when Watch this lesson.
Paul, you are the best!!
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);
Thank you. This was cool!
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 :-)
NO SECRET WORD? Its ok Paul, your videos are amazing! Thanks for this tip, it makes push buttons so much easier to make!
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.
brilliant !
This Tutorial is short but informative.
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?
Love Your Videos. Keep it UP!
Glad you like them!
Thanks Paul.
i was going nuts trying to understand why this was done during the joystick code. now it makes sense.
Even without a secret word, Thanks a lot, Obrigado!
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.
Thank you sir, I learn a lot from you...make more and more video sir....
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.
Another great tutorial! Practical method.
Glad you liked it
Thank you very much Mr. Genius 😁
Bosco very cool method of checking if people are getting the most out of your videos
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!
Thanks, great tutorial :-)
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?
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?
Wow that is Sooo much easier. Thanks !!!!!! :-)
like the tutorial, nice feature
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.
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? ?
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.
Thank you very much!
tried it first on my own and got horrible feedback. Your method worked great. good tip.
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)?
I'm just curious is it possible to do this the other way around like "digitalWrite(buttonPin, LOW)", will this cause a short circuit?
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
Great tip...thanks again!
How does the Arduino Serial.x library work? How does it do the UART and printing?
How do you take care of switch debouncing?
Thank you very much best teacher in the world .
Hi Paul, I had one doubt that what am I doing wrong if I write,
pinMode(buttonPin,OUTPUT);
Because the results are similar..
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?
Yes - that is what I am doing too.
thanks for the insight! less is more =)
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)!
5:58 We say pull_up next to the INPUT or this. Are there any differences?
Very nice video. Is it possible to do a PULL-DOWN with just code?
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...)
This is cool, again!
Got it right first time around. Even remembered to set up the serial begin.
I feel smarter than shit!
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!
Can you use internal resistor as a pull-down?
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
is this trick will work with toggle switch?
Can I pull the switchpin low internally????
What is the Graphing command for serial Monitor?
how to incorporate push button in infared thermal scanner project?
Thank you
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"?
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?