2

I have created a curcuit which reads the analog pin 3 auf the arduino nano and does other things dependant on the returned value. However I have problems regarding the analogRead() function. Whenever I use a piece of wire to short the "Analog_UpDownHorn_Signal" and do it fast paced so that the arduino reads 0V and 5V repeatedly the serial communication stops. Sometimes it resumes. Sometimes it doesn't and when it does the value is always 1023.

I have managed to reduce the problem to the following 2 lines of code, which leads me to believe its my curcuit or a bug in the functions used. Before the arduino gets stuck it sometimes puts out random '?' or other wierd characters on the serial monitor.

void setup()
{
  Serial.begin(9600);
}

void loop() 
{
  Serial.println(analogRead(A3));
}

enter image description here

  • Few comments, does adding a delay in the loop of ~100ms help? Have you tried writing the value of A3 to a variable then printing the variable instead of nesting that in the print command? Can you confirm the Arduino is getting a stable 5V supply? Are other parts of a circuit connected to the Arduino still? – Jack Soldano Aug 12 at 13:43
  • The delay didn't help. Writing the value to a variable and printing it didn't help. I can confirm a stable 5V supply, i checked it. Also something noteworthy: when I use a resistor for example a 1kOhm the values (~512) are correct no glitches or anything. Only when i short the signal to ground these problems appear. – TaRg3t Aug 12 at 14:17
  • Add a Serial.println("setup") to the setup function so you see when the arduino resets – Sim Son Aug 14 at 15:40
2

The capacitor you have is rather large on the Analogue input, normally at this position it would be for debounce. Try something in the range of 100nF. Another idea would be to increase R8 to 10k.

https://www.g7smy.co.uk/2015/09/multiple-buttons-on-one-pin-with-an-arduino/

| improve this answer | |
2

I have fixed the issue by connecting the two grounds on the opposite site of the arduino nano with a thick solder connection on the bottom side of my perfboard. Seems like it really had to do with the big capacitance an the rapid discharge when shorting it to ground.

Maybe it had a "charge pump" like effect with decoupling cap and the debouncing cap, because those are on the same side of the board.

To further avoid this problem i will not short the cap an discharge it through a low ohm resistor. Furthermore i could lower the capacitance as it was stated before and up the resistor values.

| improve this answer | |

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.