Raspberry Pi - Getting Inputs from Buttons...

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 ก.พ. 2025
  • Here is another Raspberry Pi GPIO tutorial... This tutorial builds on my previous 2 tutorials available to view via my Channel. In this tutorial you will learn how to get an input from a simple button.
    www.youtube.com...
    Commands used:
    To change directory - cd /****/*****/*****/
    To enable your python program - sudo python yourprogram.py
    Code write up in this forum post: www.raspberrypi...
    Please subscribe and tell your friends of my videos! Feel free to comment on what you would like me to do next or if you have any problems!
    The Raspberry Pi Guy
    theraspberrypiguy@gmail.com
    www.amazon.co.u...

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

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

    11 years and still Useful, thank you!

  • @TheSparky300
    @TheSparky300 12 ปีที่แล้ว

    Great tutorial thanks. One question, 'protection' to be safe should you have not added another resistors or a Zener diode? I'm interest in knowing if this is needed for the 3.3V connection.

  • @aarcher73k
    @aarcher73k 11 ปีที่แล้ว

    "Python is the best beginner's language"
    Not only is it not the best language, it's NOT the best for beginners. It is however, my favorite language :) I have my RPi running a few devices atm. I control them all over TCP connections... very fun and pretty easy!

  • @beersy001
    @beersy001 12 ปีที่แล้ว

    Hey, great video!
    Do you really need that 2nd while loop? after your if clause wouldn't the thread go back to the start of the 1st while loop and re-get the value of gpio.input(17), which if the button is not held down would be true?

  • @MrSabbatage
    @MrSabbatage 12 ปีที่แล้ว

    Great video. I'm going to hook mine to a magnetic door sensor, so it will close the circuit when the door is opened and open it again when it's shut. How would the code change to execute the print on initial circuit close? I want to send an email when the door opens initially, not wait for it to close.
    Thanks for any and all help

  • @nialllonergan7225
    @nialllonergan7225 11 ปีที่แล้ว

    Your tutorials are excellent! Keep it up man!

  • @mylaptopdiednooo
    @mylaptopdiednooo 12 ปีที่แล้ว

    I couldnt use sound on this video for some reason could i use this for creating a controller mounted onto the case of a portable pi im making

  • @AlexisHopeBambii
    @AlexisHopeBambii 11 ปีที่แล้ว

    Python is great for learning. What do you suggest Haskell?

  • @nvhs83
    @nvhs83 12 ปีที่แล้ว

    nice! can you write a wiring diagram?
    How many ohm resistor?

  • @382946rthu
    @382946rthu 9 ปีที่แล้ว +1

    Isn't the internal loop to prevent the from redisplaying multiple time? Seems like the main loop would update your variable.

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

    Great video m8! Choosing a red wire for the ground was a bit confusing though.

  • @leefiles
    @leefiles 11 ปีที่แล้ว

    Thanks.
    I use the 26 pin connector from the pi to the experimenter's bread board pretty much at all times.

  • @grey3agle
    @grey3agle 11 ปีที่แล้ว

    using a button like that to click intending on making something a bit portable I have two momentary switches was just wondering for a left and right click how i would go about it i get that i could run at boot the script once I have it but i dunno where to begin on the script python to me is like french i can jumble through and read it but inderpendant writing is borderline impossible help please

  • @kevinrogers8647
    @kevinrogers8647 11 ปีที่แล้ว

    great work have you any code on a stepper motor that works
    as I'm new to coding and 65yrs old I do find it quit fun. kevin

  • @frozencons
    @frozencons 8 ปีที่แล้ว

    Excellent work, man. Thanks for doing this.

  • @whidzee
    @whidzee 11 ปีที่แล้ว

    How would you set up this button to be a power button for the raspberry pi? hit the button and it shuts it down, hit it again and it turns it on.

  • @AlexisHopeBambii
    @AlexisHopeBambii 11 ปีที่แล้ว

    Nice vid, thanks! Im twice your age and you're teaching me stuff! Going to have a go at this over the weekend.
    Out of interest where did you get your parts from? Over the counter electronics store or online? Links would help a noob like me ;)

  • @blackout_rizzle5723
    @blackout_rizzle5723 10 ปีที่แล้ว

    Hello. i am trying to wire 6 buttons to the rasberry pi b+ model. Each will have its own functions. any suggestions on how the wiring should be made and what code will work in python. Very new to rasberry pi but loving it thus far. Thanks in advance

  • @Totogita
    @Totogita 9 ปีที่แล้ว

    I hooked up a momentary shut down button on my raspberry pi so when I press it the pi shuts down. I got the idea from instructable. Now I would like to monitor the 10 flashes using a GPIO pin. Can that be done and how? I really need to insert the python code that will copy the flashes on Pi and output it via an external led

  • @fc_key
    @fc_key 8 ปีที่แล้ว

    I still got the question isn't it possible to connect the button directly by 3.3v and on the other side to the imput GPIO? When button not pressed no voltage on input GPIO pin when pushed 3.3v on the input GPIO pin? Why do we need two circuits? May the 3.3V damage the raspberry?

  • @hennry33133
    @hennry33133 8 ปีที่แล้ว

    Is it possible to make it wireless using rf433 receiver and transmitter? For example the button is connected to a transmitter and the rpi is connected to a transmitter. And when i press the button, it will show "button has been pressed" on the rpi

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

    @10:54 The word ("embedded") and it's meaning certainly being used in** a grammatically correct way; however, it is not the proper terminology. In programming, loops which can be described in this was are known as "nested" loops. Any loop, test, or other function, wherein another independent non-procedural series of statements occur is given the quality of being "nested". This covers nested if-statements, nested loops, and the concepts of applied incursion (v. procedural) functions. I'm not familiar with python enough to say "use a do-while loop," - but it looks like that would have made a lot more sense here as well.. Maybe a boolean flag, and a function, with a check against the end condition (pin state high/low), etc. Nice job though! :D

  • @1229ywm
    @1229ywm 9 ปีที่แล้ว

    Can I add in one more button using gpio 18 and how to write the code.

  • @nolimit7
    @nolimit7 10 ปีที่แล้ว

    hi i would like to control xbmc using these type of buttons any ideas on how to do this.

    • @TerribadSC2
      @TerribadSC2 10 ปีที่แล้ว

      You would have to program the buttons to simulate key presses. Not terribly difficult but some minor programming is involved.

  • @SirSilversilk
    @SirSilversilk 12 ปีที่แล้ว

    Loved this button video....thank you!

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

    Great tutorials but your statement about tactile switches is incorrect. A tactile switch can be a momentary or latching / locking. By default a tactile switch isn't latching. That said you have specified that it needs to be momentary so user will get it right anyway. I only wanted to say this so that potentially another 16,000 people don't leave with wrong idea about the definitions. Thanks and keep up with the awesome tutorials :D

  • @iamnoobprooftvuk790
    @iamnoobprooftvuk790 11 ปีที่แล้ว

    how do u connect your rasberry pi to your pc?

  • @jankaptijn9936
    @jankaptijn9936 11 ปีที่แล้ว

    what kind of case do you use

  • @berighteous
    @berighteous 12 ปีที่แล้ว

    how many buttons can we hook to the pi?

  • @TraceguyRune
    @TraceguyRune 7 ปีที่แล้ว

    Doesn't dust kill circuit boards? Why do all the Pi cases leave it open and vulnerable to dust

  • @r1ch0007
    @r1ch0007 11 ปีที่แล้ว

    Thanks! This has helped me alot. Quick question tho, where can I get that plastic casing you have for your Pi?
    Thank you :)

    • @sanmighty3308
      @sanmighty3308 4 ปีที่แล้ว

      On the raspberry pi store

  • @ipodsandwaffles
    @ipodsandwaffles 11 ปีที่แล้ว

    Hello. Love the tutorial. Would be really nice to know how to replace the print command with a command line command. Thanks!

  • @MatthewSwartIreland
    @MatthewSwartIreland 12 ปีที่แล้ว

    How ya mate? I ran that Tutorial and came up with the following error.
    root@raspberrypi:/home/pi# sudo python gpiotest1.py
    File "gpiotest1.py", line 9
    while True:gpio.output(14, gpio.HIGH) time.sleep(1) gpio.output(14, gpio.LOW) time.sleep(1)
    ^
    SyntaxError: invalid syntax
    Confused as I typed it all out as per your tutorial am I missing something?

  • @humzaahmed6563
    @humzaahmed6563 9 ปีที่แล้ว

    will this work from a touch sensor

  • @AmKorvell
    @AmKorvell 11 ปีที่แล้ว

    Hello. Awesome tutorial.
    When I close the program and then start it again, I get the following message:
    runtimewarning this channel is already in use.
    I have tried adding the following GPIO.cleanup().
    But it does not help.

  • @SixtyNeptune
    @SixtyNeptune 9 ปีที่แล้ว

    i know its been a lot of time like a lot lot of time on this video and i want to ask you something... soo the last part of the program when u said
    while input_value == False:
    input_value==gpio.input(17)
    it means that whenever you press the button and get the false it goes back to the value it had before pressing? something like that? hope someone can answer me asap thanks!

    • @TheRaspberryPiGuy
      @TheRaspberryPiGuy  9 ปีที่แล้ว

      +Kariey Zah well isn't this a blast from the past! I can't actually remember what I was thinking when I coded this (that's what comments are for, whoops!) but I do remember the crux of the code coming from a MagPi magazine. You're description of its function is right, however if I was to make this video again I would probably simplify my program!

  • @johnkrumrine6098
    @johnkrumrine6098 11 ปีที่แล้ว

    Do you have recommendations for making a more permanent circuit based on this? I'm really new to electronic experimentation and I'm trying to make this button circuit to place into a Super Nintendo case. Breadboard doesn't really work in that situation. >.

  • @neurom4nc3r
    @neurom4nc3r 11 ปีที่แล้ว

    awesome tutorials, you do a very good work. cya

  • @piraats008
    @piraats008 12 ปีที่แล้ว

    Ace! You saved my life :D Thanks very much

  • @dominikhofer6161
    @dominikhofer6161 11 ปีที่แล้ว

    wie muss ich es machen wen ich machen wil das es stat "the button has been brest " einen input auf einen anderen pin geben wil ??

  • @Alxsoa
    @Alxsoa 7 ปีที่แล้ว

    Excellent tutorial, it helped me a lot

  • @jeevankumar5140
    @jeevankumar5140 6 ปีที่แล้ว

    How can I interact with any python games through this button press

  • @arbo1998
    @arbo1998 11 ปีที่แล้ว

    This is so cool!
    i did everything that you did in the tutorial but i keep getting this error when I try to run the program.
    pi@aaronpi ~ $ sudo python /button.py
    File "/button.py", line 11
    ^
    SyntaxError: invalid syntax
    I am not sure what is is saying because there is no line 11.

  • @smrutimandal
    @smrutimandal 12 ปีที่แล้ว

    Are you using GPIO pin 14?

  • @MrJoniDisco
    @MrJoniDisco 11 ปีที่แล้ว

    hi there
    can i have some help off some 1 how do i get it to work with a html to puss a button on a website plz

  • @andrewshaw1525
    @andrewshaw1525 12 ปีที่แล้ว

    First of all, excellent tutorial!
    I would like to know how I might modify the code so that I can have one action after one press of the button and a different action if I double-tap the button (maybe allowing 100ms to listen for a second press) Can anyone help?

  • @oliviacharlebois5311
    @oliviacharlebois5311 11 ปีที่แล้ว

    Where can I buy this button?

    • @kbowden111
      @kbowden111 11 ปีที่แล้ว

      You can buy these buttons on Ebay like this listing here: www.ebay.com/itm/100pcs-Tactile-Push-Button-Switch-Momentary-Tact-6x6x5mm-DIP-Through-Hole-4pin-/231123514137?pt=LH_DefaultDomain_0&hash=item35d008f319

  • @ipodsandwaffles
    @ipodsandwaffles 11 ปีที่แล้ว

    import os
    os.system('command here')
    would like to show you the project i made using only the tools you provided for me here...

  • @thomasengland6263
    @thomasengland6263 11 ปีที่แล้ว

    Can you get it to say light and flash a light

  • @programmernewbe
    @programmernewbe 2 ปีที่แล้ว

    how if 3 buttons are pressed simultaneously?

  • @iamnoobprooftvuk790
    @iamnoobprooftvuk790 11 ปีที่แล้ว

    i suscribed by the way ur a good teacher

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

    It only works when I press it once.

  • @ollierollie7443
    @ollierollie7443 5 ปีที่แล้ว

    Do you still use this?

  • @IlhamAkbarz
    @IlhamAkbarz 12 ปีที่แล้ว

    Great tutorial !

  • @iamnoobprooftvuk790
    @iamnoobprooftvuk790 11 ปีที่แล้ว

    i shared your video on facebook so it can get more views

  • @UCBCteam
    @UCBCteam 12 ปีที่แล้ว

    Hello everyone
    I was wondering if I can find any helpful materials or tutorials on how to read data and transfer data from one device to another Raspberry PI device using USB ports. In short it would be reading data through USB.
    Please help me with this I would really appreciate your help
    Many thanks
    Usman

  • @hohtz
    @hohtz 12 ปีที่แล้ว

    Can't you do that on C ?

  • @alexwolfe313
    @alexwolfe313 10 ปีที่แล้ว

    Sometimes the button registers two presses, any idea why?

    • @iamjoe610
      @iamjoe610 10 ปีที่แล้ว +3

      That's because of something called bouncing. Think of what would happen if you took a hammer and smacked it against a concrete floor, the hammer would make contact with the floor initially, and sort of bounce around, if it were a switch it would act as if it was flipped several times. There is a way of fixing it, a process called debouncing, instead of checking the input for a high pulse, it checks for a falling pulse and activates a small delay before it can be reactivated.

    • @teeraucher
      @teeraucher 7 ปีที่แล้ว

      Why don't u put the button in between the resistor and gpio17? That way the circed is normally on zero v and only uses energy if pressed. Also calling the input will return True if the button is pressed witch is a bit more logical in my opinion.

  • @CallumSteadman
    @CallumSteadman 11 ปีที่แล้ว

    hi getting error
    AttributeError: 'module' object has no attribute 'setmode'
    please help

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

      Sounds like you either do not have GPIO library installed, have not imported it correctly, or you did not use it as a function like this: gpio.setmode(gpio.BCM). Linux and Python are case sensitive so make sure all lower case and upper case letters match the code above. Pause video at 9:22 to see how everything needs to be typed. In programming a single spelling or case sensitive error can throw the entire program off.

  • @malikbrahimi7504
    @malikbrahimi7504 10 ปีที่แล้ว

    This is not working for me and I've done exactly as you've said. I need your help.

  • @esi915
    @esi915 12 ปีที่แล้ว

    awesome work man! thanks

  • @andrewshaw1525
    @andrewshaw1525 12 ปีที่แล้ว

    I figured it out when used my brain :P
    Cheers!

  • @NinjaOtt3r
    @NinjaOtt3r 12 ปีที่แล้ว

    ~Novice electrician speaking~ I found the source of the problem. So apparently if you connect the 3.3 volts to ground, the pi restarts. (I assume this is a safety feature)

  • @NinjaOtt3r
    @NinjaOtt3r 12 ปีที่แล้ว

    Great vid, but I kinda programmed a button that restarts my pi on accident... (Help me please!)

  • @TamilLatest
    @TamilLatest 12 ปีที่แล้ว

    awesome video!

  • @iamnoobprooftvuk790
    @iamnoobprooftvuk790 11 ปีที่แล้ว

    oyeah how much does a rasberry pi cost

  • @Lazy84.20
    @Lazy84.20 12 ปีที่แล้ว

    Just a friendly message that "sudo" is pronounced "su do". It doesn't sound like the word "pseudo". It's from DO this as SuperUser. Also, thanks for the tutorial.

  • @FranseFrikandel
    @FranseFrikandel 11 ปีที่แล้ว

    When changing directory, you already where in your home directory (/home/pi) and all you needed to type was: cd MTB/

  • @FahadUddin1
    @FahadUddin1 10 ปีที่แล้ว

    hi
    can i have this program in C...plz

  • @kevinrogers8647
    @kevinrogers8647 11 ปีที่แล้ว

    great work I think you should be a teacher. could you work through a stepper motor please.

  • @Zadstube
    @Zadstube 11 ปีที่แล้ว

    this comment has nothing to do with Raspberry Pi... just had to say.. you sound exactly like the kid from the original max headroom movie O-o.... he created an AI. you work with PI ^_^

  • @graffking1999
    @graffking1999 11 ปีที่แล้ว

    You could have used a else statement, it looks nicer.

  • @dfreak1000
    @dfreak1000 12 ปีที่แล้ว

    its reali cool that hes going

  • @iamnoobprooftvuk790
    @iamnoobprooftvuk790 11 ปีที่แล้ว

    i am 10 plz can u use more simple language and what was the aim of the video? and i was wondering if u could teach us how to make a r.c(remote controlled) car using xbox controller/controller and rasberry pi to move the r.c car

  • @wassimigho
    @wassimigho 7 ปีที่แล้ว

    Cool! Thanks a lot!

  • @AirTrip2010
    @AirTrip2010 9 ปีที่แล้ว

    It's "if not input_value", not "if input_value == False".

  • @r1ch0007
    @r1ch0007 11 ปีที่แล้ว

    Thanks! :)

  • @chunyousu7759
    @chunyousu7759 8 ปีที่แล้ว

    only work when I touch it with my hand, wtf

  • @viper474
    @viper474 12 ปีที่แล้ว

    While I understand the rationale behind why you'd pronounce it that way, I have heard very few people actually say it that way.

  • @NinjaOtt3r
    @NinjaOtt3r 12 ปีที่แล้ว

    P.S. I've pressed it three times now.

  • @viper474
    @viper474 11 ปีที่แล้ว

    I understand why you would say sue do, but I have only heard people say sue doh.

  • @SeniorDigitalMarketing
    @SeniorDigitalMarketing 12 ปีที่แล้ว

    go to 12:55 to see it work

  • @iamnoobprooftvuk790
    @iamnoobprooftvuk790 11 ปีที่แล้ว

    by the way the rasberry pi cost £90 including case andi live in england

  • @esteves-mo8zb
    @esteves-mo8zb 10 ปีที่แล้ว

    You shuld shutdown the PI while you are doing those connections

  • @ChristopherJones242
    @ChristopherJones242 10 ปีที่แล้ว

    10 killer ohm

    • @girardaquino
      @girardaquino 9 ปีที่แล้ว

      Too high? Just wondering...

  • @kumaridavid2551
    @kumaridavid2551 11 ปีที่แล้ว

    Hi I am 14

  • @doldol1
    @doldol1 8 ปีที่แล้ว

    Euw "if value == False:". I puked a little. "if not value:"?