Use this forum to chat about hardware specific topics for the ESP8266 (peripherals, memory, clocks, JTAG, programming)
User avatar
By liderbug
#73770 Need some advice. I'm trying out a esp8266-01 with 5v relay. ... 0.0.rviZwX

I've tried various/several:
pinMode(N, OUTPUT);
digitalWrite(N, 0[1]);
with no joy. What should "N" be? I've can "curl http://IP/on[off]" and the 8266 responds/blinks but no relay change.
User avatar
By liderbug
#73789 I found a schematic for this product. From what I can tell the 8266 talks to a [verylargestrangenumber] part which only has input of tx & rx - no gpio0 or 2. I modified my sketch to use pin 1 and pin 3 but still it just sits there. I did find a web page where they got it to work (so they say) by connecting via usb<->ttl<-> the tx/rx pins on the board - and bypass the 8266 - so what's the 8266 there for?

I also have a similar relay board without the strange control chip. However the Enable pin is low on the 8266 so something isn't right. And I've found a couple of sketches that look like they should work - but don't. I've email both sellers for info - film @ 11 - maybe...
User avatar
By aDub
#73873 N is the pin number

Don't connect a relay directly to any of the pins.
if you have a junkbox then make a simple driver like
(you can leave out D & R)
or purchase a relay driver.
Your relay coil MUST be quenched with a diode to prevent back emf
best practice would be to drive the relay from a separate supply. If using the same supply a big electrolytic cap near the processor board would be good.

Practice with an LED and 1K resistor rather than the relay to check your code.
User avatar
By aDub
#73875 I don't wish to be insensitive, but you probably need to work through a few simple tutorials

In answer to the code fragment above...

Code: Select allvoid setup() {
  pinMode(LED_BUILTIN, OUTPUT);     // Initialize the LED_BUILTIN pin as an output

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, LOW);   // Turn the LED on (Note that LOW is the voltage level
                                    // but actually the LED is on; this is because
                                    // it is active low on the ESP-01)
  delay(1000);                      // Wait for a second
  digitalWrite(LED_BUILTIN, HIGH);  // Turn the LED off by making the voltage HIGH
  delay(2000);                      // Wait for two seconds (to demonstrate the active low LED)

once that works, connect an LED and series resistor (500R to 2K will be fine for testing) between (say) D7 and ground and replace "LED_BUILTIN" with "D7"

Also, please post links to your device