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!
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.
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
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, ....
@@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
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 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
== 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/
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.
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)
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
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.
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.
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); }
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.
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'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.
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.
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!
Great video! All your explanations are slow and matcable. Great job!
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) ;
}
}
Great work!
Your vidios in the ardiuno series are amazing.Keep it up bro
Bro you explain the best. 👍👍👍
Amazing explanation
Great instruction thanks for sharing.
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.
could you pls tell me why that high resistor is used?(i am an absolute beginner with Arduino so i dont know any terms)
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
i love your videos
☺
It worked in tinkercard but it didn't work in real life
Did you find a way to fix it?
I looked through the code and he forgot to add the "if (digitalRead(2) == HIGH)
First step is to get a life
@@justin.420piss off
@@justin.420 Get lost bro ppl actually make money with this shi u need to get a life and learn something
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!
This is amazing! Thank you!
I made it so when pressed green led goes on when not pressed red led goes on
How?
@@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
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.
gee I wish when people write the code, they make it bigger to be able to see the code.
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: th-cam.com/video/FKekzzj5844/w-d-xo.htmlsi=VWlZPUgTYETmyjXP
thank uu
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.
@@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
sorry nevermind. i didnt connect it properly.
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/
Does it work with Mega 2560? (it is unofficial Arduino, but almost the same)
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
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)
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
use delay(miliseconds) before one of the digitalWrites i think
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.
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.
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.
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);
}
This code doesnt work. .....could not convert 'digitalWrite(12, 1)' from 'void' to 'bool. How to FIX????
its digitalWrite(12, HIGH)
It’s not working for me
why this button so big lmao goofy aah button
Youve never seen a slightly larger button before?
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
Why you need Arduino for this
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.
I copied the code and it won't compile. This is bullshit!
Did you find a way to fix it?
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
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.
pls explain in detail