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

Комментарии • 54

  • @casual2531
    @casual2531 3 месяца назад +8

    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 3 месяца назад

    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 4 месяца назад +2

    You explained very well! thank you so much!

  • @aaronjeffery7123
    @aaronjeffery7123 2 месяца назад

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

  • @farbodkeyhanloo906
    @farbodkeyhanloo906 8 месяцев назад

    This is amazing! Thank you!

  • @CaffineAndCode
    @CaffineAndCode 7 месяцев назад +1

    Amazing explanation

  • @AayushGupta-uj6hx
    @AayushGupta-uj6hx Месяц назад

    Bro you explain the best. 👍👍👍

  • @daveluvs3dprinters
    @daveluvs3dprinters 4 месяца назад

    i love your videos

  • @spurfy8392
    @spurfy8392 4 месяца назад

    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  4 месяца назад

      We recommend watching our video about LEDs before this one, it may answer your questions: ruclips.net/video/FKekzzj5844/видео.htmlsi=VWlZPUgTYETmyjXP

  • @behem05
    @behem05 8 месяцев назад

    what do i need to edit in order to replace the led with variables?

    • @Science.Buddies
      @Science.Buddies  8 месяцев назад

      If you watch to the end of the video (starting around 16:20) we cover using variables in the code.

  • @G18-ROQUEPRECIOUSZOEA.
    @G18-ROQUEPRECIOUSZOEA. 4 месяца назад

    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  4 месяца назад

      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.

  • @amirarab254
    @amirarab254 2 месяца назад

    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  2 месяца назад +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 2 месяца назад

      Thank you very much

  • @user-nv3sb5hr2f
    @user-nv3sb5hr2f Месяц назад

    thank uu

  • @Lucky_Trucky
    @Lucky_Trucky Год назад +6

    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  Год назад +4

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

  • @ArzenikRawr
    @ArzenikRawr 6 месяцев назад +5

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

    • @micahbentley2233
      @micahbentley2233 6 месяцев назад

      How?

    • @ArzenikRawr
      @ArzenikRawr 6 месяцев назад

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

    • @kushalm7328
      @kushalm7328 5 месяцев назад

      me too😀

    • @micahbentley2233
      @micahbentley2233 5 месяцев назад

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

    • @tomekpro2918
      @tomekpro2918 5 месяцев назад

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

  • @anjiiro610
    @anjiiro610 3 месяца назад

    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  3 месяца назад

      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.

  • @harishanth.r732
    @harishanth.r732 4 месяца назад

    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 3 месяца назад

      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)

  • @SyntaxError-2505
    @SyntaxError-2505 2 месяца назад

    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  2 месяца назад

      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.

  • @travisborges1048
    @travisborges1048 2 месяца назад

    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  2 месяца назад

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

  • @dataeater1319
    @dataeater1319 Месяц назад

    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 ?

    • @Science.Buddies
      @Science.Buddies  Месяц назад

      Hi - you may have more luck asking this question on the official Arduino forums.

  • @rrssmooth6643
    @rrssmooth6643 4 месяца назад

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

  • @marvelqueen52
    @marvelqueen52 Месяц назад +2

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

  • @__KursK__
    @__KursK__ 2 месяца назад

    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  2 месяца назад

      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__ 2 месяца назад

      @@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  2 месяца назад

      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

  • @user-ld5gx1zx8v
    @user-ld5gx1zx8v 4 месяца назад

    It doesn't work

    • @123nody
      @123nody 4 месяца назад

      Same for me

    • @123nody
      @123nody 4 месяца назад

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

    • @sadhgunavarshinie7281
      @sadhgunavarshinie7281 3 месяца назад

      Check the other vid about debugging arduino in this playlist

  • @IplayGames24seven
    @IplayGames24seven 2 месяца назад

    I dont have a PC 😡

    • @Science.Buddies
      @Science.Buddies  2 месяца назад

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

  • @RJkatztabby
    @RJkatztabby Месяц назад

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

  • @bimbo-yw6ny
    @bimbo-yw6ny 15 дней назад

    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 15 дней назад

    why the 10kohms resistor??

    • @bimbo-yw6ny
      @bimbo-yw6ny 15 дней назад +1

      i'm sorry i followed the video, i got the explanation, not to short the 5v to the pin with a 10k resistor.