1
\$\begingroup\$

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!

\$\endgroup\$
14
  • 1
    \$\begingroup\$ Where is the relay documentation you refer to? \$\endgroup\$ – StarCat Mar 27 at 18:39
  • 2
    \$\begingroup\$ that is not a relay ... it is a relay module ... refer to the datasheet about the correct way to control it ... you probably do not need the 10 k resistor \$\endgroup\$ – jsotola Mar 27 at 18:40
  • 2
    \$\begingroup\$ You have a relay module, not a plain relay. Those modules usually have some circuitry so the relay can be controlled directly by an Arduino output - no resistor necessary. You would need the documentation on the module to determine what the LEDs indicate. If you are going to work with electronics, you need to understand wiring diagrams. \$\endgroup\$ – Peter Bennett Mar 27 at 18:40
  • 3
    \$\begingroup\$ Please, no out of focus photographs. I don't understand out of focus photos. \$\endgroup\$ – Transistor Mar 27 at 19:05
  • 1
    \$\begingroup\$ What made you put a 10k resistor in series in the first place? Also, if you don't understand basic wiring diagrams, I have to ask how confident you are working with mains voltages, making arduino controlled incineration devices - I mean - electric cookers? \$\endgroup\$ – Justme Mar 27 at 19:11
2
\$\begingroup\$

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.

\$\endgroup\$
4
  • \$\begingroup\$ Thank you @Transistor. Wiring was correct. Turning off requires conditionally activating a 20K resistor (PULLUP). This is apparently done through code. I will add a solution below. \$\endgroup\$ – Tims Mar 28 at 15:02
  • \$\begingroup\$ Typically the microcontroller's outputs are push-pull. You only need a pull-up if the output is open drain only. Do you know what yours is? \$\endgroup\$ – Transistor Mar 28 at 15:06
  • \$\begingroup\$ Not sure, but relay is acting perfectly after using INPUT_PULLOUT instead of HIGH pinmode for deactivating the relay. \$\endgroup\$ – Tims Mar 28 at 15:10
  • 1
    \$\begingroup\$ OK. Accept your answer instead of mine if yours is correct. Otherwise you'll confuse anyone looking for the solution. Thanks. \$\endgroup\$ – Transistor Mar 28 at 15:21
0
\$\begingroup\$
  • make sure your 3 wire interface uses a common ground with relay coil and logic supply
    - Make sure you are using 5V and not 3.3V for the 5V coil
  • if it is good code then the voltages will switch on the interface which you can easily measure or use 1k R+LED as a crude logic probe.

Since the 3 wire interface is low current it is better to use twisted pairs of AWG24 CAT3 or similar for EMI reasons and neatness rather than 16 or 18 AWG

\$\endgroup\$
2
  • \$\begingroup\$ Yes, 5v comes from the WeMos D1 board. What is common ground? Ground for the relay on the DC side is coming from laptop/WeMos board. On the AC side, ground is coming from the outlet. Is this adequate? \$\endgroup\$ – Tims Mar 28 at 4:12
  • \$\begingroup\$ ok. DC Gnd is anything that is 0V low impedance. Do you know off state voltage ? Low side or high of LED? Your photo still sucks, sorry \$\endgroup\$ – Tony Stewart EE75 Mar 28 at 11:10
0
\$\begingroup\$

Deactivating a relay requires conditionally activating a 20K resistor (PULLUP) on the Arduino board.

const byte pin = 2;

void setup(){

  // Define the pin as INPUT_PULLUP until you are ready to use it.
  pinMode(pin, INPUT_PULLUP);

}

void loop(){

  delay(1000);

  // Activate the relay. Supplying a low impedance
  // path to ground turns the relay on.
  pinMode(pin, OUTPUT);
  digitalWrite(pin, LOW);

  delay(1000);

  // Deactivate the relay.
  pinMode(pin, INPUT_PULLUP);

  // Using digitalWrite(pin, HIGH); is an alternative to using
  // pinMode(pin, INPUT_PULLUP); If your relay module is the
  // same as the one shown below, then it doesn't matter which
  // method you choose.

}

Answer from VE7JRO

About INPUT_PULLOUT on Arduino boards

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.