So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By Phaz
#59147 Hey ya'll - after hours of scouring the forums - i'm still stumped.

I've got a simple setup - control relay over wifi via blynk on my nodemcu esp8266 board.

Everything works fine - except the relay triggers everytime the unit is restarted - causing my garage door to open (relay is connected to garage door).

I've heard i need a pulldown resistor - but where should this go? If i added a 10k ohm resistor between relay GND and gnd on the board - it prevents the relay from working at all.
User avatar
By rudy
#59151 You didn't say what module you are using. What port outputs you have available. I'll assume you have a board with a ESP-12 on it. If so then use GPIO4 or GPIO5. They do not produce a high on reset or startup.

You also didn't say what you are using to turn the relay on. If you are using a circuit with a npn transistor (or an N-channel mosfet) then you need to turn the pin high in order to turn the relay on. If you are using GPIO12, 13, 14 then using a 1k resistor connected to the port pin and the other side connected to the ESP ground should do it.

From what you said I have no idea what you are using for a relay circuit. Rather than me go round in circles I think it is better if you tell us what you have, what you are working with.

edit:

If you have a ESP-01 module then you only have GPIO-0, GPIO-2, RX, and TX to work with. If you need to use the first two then you would be better off using a circuit with a pnp transistor. High would be off and a low would turn the relay on.

I have been using GPIO-15 since it is low on startup.
User avatar
By Phaz
#59170 Got it working - finally :P


And as usual, it was something really simple (logic error) - I didn't end up needing any pulldown resistors.

These are my thoughts (At 1:30 am after starting this at 5pm :'( )- The relay was in a 'high' state normally (light was constantly on), so when the power went out it triggered the relay. Below is the amended code for the button, instead of having digitalwrite relay HIGH when button pressed, i switched it around to LOW. This fixed the issue - I still need to ponder as to exactly how this fixed it, if you guys have any thoughts please let me know.


Code: Select all    // BUTTON - activate garage door when button is pressed
    int buttonState = digitalRead(BUTTON);
    if (buttonState == HIGH) {
      digitalWrite(RELAY, LOW);
    } else {
      digitalWrite(RELAY, HIGH);
    }   


EDIT:: Also, at the same time, changing the digitalwrite state of the relay from low to high in the setup also attributed to the solution.

I'm still trying to get my head around it - but thanks all for the help.

Code: Select allpinMode(BUTTON, INPUT); //Button for manual garage open
digitalWrite(RELAY, HIGH); // Keep relay off while device turning on
pinMode(RELAY, OUTPUT); //Pin connected to relay