How connect multiple switches to one pin, Arduino?

แชร์
ฝัง
  • เผยแพร่เมื่อ 12 ส.ค. 2020
  • In this video, I show the circuit needed to connect multiple buttons to one pin (an analog pin) on the Arduino. I explain the circuit and how to design it. This circuit displays the power and usefulness of resistors and the potential divider.
  • วิทยาศาสตร์และเทคโนโลยี

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

  • @recordationperioperativein5238
    @recordationperioperativein5238 6 หลายเดือนก่อน +5

    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

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

    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!

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

    Nicely explained, thank you 🙂

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

    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.

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

    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.

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

    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

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

    Thank you!

  • @vikrantaev
    @vikrantaev 3 ปีที่แล้ว

    Nice project india👌

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

    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.

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

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

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

      @@ertugrulbt .1uf

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

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

  • @azeedogz
    @azeedogz 25 วันที่ผ่านมา

    Can this be done with rotary encoder?

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

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

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

    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?

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

    💖💖💖💖

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

    Issue is dirty switch contacts as they age causing errors.

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

    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.