i am using a sain smart 5v 16 channel relays board and powering it with a 5v dc adapter, for microcontroller I am using an esp32.
the issue is when I send an on command to the relay connected with any GPIO pin the rleays makes a buzzing sound instead of a regular click, meanwhile I don't have any such issue when I use a single relay boards.
Help us help you.
Are you sure it's 5V.
Sain smart only has an 8 channel 5V board
yes its a 5v, i am not sure if i can share a link to amazon product, but let me share an image for your reference too.
amazon product link
The website says Brand: Other and provides no further information. I would just be guessing as to what is wrong.
Maybe another forum poster has used that board and can help
just a quick question, what board would you suggest?
How about that schematic?
Did you note the comment of a user connecting the board to 3V3 instead of 5V?
I have never used a relay board wih an ESP32.
If you have a single channel model that works, try looking for an 8 or 16 channel version of he same model.
Things to investigate.
- Are you sure the adapter has enough current capacity? What are it's detailed specs?
- Do you have detailed current specs for the relay board? The supplier should provide.
- (most likely) ESP32's outputs are 3.3V, there are many instances of these not being adequate to drive the input side of relay boards like this.
Best advice - set this one aside, and look for a 3.3V compatible relay board.
From my experience with relay boards that needs at least 4.5V and is expecting a 5V logic level signal. But without an annotated schematic that is only a SWAG.
I don't have a schematic, as I am not an advanced user this is my first time using an esp32 and relay boards. the connections I am using are pretty straightforward forward I don't know what the issue is as when I use single-channel relays they work perfectly and I have connected about 8 single-channel relays and used them but what I cant figure out is the 16-channel relay board.
no to your second question.
if you want i can share the images of the connections I am making if that helps.
i am providing the power to the relays separately and the esp32 separately with the common gnd connected.
yes i have tested with a multimeter and verified that the adapter is providing at least 5.6v, what I cant understand is why the single channel relays work and not the 16 channel one.
#include <WiFi.h>
#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <Preferences.h>
const char* ssid = "Yolo";
const char* password = "yolo1122";
const int relayPins[] = {13, 12, 14, 27, 26, 25, 33, 32, 35, 34, 15, 2, 4, 5, 18, 19, 21, 22, 23};
const int numRelays = sizeof(relayPins) / sizeof(relayPins[0]);
AsyncWebServer server(80);
Preferences preferences;
void setup() {
Serial.begin(115200);
// Set GPIO2 as an output for the blue LED light and initially turn it off
pinMode(2, OUTPUT);
digitalWrite(2, LOW);
for (int i = 0; i < numRelays; i++) {
pinMode(relayPins[i], OUTPUT);
// Load saved relay states from Preferences
preferences.begin("relayState", false);
String key = "state" + String(i);
bool savedRelayState = preferences.getBool(key.c_str(), false);
preferences.end();
digitalWrite(relayPins[i], savedRelayState ? HIGH : LOW);
}
// Setup your ESP32 as an access point
WiFi.mode(WIFI_AP);
// Set the static IP
IPAddress local_IP(192,168,4,50);
IPAddress gateway(192,168,4,1);
IPAddress subnet(255,255,255,0);
WiFi.softAPConfig(local_IP, gateway, subnet);
WiFi.softAP(ssid, password);
// Turn on the blue LED light to indicate that the ESP32 is broadcasting its SSID
digitalWrite(2, HIGH);
Serial.print("Access Point is running. Connect to it with SSID: ");
Serial.println(ssid);
IPAddress IP = WiFi.softAPIP();
Serial.print("IP address: ");
Serial.println(IP);
server.on("/relay", HTTP_POST, [](AsyncWebServerRequest *request) {
int channel = -1;
String state;
if (request->hasParam("channel")) {
channel = request->getParam("channel")->value().toInt();
}
if (request->hasParam("state")) {
state = request->getParam("state")->value();
}
if (channel >= 0 && channel < numRelays) {
bool newState = false;
if (state == "on") {
digitalWrite(relayPins[channel], HIGH);
newState = true;
} else if (state == "off") {
digitalWrite(relayPins[channel], LOW);
newState = false;
}
// Save relay state to Preferences
preferences.begin("relayState", false);
String key = "state" + String(channel);
preferences.putBool(key.c_str(), newState);
preferences.end();
request->send(200, "text/plain", "Relay " + String(channel) + " state set to: " + state);
} else {
request->send(400, "text/plain", "Invalid channel or state");
}
});
server.on("/getStates", HTTP_GET, [](AsyncWebServerRequest *request) {
preferences.begin("relayState", false);
String states = "";
for (int i = 0; i < numRelays; i++) {
String key = "state" + String(i);
bool savedState = preferences.getBool(key.c_str(), false);
states += "Relay " + String(i) + ": " + (savedState ? "ON" : "OFF") + "\n";
}
preferences.end();
request->send(200, "text/plain", states);
});
server.begin();
Serial.println("HTTP server started");
}
void loop() {
// Your main code here, if needed
}
I have tried to attach the code as well using the code tag I don't know if I did it right or not.
the code itself is working fine I have tried with single channel relays.
Buzzing sounds like there is no enough current to pull the relay in.
Here is the spec for the relays alone https://denkovi.com/Documents/JQC-3FF-S-Z.pdf
Spec sheet for the board
https://www.uctronics.com/download/Amazon/U604302_print.pdf
If you note it says it has a 12V operating Voltage
if you notice the subtle differences between the 2, the 2nd one is missing some capacitors that's the 5v one.
True it is also missing the regulator, however I was going by the amazon in the link.
No matter here is another one for reference
drive current for each input pin is 20mA
so, you mean I need a 5v regulator?
The two pictures show different relay coil voltages. The original posted showed 5V this one shows 12V. The add states: " Relay 16 Channel 5V Module for Arduino UNO MEGA 2560 R3 Raspberry Pi Board" That is what was in the picture but not what you were sent, so send it back and get a 5V one, your project should then work. This is a common problem with marketplace vendors, many do not know what they are selling and do not post specifications, and when they do many times they are wrong. Mramzanm was correct and it would have worked had he had gotten what he ordered.