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));
}
2 Answers 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/
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.
Serial.println("setup")
to the setup function so you see when the arduino resets