Problems with ESP32 and relay module

Hello, I am having problems activating a relay from the ESP32 WROOM 32d module, the signal reaches the relay card, but it does not activate, I tried several relay cards, and it does not activate, I also tried connecting the signal to a led, together with the negative, and the led if it works.

I also tried replacing the ESP32 with another one, and that doesn't work either.

What could be wrong with my connection or code?, thanks

Code:

//This example code is in the Public Domain (or CC0 licensed, at your option.)
//By Evandro Copercini - 2018
//
//This example creates a bridge between Serial and Classical Bluetooth (SPP)
//and also demonstrate that SerialBT have the same functionalities of a normal Serial

#include "BluetoothSerial.h"

#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif

#if !defined(CONFIG_BT_SPP_ENABLED)
#error Serial Bluetooth not available or not enabled. It is only available for the ESP32 chip.
#endif

BluetoothSerial SerialBT;

int pinOut = 12;
int maleta = 23;

void setup() {
  Serial.begin(115200);
  SerialBT.begin("ESP32test"); //Bluetooth device name
  Serial.println("The device started, now you can pair it with bluetooth!");
  pinMode(pinOut, OUTPUT);
  digitalWrite (pinOut, LOW);
  delay (20);
  
}

void loop() {
  if (Serial.available()) {
    SerialBT.write(Serial.read());
  }

  
  if (SerialBT.available())
  {

   
    char data = ((byte) SerialBT.read());
    switch (data)
    {
      case 'P':
        digitalWrite (pinOut, HIGH);
        //Hacemos un delay de 1 segundo
        delay (1000);
        digitalWrite (pinOut, LOW);
        break;

      case 'b':
        digitalWrite(maleta, HIGH);
        delay(800);
        digitalWrite(maleta, LOW);
        break;
      default : break;
    }
    Serial.println(data);
  }
  delay(20);
}

Diagram

Disconnect the ESP from the circuit.

Manually key the IN relay input between 0 and 5v, does the relay operate ?

Then try 0 to 3.3V to key the module ?

hello, manually with 5v, the relay works. should I lower the power supply to 3.3v?, and try again, manual?

There is a 3.3V pin on the ESP.

Connect relay PCB IN input between 0v (GND) and 3.3V on the ESP.

No, leave the 5V supply to the relay, but use the 3V3 supply from the ESP to try and operate the relay IN.
Your ESP is 3V3 logic output and it may not be enough to operate the relay driver.

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

Excuse my ignorance, but should I connect the GND and the 3.3v output together with the IN input of the relay all at the same time? By joining the GND to the 3v3v output, wouldn't it cause a short circuit? thank you

Before you apply power;
Join the relay gnd to ESP gnd
Join the relay 5V to ESP 5V
Then apply power;
Then connect the relay IN to 3V3 pin on the ESP.

As shown in @LarryD diagram in post #4.

Tom.. :smiley: :coffee: :coffee: :australia:

First connect IN to 0V (GND) what happens with the relay ?

Then connect IN to 3V3, what happens with the relay ?

Never connect 0V (GND) to a power supply voltage !

It did not work, but apparently I was able to correct it, they were the 15cm dupont cables that I was using for the relay, I replaced them with other 10cm cables that I had brought from China, and it worked immediately, I did several tests and it continued to work.

I didn't know there was quality in those cables.

There isn’t if you make your own :wink:

Can you build the arduino cables, with a 24awg cable?, and buy the pins and build them, instead of buying them made?,

How to be safer, or what do you think?

Yes you can.

See:

Friend, very thnks for u help, i am from Colombia, and i am noob in all this about arduino.

Very very Thnks.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.