Skip to content

Instantly share code, notes, and snippets.

@MazeW
Created December 23, 2021 20:55
Show Gist options
  • Save MazeW/a876844f92f05c081002d3f183ebe726 to your computer and use it in GitHub Desktop.
Save MazeW/a876844f92f05c081002d3f183ebe726 to your computer and use it in GitHub Desktop.
This is how to connect a tongling relay to a d1-mini (ESP8266)

Connect a 5V relay

I had issues connecting the relay to the wenmos d1-mini (ESP8266 or ESP-12F), turns out you must use the 3v3 pin not 5V.

relay d1
VIN 3v3
GND G
IN D2

You can use any pin you want for IN, but check diagram below for safe GPIO pins that aren't used by something else.

image

Example code that turns relay on and off:

int state = 0;
int relay = 4; // D2 on d1-mini
void setup() {
  pinMode(relay, OUTPUT);
}

void loop() {
    if(state == 0){
      state = 1;
      digitalWrite(relay, HIGH);
      delay(3000);
    } else {
      state = 0;
      digitalWrite(relay, LOW);
      delay(3000);
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment