Elegoo Uno - how is it possible?

Hi,

I'm working on a project with several sensors connected together using Elegoo Uno R3. I couldn't make it work and I tried to work out where the problem is. Thus, I needed to go back to the simplest examples like "button" from the library. The situation:

  1. Only one wire without anything is plugged to a digital port.
  2. Standard code "button" from the example library is uploaded to the board
  3. Led reacts to any motion near to the wire. But no reaction, if the wire is plugged to other port.
  4. It makes my crazy.

Watch it:

Code:

const int buttonPin = 10; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin

// variables will change:
int buttonState = 0; // variable for reading the pushbutton status

void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}

void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
} else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}

Instead of INPUT, you need a pin mode of INPUT_PULLUP or you need a pullup or a pulldown resistor. Without one of these three things, anything is possible.

Thanks. It helped.

But how is it possible? I used a pullup-resistor (1k) and it didn't helped.

It sounds a lot like your pullup was incorrectly wired.

Without a pin mode of INPUT_PULLUP or a pullup or a pulldown resistor, the inputs of an Arduino have a VERY high impedance (millions or even billions of ohms). A 1K resistor should have made a big improvement, but I cannot see what you have done, so I suspect (as did AWOL) that something has been miswired.

With this high an input impedance, the inputs are easily affected by anything on the integrated circuit, anything in the packaging, anything on the printed circuit board, even waving your hands around in the air nearby. This also explains why one input can be sensitive to your hands when others are not.

Changing the pin mode (in setup()) to INPUT_PULLUP is very easy and is unlikely to lead to wiring errors! I suggest that you try this.