How connect multiple switches to one pin, Arduino?

Поділитися
Вставка
  • Опубліковано 13 гру 2024

КОМЕНТАРІ • 23

  • @recordationperioperativein5238

    You could also put the resistors from each switch in parallel and determine the resulting resistance to know if multiple switches were pressed at the same time

  • @recordationperioperativein5238

    Great idea. I wasn't sure why you needed to add Rg (until later when you said it was to minimize current flow). So technically you could make it simpler without it.

  • @tetraquark2402
    @tetraquark2402 3 місяці тому

    Nice! takes me back to when I studied electronics 40 years ago but then switched to programming mainly because I found the maths hard to do

  • @shokdj1
    @shokdj1 7 місяців тому +1

    This is a ladder resistor I've just done this on 1 of my projects it's fine as long as you don't need to press more than 1 button at a time

  • @aronmedders4353
    @aronmedders4353 3 роки тому +2

    Really nice video! Very well explained. I'll be using the math for a rotary switch that just so happens to be 12 position so the example is perfect!

  • @alabamacajun7791
    @alabamacajun7791 10 місяців тому +2

    Ironically I have an alarm clock that uses this principle. The only problem is sometimes pressing the time set button changes the alarm time. Turning the alarm on/off is a button clicking concerto in the morning.

  • @azeedogz
    @azeedogz 6 місяців тому +1

    Can this be done with rotary encoder?

  • @transientaardvark6231
    @transientaardvark6231 10 місяців тому +1

    Or, for N push=buttons, connect N+1 of all the same resistor value (doesn't really matter, just chose the sum to give maybe 0.1-10mA through the lot) and then use the switches to select a tap on the chain to the ADC input. No complex math, no problematic values. If the ADC is not reading the rail (put a big puller to one of the rails) then a switch is pressed, the voltage read tells you which.

  • @jeremywillis3434
    @jeremywillis3434 Рік тому +1

    So to use multiple switches at once, we can separate out the resistance to modulate the voltage output by 2^Rx, we can undo the math on the other end of the equation to essentially figure out which switches are closed, right?

  • @Stephens8x6Workshop
    @Stephens8x6Workshop 2 роки тому +1

    Nicely explained, thank you 🙂

  • @Scoobydcs
    @Scoobydcs Рік тому +1

    Does this work with toggle switches or will they flicker on/off?

  • @patrickmclaughlin6013
    @patrickmclaughlin6013 3 роки тому +1

    cool! great idea
    did you use software to de-bounce the switches?
    it seems like if you carefully selected the resistors you could have values for multiple button press signals?
    too bad the esp8266 only has one adc, guess you would need a ADS1115 in that case if you needed the adc for other sensors

    • @km077
      @km077 Рік тому +3

      About multiple buttons pressed at the same time:
      Since his values' distribution is linear (you add 0.083V each time (14:55 or this times 5 idk)) he cannot. This is an efficient way to distribute values for single presses while leaving lots of room for imperfect physical resistors' values.
      However, as you noticed, there is a way- make the distribution exponential (you multiply by 2 each time). By choosing the base to be 2, you can easily implement it in the binary system on the software side (Divide all values by the 1st increment and represent the resulting number as a binary number- each consecutive bit is the state of each consecutive button.). The downside would be less buttons that you could theoretically use, since the increment at the lowest values could be too small (in the case of too many buttons) for the Arduino to notice. Idk what the smallest safe increment is (would require a little bit of testing), but it determines the maximum amount of buttons you can use.
      About de-bouncing:
      These are standard buttons, so if anything he had to de-bounce them in the software. There exist expensive buttons that don't bounce when pressing and releasing. You don't always need to debounce, but for logic or other sensitive purposes you absolutely have to. You can do it by either adding a delay (with 'millis()' preferably) or by making a bunch of x previous measurements into an array and either counting whether there is more high or low states or by taking an average of those x measurements and comparing it to 0.5 (less than 0.5 would be low and more than 0.5 would be high (0.5 itself can be high or low, depending on your personal preference), since in Arduino Reference LOW==0 and HIGH==1).
      This comment is mainly for future adventurers, however if you check it out after those 2 years and find it still helpful, I'd be glad. lol cheers, mate

    • @shokdj1
      @shokdj1 7 місяців тому +1

      What I did on my ladder resistor was use 16 samples I also used a capacitor. So you press the button and it gives you the average value over 16 loops

    • @ertugrulbt
      @ertugrulbt 6 місяців тому

      @@shokdj1 What should be the value of the capacitor when using it? I made a 16 button system. Which capacitor should I use?

    • @shokdj1
      @shokdj1 6 місяців тому

      @@ertugrulbt .1uf

    • @shokdj1
      @shokdj1 6 місяців тому

      @@ertugrulbt I’d like to add I’m no expert but that seemed to help for me

  • @vikrantaev
    @vikrantaev 4 роки тому +1

    Nice project india👌

  • @lezbriddon
    @lezbriddon 9 місяців тому +1

    Issue is dirty switch contacts as they age causing errors.

  • @heypbolon1941
    @heypbolon1941 2 роки тому +1

    Thank you!

  • @linzenmeyer
    @linzenmeyer 8 місяців тому +1

    Or you can spend $1 and use an expander and cut the code by about 90%. Debounce would be a nightmare and multi-press will cause a number of issues.

    • @alby_alby
      @alby_alby 3 місяці тому +1

      By expander do you mmean a multiplexer or something else?

  • @ChandrashekarCN
    @ChandrashekarCN 10 місяців тому

    💖💖💖💖