Getting desperate. Arduinos digital read total nonsens


sind some weeks, I start doing a lot of stuff with arduino.

Today, I wanted to start my new project with a Arduino Mega2560. And now the trouble begun.
First I thought I would be stupid, I was not able to make a sketch, that prints in serial, just if a switch was toggled or not.

Later, doing stuff with LED, I saw, that nowthing works normal.

My digital pins read total nonsense. influenced from whatever… I have noe clue.
It also happens, that they read nonsense, when there is not even a cable plugged in.

I’ve updateded a video:

The best thing: I also have a Arduino UNO, and it behavers exactly the same!

What I’ve tested so far:

  • changed all cables (but as you see, the pins also change state without need of a cable)
  • changed the button (using the BASIC example for button and LED, this gets even stranger
  • change source of electricity. (USB 2 different ports, one powerbank and a power adapter.
  • also without breadboard, and another breadboard.
  • tested different sketches. With LED, without LED, also with builtin LED.
  • Output always seems to work correct. but as soon as a pin has input mode…

Hope someone has an idea what I could try next.

the inputs are floating and reading “noise”.
Use the pinMode(i,INPUT_PULLUP); instruction.

1 Like

If you want it to read LOW you need to connect it to GND.
If you want it to read HIGH you need it to sense 5 V (don’t connect it directly to 5 V).
Here a tutorial:

1 Like

Did you you fix it?

It works now. I missused INPUT and the INPUT_PULLUP.
however, I will also carfully check the tutorial using a resistor also for the button!
Thanks all!! :grinning:

An external pullup resistor is not need in the case you used the pinMode(pin,INPUT_PULLUP) instruction for the internal pullup resistor of the controller.