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:
- Only one wire without anything is plugged to a digital port.
- Standard code "button" from the example library is uploaded to the board
- Led reacts to any motion near to the wire. But no reaction, if the wire is plugged to other port.
- 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 statusvoid 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);
}
}