-1

I have an Atmega328P-AU with 16Mhz crystal(schematics). And its analog pins A0 to A3 are connected to button inputs. All these pins are pulled-down(10K res). And in code, I have digitalRead(A0) to digtalRead(A3).

When I press button attached to A3 and A2. They works as they should. But when I press any button attached to A0 or A1, both their digitalRead() returns true.

I checked 3 times, all resistors and buttons wires are well connected and are not shorted.

Here is test code

void setup()
{
    Serial.begin(9600);
    pinMode(A0, INPUT);
    pinMode(A1, INPUT);
    pinMode(A3, INPUT);
    pinMode(A2, INPUT);
}

void loop()
{    
if (digitalRead(A0))
    Serial.println("A0");
if(digitalRead(A1))
    Serial.println("A1");
if (digitalRead(A2))
    Serial.println("A2");
if (digitalRead(A3))
    Serial.println("A3" );
delay(400);
}

Here are outputs.

When pressed A0

A0
A1

When pressed A1(same result)

A0
A1

When pressed A2

A2

When pressed A3

A3

I'm wondering what could be causing this problem ?

Edit: Test

  • When I press A1 button, the A1 pin is high with 4.8V as well as A0 pin is high with 2.6V to 3.8V.

  • When nothing is pressed, A1 has 180mV while A0 has -180mV.

schematic

simulate this circuit – Schematic created using CircuitLab

migrated from electronics.stackexchange.com Jul 7 '15 at 17:05

This question came from our site for electronics and electrical engineering professionals, students, and enthusiasts.

  • Have you actually checked the voltage on the A0 & A1 inputs when their switches are pressed, and only 1 of them goes high? Because this sounds like a short between A0 & A1... – Techydude Jul 7 '15 at 4:15
  • Please post a wiring schematic for verification and please verify A0 stays Low and A1 goes High using a dmm or osciloscope as @Techy dude suggests – crasic Jul 7 '15 at 4:42
  • I've updated the question, please check. – xmen Jul 7 '15 at 5:18
  • Just to point this out too, but when both A0_SW, A1_SW are pressed R1, R2 go into parallel where they can be seen as a single 5k resistor. – Matt Jul 8 '15 at 2:20
2

Assuming you've not activated any ADC functionality in your Arduino code (i.e. assuming the sample code you've posted here is 100% what you've tried, and no analogReference(); statement), then I still think your problem is a partial short between AO & A1. If my above assumptions are not the case, then there are other possibilities.

With a 5.0V Vcc rail, anything more than 0.5Vcc (i.e. 2.5V) will register as a high/1 (datasheet section 30 - Electrical characteristics, 30.2 DC Characteristics), so based on the measurements you posted to the edit of your question, your code is indeed correctly reporting a 1 on A0 when you push A1 button.

But it's only barely a 1/high, and as you've said, it varies from 2.6 to 3.8, another classic sign of a soldering or partial short circuit somewhere.

If you're able to remove the '328 from the circuit, use your multimeter to read resistance between A0 & A1. Also try a new/different '328, maybe you damaged one of its input in the past.

  • Not using any ADC functionality. There is around 8.8K resistance between A0 and A1 on '328 soldered to PCB. While a new unsoldered chip shows no resistance between those pins. So yea, either there is little short or more likely the uC got damaged. – xmen Jul 7 '15 at 13:22
  • One more thing, seems not important but strange. On soldered '328 the resistance between A2 and A3 is around 20K while A0 and A1 is 8.8K max. Also, the pulldown resistors on A0 and A1 shows 6.6K to 7K reading on their ends. While its 10K on A2 and A3 each. It seems not a problem because they just pulling down the current, but still why different values. – xmen Jul 7 '15 at 13:35
  • I would have replaced the '328 but still waiting for hot air gun. – xmen Jul 7 '15 at 13:37
0

I recreated this experiment on my Arduino and it worked like it should. This should work the way you want it to. The only thing I can think of is maybe the chip possibly being partially fried or the pullup resistors not being adequet (not having a low enough resistance) for the job. The resistors I used are 1k. Other than that there is not much else I can think of.

  • 2
    I used 10K pulldown, but its not working as it needs to at my side. – xmen Jul 7 '15 at 2:41
-1

Ok so it could be a number of factors. You are sure that the pins are 5V tolerant in the mode you're using? It's possible to burn out pins if they don't have internal current regulation. You said analog pin which is weird since a button will cause lots of debouce, but it looks configured digital. Debounce is still an issue on digital circuits with buttons.

  • Debounce can be solved very easily. Its not a problem to me. And according to datasheet of Atmega328P-AU, it can tolerate 5V. – xmen Jul 7 '15 at 8:51
  • Just because it can tolerate 5V doesn't mean it can sink the current off of a 5V bus without current regulation. If you didn't think my answer was helpful it doesn't mean you need to mark it down. All of what I said was true. I shouldn't need to open your datasheet and spoon feed you answers about your own device. – Matt Jul 7 '15 at 14:57
  • The resistors you're using should be fine by the way. Sock314 is not correct in that they may not be "low" enough. In this situation being too "low" of resistance would cause the issue. You want large resistors to hold a voltage drop and reduce current consumption. Also your pins are only 10uA tolerant. Are you sure that you didn't burn up the pin by sinking/sourcing too much current? – Matt Jul 7 '15 at 15:10
  • This is what I think you may have done. I'm work in EE on real time embedded systems by the way. ruggedcircuits.com/10-ways-to-destroy-an-arduino – Matt Jul 7 '15 at 15:21
  • First of all, I did not down voted you. I never do, unless the answer is very stupid and needs to be deleted. – xmen Jul 7 '15 at 19:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.