Eul
Eul

Reputation: 52

Why can't my Arduino Uno digitalRead() the digitalWrite() from other I/O pins?

I want to do something very basic as shown below:

#define READ_PIN    7
#define WRITE_PIN   8

void setup() {
  pinMode(READ_PIN, INPUT_PULLUP);
  Serial.begin(9600);
}

void loop() {
  digitalWrite(WRITE_PIN, LOW);
  Serial.println(digitalRead(READ_PIN));
}

I am bridging the WRITE_PIN and READ_PIN together to read what the pin is outputting.

The input always reads '1' as expected with INPUT_PULLUP, but I would like it to read '0'. I get the same results using analogRead() and analogWrite(), no matter which pins I use.

Does anybody know why this seems impossible to achieve?

Upvotes: 0

Views: 588

Answers (1)

Matteo Italia
Matteo Italia

Reputation: 126857

(moving from the comment)

Pin mode on Arduino is set to INPUT by default1; to use WRITE_PIN as an output you have to explicitly set it as such in setup.

pinMode(WRITE_PIN, OUTPUT);

  1. It's worth saying that, even if the default is documented, it's still good practice to always set explicitly the mode of all the pins in the setup, even input ones, for clarity.

Upvotes: 1

Related Questions