How to Use a Button with an Arduino (Lesson #5)

  Рет қаралды 118,034

Science Buddies

Science Buddies

Күн бұрын

Пікірлер: 106
@casual2531
@casual2531 9 ай бұрын
You have no idea how much you have taught me, thank you brother. I love the way you explain stuff. May God bless you.
@sigmasigma11000
@sigmasigma11000 15 күн бұрын
eik nx lohas krw uzpisi nx zajibala esi
@davehasak
@davehasak Ай бұрын
I'm a part-time engineering instructor, and I'm learning this partially for fun, and partially because I might teach it some day. This is GREAT instruction! Thank you so much.
@azatturegeldin4716
@azatturegeldin4716 10 ай бұрын
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!
@Livy2964
@Livy2964 20 сағат бұрын
You are the best teacher ever
@eternitysf3413
@eternitysf3413 10 ай бұрын
You explained very well! thank you so much!
@aaronjeffery7123
@aaronjeffery7123 9 ай бұрын
Your vidios in the ardiuno series are amazing.Keep it up bro
@TehnoVito
@TehnoVito 6 ай бұрын
Great video! All your explanations are slow and matcable. Great job!
@elisedossin6949
@elisedossin6949 Ай бұрын
Man this is great stuff
@AayushGupta-uj6hx
@AayushGupta-uj6hx 7 ай бұрын
Bro you explain the best. 👍👍👍
@savithachess1109
@savithachess1109 2 ай бұрын
Great work!
@BlobGod
@BlobGod 2 ай бұрын
Code for people who dont wanna write it void setup () { pinMode(12, OUTPUT) pinMode(2, INPUT) } void loop () { if (digitalRead(2) == HIGH) { digitalWrite(12, HIGH) ; } else{ digitalWrite(12, LOW) ; } }
@Alizxer
@Alizxer Ай бұрын
for anyone who copied this and got a error, make sure to add a semi-colon at the end of each command under void setup. exa: void setup () { pinMode(12, OUTPUT); pinMode(2,INPUT); }
@CaffineAndCode
@CaffineAndCode Жыл бұрын
Amazing explanation
@trivender007
@trivender007 10 күн бұрын
Which camera you use for recording.
@ArzenikDev
@ArzenikDev Жыл бұрын
I made it so when pressed green led goes on when not pressed red led goes on
@micahbentley141
@micahbentley141 Жыл бұрын
How?
@ArzenikDev
@ArzenikDev Жыл бұрын
@@micahbentley141 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
@kushalm7328
@kushalm7328 Жыл бұрын
me too😀
@micahbentley141
@micahbentley141 Жыл бұрын
nvm, you can make this with no arduino, just a relay. how did I do that?
@tomekpro2918
@tomekpro2918 Жыл бұрын
change line: (digitalRead(button_Pin)==LOW) on this one (digitalRead(button_Pin)==HIGH) - will be ok now.
@ran_ramirez
@ran_ramirez 10 ай бұрын
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!
@Science.Buddies
@Science.Buddies 10 ай бұрын
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.
@Studs_Studio
@Studs_Studio 2 ай бұрын
@@Science.Buddies i copied the code and i have the same problem. everything looks like it should work but it still does that. once in a while the led turns off for a second but rarely
@Studs_Studio
@Studs_Studio 2 ай бұрын
sorry nevermind. i didnt connect it properly.
@daveluvs3dprinters
@daveluvs3dprinters 11 ай бұрын
i love your videos ☺
@spurfy8392
@spurfy8392 11 ай бұрын
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 ?
@Science.Buddies
@Science.Buddies 11 ай бұрын
We recommend watching our video about LEDs before this one, it may answer your questions: kzbin.info/www/bejne/fHzInK2wn5prapYsi=VWlZPUgTYETmyjXP
@farbodkeyhanloo906
@farbodkeyhanloo906 Жыл бұрын
This is amazing! Thank you!
@Orcanian66
@Orcanian66 6 ай бұрын
Great instruction thanks for sharing.
@cvolii1377
@cvolii1377 14 күн бұрын
hey, first of all, thanks dude. But can you maybe explain the system with the 10K resister? I didnt get get you said.
@Science.Buddies
@Science.Buddies 14 күн бұрын
We recommend looking up a more detailed tutorial on pull up and pull down resistors, this is more than we can explain in a KZbin comment if you want to know more.
@cvolii1377
@cvolii1377 13 күн бұрын
@@Science.Buddies alright, thanks
@cvolii1377
@cvolii1377 13 күн бұрын
hey its me again. is it possible to use resistors to connect the leds short head to the ground or must i use a jumperwire?
@Science.Buddies
@Science.Buddies 13 күн бұрын
This video might help answer your question: kzbin.info/www/bejne/hIaudWyneriCa5osi=HP9vrJaHQel0FeXs
@ziggyzoggin
@ziggyzoggin Ай бұрын
Great video. the code is needlessly complex though, as you could simplify it to "digitalWrite(led_pin, digitalRead(button_pin));" and I think that's just as readable. though if you add more logic, you do have to make it an if statement. I understand the video is more about teaching programming than actual programming, but I just thought to mention it.
@harishanth.r732
@harishanth.r732 10 ай бұрын
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?
@thatphysicsguy7859
@thatphysicsguy7859 10 ай бұрын
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)
@G18-ROQUEPRECIOUSZOEA.
@G18-ROQUEPRECIOUSZOEA. 11 ай бұрын
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...
@Science.Buddies
@Science.Buddies 11 ай бұрын
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.
@Nottm_e
@Nottm_e 7 күн бұрын
Your video is very informative... can you share the code for this project...
@Lucky_Trucky
@Lucky_Trucky 2 жыл бұрын
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, ....
@Science.Buddies
@Science.Buddies 2 жыл бұрын
Thanks for the suggestion! We will be adding more Arduino tutorials in the future, stay tuned!
@SyntaxError-2505
@SyntaxError-2505 9 ай бұрын
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
@Science.Buddies
@Science.Buddies 9 ай бұрын
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.
@leonardohamdany1123
@leonardohamdany1123 24 күн бұрын
thankyou brother
@amirarab254
@amirarab254 9 ай бұрын
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
@Science.Buddies
@Science.Buddies 9 ай бұрын
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.
@amirarab254
@amirarab254 9 ай бұрын
Thank you very much
@stevenjenkins947
@stevenjenkins947 2 ай бұрын
​@@Science.Buddiescould you exclude the resistor and just write your code to only be looking for voltage greater than 4? That way if there is a small current leakage it won't cause the led to turn on?
@brewski425castleclash
@brewski425castleclash 3 ай бұрын
i have watched 3 hours of videos arduinos. yours finally answered my dumb questions. tdlr. a button needs a 5v and and the connection to the pcv. AND it needs a very high resistor to ground or else it short circuits shit. bruh and electricity reads from a ~E. left to right.
@CobraG001
@CobraG001 2 ай бұрын
could you pls tell me why that high resistor is used?(i am an absolute beginner with Arduino so i dont know any terms)
@brewski425castleclash
@brewski425castleclash 2 ай бұрын
You still need to complete the circuit but there are random amkunts of tiny current going through due to inperfections. The higj resistor makes sure that off means off. Even the slightest current is supposed to turn the button on. Its just good practice ​@CobraG001
@satoo2768
@satoo2768 3 ай бұрын
What if want to add a delay in the code, imagine,i want to press the buttom then wait 1 second and the led turns on. But if i keep pressing the button, the led has to turn off until i released the finger and then pressing it again during one sec
@Studs_Studio
@Studs_Studio 2 ай бұрын
use delay(miliseconds) before one of the digitalWrites i think
@behem05
@behem05 Жыл бұрын
what do i need to edit in order to replace the led with variables?
@Science.Buddies
@Science.Buddies Жыл бұрын
If you watch to the end of the video (starting around 16:20) we cover using variables in the code.
@kiwi-ne2cg
@kiwi-ne2cg 23 күн бұрын
i dont know what went wrong here, but the lightbulb only lights up when the "green" wire is lifted up...
@mila-ko3036
@mila-ko3036 4 ай бұрын
Does it work with Mega 2560? (it is unofficial Arduino, but almost the same)
@sentakatsuki
@sentakatsuki Ай бұрын
yes
@SgtDangerWaffles
@SgtDangerWaffles 9 ай бұрын
im not sure if this is right but it worked for me insted of == i put a single - and it does the same this.
@Science.Buddies
@Science.Buddies 9 ай бұрын
== 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/
@marvelqueen52
@marvelqueen52 8 ай бұрын
It worked in tinkercard but it didn't work in real life
@tutorialtime403
@tutorialtime403 6 ай бұрын
Did you find a way to fix it?
@just_sayin8208
@just_sayin8208 5 ай бұрын
I looked through the code and he forgot to add the "if (digitalRead(2) == HIGH)
@justin.420
@justin.420 4 ай бұрын
First step is to get a life
@ChaksFM
@ChaksFM 4 ай бұрын
​@@justin.420piss off
@farham565
@farham565 2 ай бұрын
​@@justin.420 Get lost bro ppl actually make money with this shi u need to get a life and learn something
@voscapattern
@voscapattern 8 ай бұрын
thank uu
@mila-ko3036
@mila-ko3036 4 ай бұрын
The code he showed in the video doesn't work for me for some reason, but here is working code for anyone like me: // C++ code // void setup() { pinMode(12,OUTPUT); pinMode(2,INPUT); } void loop() { if(digitalRead(2) == HIGH) digitalWrite(12,HIGH); else digitalWrite(12,LOW); }
@fredcormier9149
@fredcormier9149 7 күн бұрын
you literally saved our lives in class thank you we were going to fail
@ИгорьБакуринский
@ИгорьБакуринский 5 ай бұрын
This code doesnt work. .....could not convert 'digitalWrite(12, 1)' from 'void' to 'bool. How to FIX????
@voxelcatt
@voxelcatt 4 ай бұрын
its digitalWrite(12, HIGH)
@veniaminvigovsky
@veniaminvigovsky 8 күн бұрын
unfortunately it doesn't work for me for some reason, I doublechecked everything connection-wise, but it doesn't work. The LED just blinks from time to time, I don't know what's wrong... maybe the button is wrong, idk..
@veniaminvigovsky
@veniaminvigovsky 8 күн бұрын
the LED turns on even without 5v cabel connection
@veniaminvigovsky
@veniaminvigovsky 8 күн бұрын
ok so the prblem was that my button was connected to a separate power bus
@rrssmooth6643
@rrssmooth6643 11 ай бұрын
gee I wish when people write the code, they make it bigger to be able to see the code.
@Ra6771YT
@Ra6771YT 19 күн бұрын
14:21
@__KursK__
@__KursK__ 9 ай бұрын
Couldnt you just use the button as an circuit breaker instead of using code? Seems simpler but the code one is cooler
@Science.Buddies
@Science.Buddies 9 ай бұрын
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.
@__KursK__
@__KursK__ 9 ай бұрын
@@Science.Buddies Yeah, that's true. Even through, you might be able to do it with like logic Gates or relais
@Science.Buddies
@Science.Buddies 9 ай бұрын
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
@coreyworthington8786
@coreyworthington8786 6 ай бұрын
It’s not working for me
@sandipkr.sarkar5813
@sandipkr.sarkar5813 4 ай бұрын
Why you need Arduino for this
@junixec
@junixec 3 ай бұрын
It's not that you need Arduino for that but Arduino can do a lot of stuff including that, you can use a push button to light a bulb, nothing more, nothing less, but in Arduino you may use the same push button to trigger an event like turns your bulb on and off with just one button press which a regular push button cannot do unless you push it on and off continuously. You may also use the same push button with Arduino to dim your Led or Brighten your Led which a regular push button cannot do. I hope this helps.
@N1ghtR1der666
@N1ghtR1der666 25 күн бұрын
I know I am in a minority here but I have never understood why people would want to learn another language to make a program (sudo code) when the languages are mostly in plane english anyway, I find sudo code much harder to write than actual code
@sen8078
@sen8078 5 ай бұрын
why this button so big lmao goofy aah button
@Studs_Studio
@Studs_Studio 2 ай бұрын
Youve never seen a slightly larger button before?
@RJkatztabby
@RJkatztabby 7 ай бұрын
I copied the code and it won't compile. This is bullshit!
@tutorialtime403
@tutorialtime403 6 ай бұрын
Did you find a way to fix it?
@Book9999-x4z
@Book9999-x4z 11 ай бұрын
It doesn't work
@123nody
@123nody 11 ай бұрын
Same for me
@123nody
@123nody 11 ай бұрын
it works on the tinkercad sim, but on the board it doesn't. I debugged it but still nothing
@sadhgunavarshinie7281
@sadhgunavarshinie7281 10 ай бұрын
Check the other vid about debugging arduino in this playlist
@IplayGames24seven
@IplayGames24seven 9 ай бұрын
I dont have a PC 😡
@Science.Buddies
@Science.Buddies 9 ай бұрын
You can also program an Arduino from a Mac! See the software options here: www.arduino.cc/en/software
@bimbo-yw6ny
@bimbo-yw6ny 7 ай бұрын
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.
@bimbo-yw6ny
@bimbo-yw6ny 7 ай бұрын
why the 10kohms resistor??
@bimbo-yw6ny
@bimbo-yw6ny 7 ай бұрын
i'm sorry i followed the video, i got the explanation, not to short the 5v to the pin with a 10k resistor.
@CobraG001
@CobraG001 2 ай бұрын
pls explain in detail
How to Fade an LED with Arduino analogWrite (Lesson #6)
11:13
Science Buddies
Рет қаралды 47 М.
BAYGUYSTAN | 1 СЕРИЯ | bayGUYS
36:55
bayGUYS
Рет қаралды 1,9 МЛН
Quilt Challenge, No Skills, Just Luck#Funnyfamily #Partygames #Funny
00:32
Family Games Media
Рет қаралды 55 МЛН
Sigma Kid Mistake #funny #sigma
00:17
CRAZY GREAPA
Рет қаралды 30 МЛН
New Genius Ways To Use a Drill
4:21
AN Creative
Рет қаралды 3
How to Program a Push Button with an Arduino
9:45
Robot Research Lab
Рет қаралды 91 М.
How to Use a Potentiometer with Arduino analogRead (Lesson #7)
11:52
Science Buddies
Рет қаралды 62 М.
How to make a simple led traffic light circuit
3:56
Project AA
Рет қаралды 20 М.
How to Blink an LED with Arduino (Lesson #2)
15:57
Science Buddies
Рет қаралды 153 М.
How to use Pushbuttons with Arduino. Pull up vs Pull down resistors
10:36
Arduino Tutorial 28: Using a Pushbutton as a Toggle Switch
21:58
Paul McWhorter
Рет қаралды 302 М.
Make a TINY Arduino Drone with FPV Camera - Will It Fly?
20:26
Max Imagination
Рет қаралды 1,6 МЛН
BAYGUYSTAN | 1 СЕРИЯ | bayGUYS
36:55
bayGUYS
Рет қаралды 1,9 МЛН