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);
}
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.
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
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.