-->
Page 1 of 2

update NodeMCU pin

PostPosted: Tue Dec 24, 2019 10:00 am
by Maks
Hello all,

I'm i need of a little hand...

i'm trying to make my coffee machine "smart", but im having a little problem, i need to identify if the coffee machine is on at the moment or not.

I need to read the state of a pin (D7) depending if there's a 3.3v there or not...
I mean, if i put 3.3v to D7 it should return me "HIGH or 1", and when i remove the 3.3v it should show me "LOW or 0", but when i put 3.3v it remains high until i connect it to gnd

This is the code i have:
Code: Select all#define power            D7

void setup() {
    Serial.begin(115200);
 
pinMode(power, INPUT);
}

void loop() {
digitalWrite(power, !digitalRead(power));
  Serial.println (digitalRead(power));
delay(1000);
}

Re: update NodeMCU pin

PostPosted: Tue Dec 24, 2019 5:24 pm
by schufti
try removing this line
digitalWrite(power, !digitalRead(power));

and maybe you also need a pulldown at D7 (10k to gnd)

Re: update NodeMCU pin

PostPosted: Thu Dec 26, 2019 2:08 pm
by Maks
schufti wrote:try removing this line
digitalWrite(power, !digitalRead(power));

and maybe you also need a pulldown at D7 (10k to gnd)


I think i might be missing something...

If i connect the PIN D7 to GND using the resistor i will always get "0", and then if i connect to 3.3v it will short and reboot the nodemcu...
maybe i wasnt clear to explain what i need... :S

Re: update NodeMCU pin

PostPosted: Thu Dec 26, 2019 6:22 pm
by Maks
Maks wrote:
schufti wrote:try removing this line
digitalWrite(power, !digitalRead(power));

and maybe you also need a pulldown at D7 (10k to gnd)


I think i might be missing something...

If i connect the PIN D7 to GND using the resistor i will always get "0", and then if i connect to 3.3v it will short and reboot the nodemcu...
maybe i wasnt clear to explain what i need... :S


What i need is to always get "0", and only get "1" if 3.3v is applied to pin D7, if i stop applying 3.3v it should go back to "0".
Is it possible?

Thanks in advance