How to Use a Button with an Arduino (Lesson #5)
HTML-код
- Опубликовано: 10 июл 2024
- Science Buddies Electronics Kit for Arduino: www.homesciencetools.com/prod...
Learn how to use a button as a digital input to an Arduino I/O pin with the digitalRead command. See our complete playlist of Arduino tutorials here: • How to Use an Arduino and the Science Buddies website for cool science projects you can do with an Arduino: www.sciencebuddies.org/search....
0:00 intro
0:23 materials
0:37 algorithm: pseudocode
1:31 algorithm: flowchart
2:22 build the circuit
8:29 connect a pull-down resistor
9:54 write the code
13:59 test your code
14:19 reverse button behavior
16:18 variables
20:40 up next
Science Buddies also hosts a library of instructions for over 1,500 other hands-on science projects, lesson plans, and fun activities for K-12 parents, students, and teachers! Visit us at www.sciencebuddies.org to learn more.
#STEM #sciencebuddies #arduino #electronics #programming
*******************************
Connect with Science Buddies:
TWITTER: / sciencebuddies
FACEBOOK: / sciencebuddies
INSTAGRAM: / scibuddy
PINTEREST: / sciencebuddies
You have no idea how much you have taught me, thank you brother.
I love the way you explain stuff.
May God bless you.
A brilliant explanation. I was reading a book where I had a similar project with a button and a capacitor. I couldn't implement it properly, and this video helped me a lot!
You explained very well! thank you so much!
Your vidios in the ardiuno series are amazing.Keep it up bro
This is amazing! Thank you!
Amazing explanation
Bro you explain the best. 👍👍👍
i love your videos
☺
how did we know if we connect the LED, at the PIN + or a the - one ? Does it will change something ? Or the voltage juste will be inversed ?
We recommend watching our video about LEDs before this one, it may answer your questions: ruclips.net/video/FKekzzj5844/видео.htmlsi=VWlZPUgTYETmyjXP
what do i need to edit in order to replace the led with variables?
If you watch to the end of the video (starting around 16:20) we cover using variables in the code.
How is it when pushing the buttons to stay on/off? Im having a science project where i need an arduino to control the temperature of my desired heat/cold. Please respond...
Hi - if you search online for "Arduino button toggle" you should find example code that lets you push to toggle the button instead of holding it down. You can also look at our list of tutorials and use a slide switch instead of a button.
Hello and thank you very much for the great video. Nevertheless I have a question: why do I have to connect the button anyway to the ground. When I don’t push the button, there is no current flow and the input to the PIN is low. Why is the connection to the ground necessary?
Than you
The connection to ground is needed so the input pin voltage is never "floating" or undetermined. This way it is always either 0V or 5V. If the pin is not connected to anything then it can be affected by electrical noise from other things in the circuit and nearby pins.
Thank you very much
thank uu
Suggest another videos with pushbuttons: what about pushing for stay on/off, press short and long, press x times to do this and y times to do that in 5 seconds, ....
Thanks for the suggestion! We will be adding more Arduino tutorials in the future, stay tuned!
I made it so when pressed green led goes on when not pressed red led goes on
How?
@@micahbentley2233 you use the scripts from first in the if statement and make one go high if pressed and one go low then in the else you make on go low and one go high
me too😀
nvm, you can make this with no arduino, just a relay. how did I do that?
change line: (digitalRead(button_Pin)==LOW) on this one (digitalRead(button_Pin)==HIGH) - will be ok now.
Hello i have a question, how come does my LED is turned on even, i haven't pushed the button, while if i pushed the button, it just glows brighter? i just followed the commands
TYIA!
You may have the pin set as an input instead of an output - double check that your code AND your circuit follow what is shown in the video.
What will happen if place the switch on one side?
And if we place switch in such a way that the legs are placed on two side.how it gets current or voltage to all legs since the two sides are separated by a plastic? insulator?
im pretty sure its because the button takes up a lot of space on one side which doesnt allow us to use more wires in the same row(like when he used the resistor and jumper in the same row for the button)
I have a question. Can I just make the button let the electricity flow between the LED and the GND-bus? It wouldn't need as much code
Hi - if all you want to do is turn on an LED when you hold the button down, then you do not need an Arduino at all. An Arduino allows you to program more complicated behaviors, user other sensors, and control outputs like motors. You can find more information in the Arduino playlist linked in the video description.
im not sure if this is right but it worked for me insted of == i put a single - and it does the same this.
== is called a "comparison operator" and a single = is called an "assignment operator" - you can learn more about this in the Arduino language reference: www.arduino.cc/reference/en/
In my exam I’m gonna have to use 9 buttons and a display I don’t have enough pin mode what do I do ?
Hi - you may have more luck asking this question on the official Arduino forums.
gee I wish when people write the code, they make it bigger to be able to see the code.
It worked in tinkercard but it didn't work in real life
Couldnt you just use the button as an circuit breaker instead of using code? Seems simpler but the code one is cooler
Yes, if all you want is on/off control of a single LED using a button, then technically you do not need the Arduino at all, but if you want to do anything more complicated (like making multiple LEDs flash in a pattern when you push a button once) then it becomes much easier to do with code.
@@Science.Buddies Yeah, that's true. Even through, you might be able to do it with like logic Gates or relais
Right - you can hard-wire plenty of interesting circuit behaviors without any code at all. For example, check out the "Bluebot" series of projects on our site, which have both Arduino and non-Arduino versions. The non-Arduino versions can do basic left-right steering using different sensor inputs despite not having any microcontroller: www.sciencebuddies.org/science-fair-projects/science-projects?s=bluebot
It doesn't work
Same for me
it works on the tinkercad sim, but on the board it doesn't. I debugged it but still nothing
Check the other vid about debugging arduino in this playlist
I dont have a PC 😡
You can also program an Arduino from a Mac! See the software options here: www.arduino.cc/en/software
I copied the code and it won't compile. This is bullshit!
but if arduino output is only 250mamps, what's the point to use all these resistors, currrent is limited, and the board is suppose has a resistor to stop overflow of current back to the pin? i've tried without resistors, nothing bad happens, the board is still working.
why the 10kohms resistor??
i'm sorry i followed the video, i got the explanation, not to short the 5v to the pin with a 10k resistor.