Electronic – arduino – 5 V relay connected to Arduino

arduinorelaytransistors

I have a 5 V relay module connected to WeMos D1 board. The load is a small electric cooker.

The code turns on and off the relay every 5s for testing purposes.

digitalWrite(pin,HIGH);
delay(5000);

digitalWrite(pin,LOW);
delay(5000);

However, the green light and red light are always on.
there is no switching happening. An onboard led on the WeMos D1 board is blinking every 5s.

Relay specs:
https://www.ebay.com/itm/2PCS-1-Channel-DC-5V-Relay-Switch-Board-Module-for-Arduino-Raspberry-Pi-ARM-AVR/383693511233?_trksid=p2504926.m5232.l9681

enter image description here

enter image description here

int pin = 14;
void setup()
{
  pinMode(pin, OUTPUT);
  
}


void loop()
{
     digitalWrite(pin,HIGH);
     delay(5000);

     digitalWrite(pin,LOW);
     delay(5000);
}

Thank you!

Best Answer

It's very difficult to tell from the poor quality images posted but it appears that you may have connected the wires on the left side of the board one pin out of position.

enter image description here

Figure 1. The relay module requires 5 V so it should be powered from the 5V pin on the WEMOS board. The relay module GND should be connected to any GND pin on the WEMOS.

enter image description here

Figure 2. Connections on the relay board are unclear. Here it appears that you have connected in sequence red, yellow, black. This doesn't match the colours on the WEMOS.

Note the order on the relay module is VCC, GND and IN.

schematic

simulate this circuit – Schematic created using CircuitLab

Figure 3. Wiring diagram.

You expressed fear of circuit diagrams in your original post. There is no need to fear them. They are the simplest unambiguous way to show the scheme of the circuit. You can see that in this case it's ridiculously simple to understand.

There should be no connection between the WEMOS and the mains wiring other than the through the isolation of the relay.