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.
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.
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.
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.
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.