Problem reading inputs D1 and D2

Hi,

Brand new here and no clue what we're doing. My son and I are using a Wemos D1 Mini. We have a circuit built with two outputs. When low, those outputs are around 20 mV, when high, 3.25 V.

We have them hooked up to input pins D1 and D2 on the Wemos. We are using output pins D5,D6, and D7 that go to an RGB LED. By playing with the code, we can get the RGB to light correctly.

In essence, we're using the Wemos to eliminate AND, XOR, and NOR gates we were using in the original circuit. Once solved, we also plan on using the wifi capability to alert when certain conditions exist..

We've tried to code so that when D1 and D2 are high, D5 is high, D1 or D2 is high, D6 is high, D1 and D2 are low, D7 is high.

Regardless of the state of the inputs, D7 is always high. My son at looked other examples to try to figure out the code and this is what he came up with -

void setup() {
  pinMode(D1, INPUT);
  pinMode(D2, INPUT);
  
  pinMode(D5, OUTPUT);
  pinMode(D6, OUTPUT);
  pinMode(D7, OUTPUT);
}

void loop() {
  //digitalWrite(D5, HIGH);
  //digitalWrite(D6, HIGH);
  //digitalWrite(D7, HIGH);
  if (digitalRead(D1) == HIGH && digitalRead(D2) == HIGH) {
    digitalWrite(D5, HIGH);
  } else if (digitalRead(D1) == HIGH || digitalRead(D2) == HIGH) {
    digitalWrite(D6, HIGH);
  } else {
    digitalWrite(D7, HIGH);
  }
}

Can anyone point us in the right direction?
Thank you!

You have stated what you want the outputs to be when there are specific input pin states, what you haven't stated is what you want the outputs to be when the desired states are not met.

The code also reflects this.
So what you may be seeing is that once the specific condition occurs and sets the output, there is nothing to change it.
In the code, once a condition sets a pin HIGH there is noting to ever set back to LOW.

For example, once D1 and D2 are both low, D7 will be set to HIGH and remain HIGH forever.

If you are wanting all the pins to be low if their corresponding conditions are not met, then you could add a 3rd if to check for your 3rd condition of both LOW and set D7 HIGH if that is true,
Then, the remaining else would set D5, D6 and D7 LOW.

--- bill

As Bill pointed out, you probably need to set all three pins in the states.

And since you are a self-proclaimed noob, do you have your input buttons wired properly? There are two ways to do this.

  1. Connect one side of a button to ground and the other to a pin. This requires that pin to be INPUT_PULLUP, not INPUT and it will read LOW when pressed and HIGH when not pressed. This requires no external components
  2. Connect one side of a button to VCC and the other side to a pin. This configuration requires an external resistor between the pin and ground so the pin will read LOW when not pressed and not simply be disconnected, aka “floating” which is bad (you may read either value)
void setup() {
  pinMode(D1, INPUT);
  pinMode(D2, INPUT);
 
  pinMode(D5, OUTPUT);
  pinMode(D6, OUTPUT);
  pinMode(D7, OUTPUT);
}

void loop() {
  //digitalWrite(D5, HIGH);
  //digitalWrite(D6, HIGH);
  //digitalWrite(D7, HIGH);
  if (digitalRead(D1) == HIGH && digitalRead(D2) == HIGH) {
    digitalWrite(D5, HIGH);
    digitalWrite(D6, LOW);
    digitalWrite(D7, LOW);
  } else if (digitalRead(D1) == HIGH || digitalRead(D2) == HIGH) {
    digitalWrite(D5, LOW);
    digitalWrite(D6, HIGH);
    digitalWrite(D7, LOW);
  } else {
    digitalWrite(D5, LOW);
    digitalWrite(D6, LOW);
    digitalWrite(D7, HIGH);
  }
}

Thanks so much to both of you !!! That did the trick. The circuit itself was still doing screwy things. Once I added the resistors from input to ground, it works flawlessly. Again, thank you !!!