I have made circuit where you can see that it is reading some signal from a button.
I've found in Arduino tutorials that there should be a pull-down resistor, which I don't really understand well.
I've read tons of articles on the subject of open-drain/collector and haven't got the idea. This is why I don't understand what happens in this circuit. Maybe someone can explain me entire process.
When I measure voltage on the wire which goes to pin 12, I see 0V. When I read the voltage on the resistor (10 kiloohm,) I see almost 5V. How does pin 12 understand that I pass it a high if there no voltage going to pin 12?
const int buttonInputPin = 12;
const int ledPin = 13;
void setup() {
pinMode(buttonInputPin, INPUT);
pinMode(13, OUTPUT);
Serial.begin(9600);
}
void loop() {
int buttonState = digitalRead(buttonInputPin);
Serial.println(buttonState);
if (buttonState == HIGH) {
digitalWrite(ledPin, HIGH);
}else {
digitalWrite(ledPin, LOW);
}
}
I am using an Arduino Uno (ATMEGA 328PB.)