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

แชร์
ฝัง
  • เผยแพร่เมื่อ 25 พ.ย. 2024

ความคิดเห็น • 81

  • @casual2531
    @casual2531 7 หลายเดือนก่อน +20

    You have no idea how much you have taught me, thank you brother.
    I love the way you explain stuff.
    May God bless you.

  • @azatturegeldin4716
    @azatturegeldin4716 8 หลายเดือนก่อน +2

    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!

  • @eternitysf3413
    @eternitysf3413 8 หลายเดือนก่อน +3

    You explained very well! thank you so much!

  • @TehnoVito
    @TehnoVito 4 หลายเดือนก่อน

    Great video! All your explanations are slow and matcable. Great job!

  • @BlobGod
    @BlobGod 23 วันที่ผ่านมา

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

  • @savithachess1109
    @savithachess1109 15 วันที่ผ่านมา

    Great work!

  • @aaronjeffery7123
    @aaronjeffery7123 7 หลายเดือนก่อน

    Your vidios in the ardiuno series are amazing.Keep it up bro

  • @AayushGupta-uj6hx
    @AayushGupta-uj6hx 5 หลายเดือนก่อน

    Bro you explain the best. 👍👍👍

  • @CaffineAndCode
    @CaffineAndCode ปีที่แล้ว +1

    Amazing explanation

  • @Orcanian66
    @Orcanian66 4 หลายเดือนก่อน

    Great instruction thanks for sharing.

  • @brewski425castleclash
    @brewski425castleclash หลายเดือนก่อน

    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 24 วันที่ผ่านมา

      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 24 วันที่ผ่านมา

      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

  • @daveluvs3dprinters
    @daveluvs3dprinters 8 หลายเดือนก่อน

    i love your videos

  • @marvelqueen52
    @marvelqueen52 6 หลายเดือนก่อน +13

    It worked in tinkercard but it didn't work in real life

    • @tutorialtime403
      @tutorialtime403 4 หลายเดือนก่อน +1

      Did you find a way to fix it?

    • @just_sayin8208
      @just_sayin8208 3 หลายเดือนก่อน +2

      I looked through the code and he forgot to add the "if (digitalRead(2) == HIGH)

    • @justin.420
      @justin.420 2 หลายเดือนก่อน +5

      First step is to get a life

    • @ChaksFM
      @ChaksFM 2 หลายเดือนก่อน

      ​@@justin.420piss off

    • @farham565
      @farham565 4 วันที่ผ่านมา

      ​@@justin.420 Get lost bro ppl actually make money with this shi u need to get a life and learn something

  • @Lucky_Trucky
    @Lucky_Trucky 2 ปีที่แล้ว +7

    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 ปีที่แล้ว +5

      Thanks for the suggestion! We will be adding more Arduino tutorials in the future, stay tuned!

  • @farbodkeyhanloo906
    @farbodkeyhanloo906 ปีที่แล้ว

    This is amazing! Thank you!

  • @ArzenikDev
    @ArzenikDev 10 หลายเดือนก่อน +7

    I made it so when pressed green led goes on when not pressed red led goes on

    • @micahbentley141
      @micahbentley141 10 หลายเดือนก่อน

      How?

    • @ArzenikDev
      @ArzenikDev 10 หลายเดือนก่อน

      @@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 10 หลายเดือนก่อน

      me too😀

    • @micahbentley141
      @micahbentley141 10 หลายเดือนก่อน

      nvm, you can make this with no arduino, just a relay. how did I do that?

    • @tomekpro2918
      @tomekpro2918 10 หลายเดือนก่อน

      change line: (digitalRead(button_Pin)==LOW) on this one (digitalRead(button_Pin)==HIGH) - will be ok now.

  • @rrssmooth6643
    @rrssmooth6643 8 หลายเดือนก่อน

    gee I wish when people write the code, they make it bigger to be able to see the code.

  • @spurfy8392
    @spurfy8392 9 หลายเดือนก่อน +1

    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  9 หลายเดือนก่อน +1

      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

  • @voscapattern
    @voscapattern 6 หลายเดือนก่อน

    thank uu

  • @ran_ramirez
    @ran_ramirez 8 หลายเดือนก่อน +1

    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  8 หลายเดือนก่อน +1

      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 17 วันที่ผ่านมา

      @@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 17 วันที่ผ่านมา

      sorry nevermind. i didnt connect it properly.

  • @SgtDangerWaffles
    @SgtDangerWaffles 7 หลายเดือนก่อน

    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  7 หลายเดือนก่อน

      == 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/

  • @mila-ko3036
    @mila-ko3036 2 หลายเดือนก่อน

    Does it work with Mega 2560? (it is unofficial Arduino, but almost the same)

  • @amirarab254
    @amirarab254 7 หลายเดือนก่อน

    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  7 หลายเดือนก่อน +1

      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 7 หลายเดือนก่อน

      Thank you very much

  • @harishanth.r732
    @harishanth.r732 8 หลายเดือนก่อน

    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 8 หลายเดือนก่อน

      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)

  • @satoo2768
    @satoo2768 หลายเดือนก่อน

    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 17 วันที่ผ่านมา

      use delay(miliseconds) before one of the digitalWrites i think

  • @SyntaxError-2505
    @SyntaxError-2505 7 หลายเดือนก่อน

    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  7 หลายเดือนก่อน

      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.

  • @G18-ROQUEPRECIOUSZOEA.
    @G18-ROQUEPRECIOUSZOEA. 9 หลายเดือนก่อน

    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  9 หลายเดือนก่อน

      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.

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

  • @mila-ko3036
    @mila-ko3036 2 หลายเดือนก่อน

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

  • @ИгорьБакуринский
    @ИгорьБакуринский 3 หลายเดือนก่อน

    This code doesnt work. .....could not convert 'digitalWrite(12, 1)' from 'void' to 'bool. How to FIX????

    • @voxelcatt
      @voxelcatt 2 หลายเดือนก่อน

      its digitalWrite(12, HIGH)

  • @coreyworthington8786
    @coreyworthington8786 4 หลายเดือนก่อน

    It’s not working for me

  • @sen8078
    @sen8078 2 หลายเดือนก่อน +1

    why this button so big lmao goofy aah button

    • @Studs_Studio
      @Studs_Studio 17 วันที่ผ่านมา

      Youve never seen a slightly larger button before?

  • @__KursK__
    @__KursK__ 7 หลายเดือนก่อน

    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  7 หลายเดือนก่อน

      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__ 7 หลายเดือนก่อน

      @@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  7 หลายเดือนก่อน

      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

  • @sandipkr.sarkar5813
    @sandipkr.sarkar5813 หลายเดือนก่อน

    Why you need Arduino for this

    • @junixec
      @junixec 27 วันที่ผ่านมา

      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.

  • @RJkatztabby
    @RJkatztabby 5 หลายเดือนก่อน +1

    I copied the code and it won't compile. This is bullshit!

    • @tutorialtime403
      @tutorialtime403 4 หลายเดือนก่อน

      Did you find a way to fix it?

  • @Book9999-x4z
    @Book9999-x4z 9 หลายเดือนก่อน

    It doesn't work

    • @123nody
      @123nody 8 หลายเดือนก่อน

      Same for me

    • @123nody
      @123nody 8 หลายเดือนก่อน

      it works on the tinkercad sim, but on the board it doesn't. I debugged it but still nothing

    • @sadhgunavarshinie7281
      @sadhgunavarshinie7281 8 หลายเดือนก่อน

      Check the other vid about debugging arduino in this playlist

  • @IplayGames24seven
    @IplayGames24seven 7 หลายเดือนก่อน

    I dont have a PC 😡

    • @Science.Buddies
      @Science.Buddies  7 หลายเดือนก่อน

      You can also program an Arduino from a Mac! See the software options here: www.arduino.cc/en/software

  • @bimbo-yw6ny
    @bimbo-yw6ny 5 หลายเดือนก่อน

    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 5 หลายเดือนก่อน

    why the 10kohms resistor??

    • @bimbo-yw6ny
      @bimbo-yw6ny 5 หลายเดือนก่อน +1

      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 24 วันที่ผ่านมา

      pls explain in detail