In series resistors, to trigger different responses from Arduino

Hi,

I'm very new on my electronics journey so I'd like some guidence please.

  1. Is the below concept possible (but probably not the execution) ?
  2. How could I achieve it properly?

I'm playing with the classic Arduino robot car and I'm moving on to the crash-detect bumpers. As I want to keep some pins free, I thought I might be able to use a single analogue-in pin to trigger different responses depending on the current/voltage it receives.

The assumption is that I have 3 push switches ( left, middle and right) all connected across the same two wires, with a resistor added in between them in series. For example the left switch goes through 1x220 ohm, the middle switch goes through 2x220 ohm and the right switch goes through 3x220 ohm. The picture below may convey the concept, but is likely to be electronically bad.

Diagram

Hopefully the analogue pin can detect the difference between each switch due to the difference in current/voltage, then I can respond differently in the code.

Any hep/guidance is welcome.

Many thanks

the concept is sound. It's how my drone remote control works.

3 resistors with equal value should drop 1/3Vcc across each resistor.

1 Like

But, not the way it is shown there.

2 Likes

Look up floating pins

1 Like

FYI

image

Also

1 Like

I tried this some time ago on a ESP32 for direction keys + OK. I tried to detect multiple keypresses, so the switches were parallel to the resistors. The jitter of the ADC ruined everything :slight_smile: In the end I used 1x1k pullup and 4x1k for the buttons (same design as in 1. posting) and direct to GND for "OK".

1 Like

Perfect thank you @LarryD, that is really helpful.

Yes, you need a voltage ladder and you can measure the voltage (via ADC).
But you cannot realize multiple keys pressed with this schematic provided by LarryD: S2 would already go to GND, never mind if S6 is also pressed (to GND).

Instead, you can put the switches (S2...S6) in parallel to the R2... R5:
now, you would shorten the resistors and change the voltage. Now you can see different voltages, also a double key press (resulting in another voltage).

1 Like

Is it important to have a reasonably high value resistor closest to the 5v, to ensure the current is kept within range?

I'm not sure I understand electronics well enough yet.

Could I guess that if the first resistor 2000 ohm and we have 5v, then using I=v/r
I=5/2000=2.2mA
Or an I mixing up my knowledge?

image

If switch S2 is closed the bottom of R6 is at GND.

We therefore have 5V across R6.

5V / R6 (2k) = the current flowing through R6.

5V / 2K = 2.5mA when Switch S2 is closed.


2.5mA is not a lot of current; the UNO 5V regulator can supply ~500mA (with Vin = 7-9V).

We could have used 20k, then the S2 closed current would be 250uA.

However you, the designer, need to decide if very low current is necessary.

The less the current, the more likely external electrical noise can effect readings.


With the selected resistors seen in the schematic, RAW A/D values are: 0, 145, 329, 505 and 741.

The different between the values is reasonably large and almost equal ~150 to 250.


Remember also, the external ladder supply voltage can vary some.

You should add window/range to your code when you decide a switch is closed as seen below.

#define ButtonWindow   10   //range for a valid button sensing

. . .

//are we within range of the BUTTON_UP RAW value (between 145-10 = 135 and 145+10 = 155) ?
if (buttonVoltage >= (UP_10BIT_ADC - ButtonWindow) && buttonVoltage <= (UP_10BIT_ADC + ButtonWindow))
{
  button = BUTTON_UP;
}

. . . 
1 Like

Thank you @LarryD, that makes sense now. I believe I've got enough knowledge to move forward.

I was planning to use an external 5V supply (Some batteries with a buck converter), so I believe I have enough power, I was perhaps mixing up how much power I could deliver to the A1 pin, not from the 5V. I think the concepts are still a little fuzzy in my head in that respect.

The Arduino input pins are very HIGH impedance, > 100 mega ohms.

They essentially consume no power/current. They work on voltage detection.

What are you implying ? :thinking:

My apologies if my comment implied wrongdoing on somebody else's part, it was a self criticism. I added a comment because I edited the post around 4 times, but I've now removed it.

I was falling into the trap of just asking for all the answers, without putting some effort in myself first. Only a little research answered the question I had asked in one of the edits.

For me, electronics and microcontrollers are a new hobby and a chance to learn something new, so just asking for all the answers is cheating :grin:

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.