Problem with reading input from digital pin

Hello together,

I am now struggeling for over 2 weeks getting an input from a tactile switch (button), which is connected to ground via resistor on a ps5 controller.

That means I am trying to read the value of the input and do something with the value in my code.

I could use INPUT or INPUT_PULLUP, but if I use INPUT_PULLUP, I am getting a reading of HIGH, which is not optimal, because the button will be pressed even if I dont press it.

When I use INPUT, I am getting a reading of 0 (LOW), which wont change, even when I press the button.

I tried everything, it is a bit harder, because the button is not actually in contact with ground on the microcontroller and not directly connected to ground on the ps5 controller (only through resistor).

Does anyone have an idea?

Show how you connected it all together. Did you connect all grounds (micrcontroller and ps5 controller)?

What's the value of this resistor

Hello cano62

Take a view:

HTH

2 Likes

Actually the ground of the microcontroller and the ps5 controller are connected. I forgot to mention, that I am running the atmega328P-au standalone, it is running on 8Mhz.

It seems like the tactile switch of the analog sticks on the ps5 controller (L3 and R3) are only connected to ground when there is some voltage.

I connected the one leg (not the voltage legs) of the tactile switch to pin 10 on the microcontroller.

Hi,

Do you have a DMM? Digital MultiMeter.

Thanks. Tom.. :smiley: :+1: :coffee: :australia:

Hey Tom, yes I do.

It looks more like a capacitor which connects the pin to ground.

Measure the the voltage on the pin of the tactile switch with respect to gnd with the DMM in Vdc mode.
Voltage Not pressed.
Voltage Pressed.

Then
Measure the voltage on the pin of the tactile switch with respect to gnd with the DMM in Vac mode.
Voltage Not pressed.
Voltage Pressed.

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

In AC mode I am getting 0V.
In DC mode I am getting 1.8V.

This is how it looks:

Hi,
Are you using digitalRead?

If so, use an analog pin and analogRead.

You should see a change in raw analog data.

What model Arduino are you using?

Tom... :smiley: :+1: :coffee: :australia:

My Goal is actually the opposite. I want to have a reading of 1.8V when its not pressed and 0V when its pressed.

Why?

You can do that in software.
What are you trying to do ultimately?

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

1 Like

see post no.3
S2 or S3 are the easiest way to achieve what you’re looking for.

My problem is, that in INPUT mode I only get a reading of 0, even when I press the switch, what could be the issue?

Is it maybe possible to set the pin to HIGH via Input mode and then set it to input_pullup?

Problem seems to be that your HIGH is only 1.8V.
That is not sufficient for digitalRead().
Hence the suggestion (above) to use analogRead().

As @TomGeorge points out, this can be rectified in the software.

Most ppl use push buttons wired in the pullup configuration, either with INOUT_PULLUP or a real external resistor, for reasons.

Then the software fixes it simply, perhaps immediately the switch is read, viz:

   bool switchIsPresst = digitalRead(pin) == LOW;

You will see sometimes, the same thing with driving an LED. Depending on how they are wired, HIGH might mean either shining or off.

Get over whatever you need to here. Software allows all kindsa "inconvenient" or "sub-optimal" things to be fixed easily.

a7

That's correct: when the switch is open, the pullup will cause the line to go high - that's why it's called a pull-up.

No: when the button is pressed, it will go low - so you have:

  1. Low input = button pressed;
  2. High input = button not pressed.

This is often called "active low", because the signal goes low when it is active - in this case, when the button is pressed.

2 Likes

No, that's not true - the purpose of R4 is to make sure there is no short to ground!

It's exactly like the S2, R1 case - where R1 prevents a short to ground.

@awneil
You've taken this out of context. That drawing is one many of us refer to when sorting pushbutton issues for Newbies. It's original author, I think, was @LarryD. That note is a reference to the common issue of distributing +5V around a chassis or circuit for pushbuttons, and refers to the risk of shorting that +5V to other objects, causing damage.
In a grounded chassis or circuit box, it's an issue.
Generally, distributing GND for the same purpose has less risk(because the box is generally grounded, for shielding purposes, anyway), though we can argue that some other time. It is, admittedly, a minor point.

2 Likes