The use of the ESP8266 in the world of IoT

User avatar
By Maks
#85035 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);
}
User avatar
By schufti
#85038 try removing this line
digitalWrite(power, !digitalRead(power));

and maybe you also need a pulldown at D7 (10k to gnd)
User avatar
By Maks
#85058
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
User avatar
By Maks
#85060
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